import * as sanitizeHtml from "sanitize-html" ; category export class RichReply { private constructor ( ) { } param { string } roomId param { any } event param { string } withText param { string } withHtml returns { any } public static createFor ( roomId , event , withText , withHtml ) { const originalBody = ( event [ "content" ] ? event [ "content" ] [ "body" ] : "" ) || "" ; let originalHtml = ( event [ "content" ] ? event [ "content" ] [ "formatted_body" ] : "" ) || null ; if ( originalHtml === null ) { originalHtml = sanitizeHtml ( originalBody ) ; } const fallbackText = "> <" + event [ "sender" ] + "> " + originalBody . split ( "\n" ) . join ( "\n> " ) ; const fallbackHtml = "<mx-reply><blockquote>" + `<a href="https://matrix.to/#/${ roomId }/${ event [ "event_id" ] }">In reply to</a> ` + `<a href="https://matrix.to/#/${ event [ "sender" ] }">${ event [ "sender" ] }</a>` + "<br />" + originalHtml + "</blockquote></mx-reply>" ; return { "m.relates_to" : { "m.in_reply_to" : { "event_id" : event [ "event_id" ] , } , } , "msgtype" : "m.text" , "body" : fallbackText + "\n\n" + withText , "format" : "org.matrix.custom.html" , "formatted_body" : fallbackHtml + withHtml , } ; } }