Implement quote replies to thread

This commit is contained in:
RMidhunSuresh 2021-12-20 16:42:30 +05:30
parent 825bec80b0
commit 38781db858

View file

@ -40,8 +40,8 @@ function fallbackPrefix(msgtype) {
return msgtype === "m.emote" ? "* " : ""; return msgtype === "m.emote" ? "* " : "";
} }
function _createReplyContent(targetId, msgtype, body, formattedBody) { function _createReplyContent(targetId, msgtype, body, formattedBody, threadId) {
return { const reply = {
msgtype, msgtype,
body, body,
"format": "org.matrix.custom.html", "format": "org.matrix.custom.html",
@ -52,10 +52,18 @@ function _createReplyContent(targetId, msgtype, body, formattedBody) {
} }
} }
}; };
if (threadId) {
Object.assign(reply["m.relates_to"], {
rel_type: THREADING_REL_TYPE,
event_id: threadId,
});
}
return reply;
} }
export function createReplyContent(entry, msgtype, body) { export function createReplyContent(entry, msgtype, body) {
if (entry.isThread) { // don't use entry.isReply here since we pretend that threads are replies
if (!entry.relation["m.in_reply_to"] && entry.isThread) {
return createThreadContent(entry, msgtype, body); return createThreadContent(entry, msgtype, body);
} }
// TODO check for absense of sender / body / msgtype / etc? // TODO check for absense of sender / body / msgtype / etc?
@ -77,7 +85,7 @@ export function createReplyContent(entry, msgtype, body) {
const newBody = plainFallback + '\n\n' + body; const newBody = plainFallback + '\n\n' + body;
const newFormattedBody = formattedFallback + htmlEscape(body); const newFormattedBody = formattedFallback + htmlEscape(body);
return _createReplyContent(entry.id, msgtype, newBody, newFormattedBody); return _createReplyContent(entry.id, msgtype, newBody, newFormattedBody, entry.threadEventId);
} }
function createThreadContent(entry, msgtype, body) { function createThreadContent(entry, msgtype, body) {