forked from Mirrors/gomuks
web/timeline: fix newlines in plaintext messages
This commit is contained in:
parent
8d201642c8
commit
3dd7f9a4bd
4 changed files with 16 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ export enum UnreadType {
|
|||
|
||||
export interface LocalContent {
|
||||
sanitized_html?: TrustedHTML
|
||||
html_version?: number
|
||||
was_plaintext?: boolean
|
||||
}
|
||||
|
||||
export interface BaseDBEvent {
|
||||
|
|
|
@ -31,7 +31,11 @@ const onClickHTML = (evt: React.MouseEvent<HTMLDivElement>) => {
|
|||
export const TextMessageBody = ({ event }: EventContentProps) => {
|
||||
const content = event.content as MessageEventContent
|
||||
if (event.local_content?.sanitized_html) {
|
||||
return <div onClick={onClickHTML} className="message-text html-body" dangerouslySetInnerHTML={{
|
||||
const classNames = ["message-text", "html-body"]
|
||||
if (event.local_content.was_plaintext) {
|
||||
classNames.push("plaintext-body")
|
||||
}
|
||||
return <div onClick={onClickHTML} className={classNames.join(" ")} dangerouslySetInnerHTML={{
|
||||
__html: event.local_content!.sanitized_html!,
|
||||
}}/>
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue