From 3dd7f9a4bde10c04d91378518cbe6ebc92b71548 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 18 Oct 2024 12:56:38 +0300 Subject: [PATCH] web/timeline: fix newlines in plaintext messages --- pkg/hicli/database/event.go | 1 + pkg/hicli/sync.go | 10 ++++++++-- web/src/api/types/hitypes.ts | 2 ++ web/src/ui/timeline/content/MessageBody.tsx | 6 +++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/hicli/database/event.go b/pkg/hicli/database/event.go index c7147b9..1520dc4 100644 --- a/pkg/hicli/database/event.go +++ b/pkg/hicli/database/event.go @@ -282,6 +282,7 @@ func (m EventRowID) GetMassInsertValues() [1]any { type LocalContent struct { SanitizedHTML string `json:"sanitized_html,omitempty"` HTMLVersion int `json:"html_version,omitempty"` + WasPlaintext bool `json:"was_plaintext,omitempty"` } type Event struct { diff --git a/pkg/hicli/sync.go b/pkg/hicli/sync.go index f8429a9..b7f90d6 100644 --- a/pkg/hicli/sync.go +++ b/pkg/hicli/sync.go @@ -344,14 +344,20 @@ func (h *HiClient) calculateLocalContent(ctx context.Context, dbEvt *database.Ev } if content != nil { var sanitizedHTML string - if content.Format == event.FormatHTML { + var wasPlaintext bool + if content.Format == event.FormatHTML && content.FormattedBody != "" { sanitizedHTML, _ = sanitizeAndLinkifyHTML(content.FormattedBody) } else { var builder strings.Builder linkifyAndWriteBytes(&builder, []byte(content.Body)) sanitizedHTML = builder.String() + wasPlaintext = true + } + return &database.LocalContent{ + SanitizedHTML: sanitizedHTML, + HTMLVersion: CurrentHTMLSanitizerVersion, + WasPlaintext: wasPlaintext, } - return &database.LocalContent{SanitizedHTML: sanitizedHTML, HTMLVersion: CurrentHTMLSanitizerVersion} } return nil } diff --git a/web/src/api/types/hitypes.ts b/web/src/api/types/hitypes.ts index f637a1d..9af6650 100644 --- a/web/src/api/types/hitypes.ts +++ b/web/src/api/types/hitypes.ts @@ -79,6 +79,8 @@ export enum UnreadType { export interface LocalContent { sanitized_html?: TrustedHTML + html_version?: number + was_plaintext?: boolean } export interface BaseDBEvent { diff --git a/web/src/ui/timeline/content/MessageBody.tsx b/web/src/ui/timeline/content/MessageBody.tsx index f8fb3a7..1825d1d 100644 --- a/web/src/ui/timeline/content/MessageBody.tsx +++ b/web/src/ui/timeline/content/MessageBody.tsx @@ -31,7 +31,11 @@ const onClickHTML = (evt: React.MouseEvent) => { export const TextMessageBody = ({ event }: EventContentProps) => { const content = event.content as MessageEventContent if (event.local_content?.sanitized_html) { - return
}