Allow sending files as replies as per MSC3676 (#8020)

This commit is contained in:
Michael Telatynski 2022-03-21 12:03:59 +00:00 committed by GitHub
parent 14653d1378
commit dd53b226eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 55 deletions

View file

@ -184,3 +184,31 @@ export function shouldDisplayReply(event: MatrixEvent): boolean {
return !!inReplyTo.event_id;
}
interface IAddReplyOpts {
permalinkCreator?: RoomPermalinkCreator;
includeLegacyFallback?: boolean;
}
export function addReplyToMessageContent(
content: IContent,
replyToEvent: MatrixEvent,
opts: IAddReplyOpts = {
includeLegacyFallback: true,
},
): void {
const replyContent = makeReplyMixIn(replyToEvent);
Object.assign(content, replyContent);
if (opts.includeLegacyFallback) {
// Part of Replies fallback support - prepend the text we're sending
// with the text we're replying to
const nestedReply = getNestedReplyText(replyToEvent, opts.permalinkCreator);
if (nestedReply) {
if (content.formatted_body) {
content.formatted_body = nestedReply.html + content.formatted_body;
}
content.body = nestedReply.body + content.body;
}
}
}