Implement is_falling_back in accordance to MSC3440 (#8055)

This commit is contained in:
Germain 2022-03-15 13:52:37 +00:00 committed by GitHub
parent cc9651089e
commit 2acc8fd18b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 23 deletions

View file

@ -142,14 +142,13 @@ export function getNestedReplyText(
return { body, html };
}
export function makeReplyMixIn(ev?: MatrixEvent, inThread = false): RecursivePartial<IContent> {
export function makeReplyMixIn(ev?: MatrixEvent): RecursivePartial<IContent> {
if (!ev) return {};
const mixin: RecursivePartial<IContent> = {
'm.relates_to': {
'm.in_reply_to': {
'event_id': ev.getId(),
'io.element.show_reply': inThread, // MSC3440 unstable `is_falling_back` field
},
},
};
@ -160,9 +159,10 @@ export function makeReplyMixIn(ev?: MatrixEvent, inThread = false): RecursivePar
* that know how to handle that relation will
* be able to render them more accurately
*/
if (ev.isThreadRelation) {
if (ev.isThreadRelation || ev.isThreadRoot) {
mixin['m.relates_to'] = {
...mixin['m.relates_to'],
is_falling_back: false,
rel_type: THREAD_RELATION_TYPE.name,
event_id: ev.threadRootId,
};
@ -171,11 +171,16 @@ export function makeReplyMixIn(ev?: MatrixEvent, inThread = false): RecursivePar
return mixin;
}
export function shouldDisplayReply(event: MatrixEvent, inThread = false): boolean {
const parentExist = Boolean(getParentEventId(event));
if (!parentExist) return false;
if (!inThread) return true;
export function shouldDisplayReply(event: MatrixEvent): boolean {
const inReplyTo = event.getWireContent()?.["m.relates_to"]?.["m.in_reply_to"];
if (!inReplyTo) {
return false;
}
const inReplyTo = event.getRelation()?.["m.in_reply_to"];
return inReplyTo?.is_falling_back ?? inReplyTo?.["io.element.show_reply"] ?? false;
const relation = event.getRelation();
if (relation?.rel_type === THREAD_RELATION_TYPE.name && relation?.is_falling_back) {
return false;
}
return !!inReplyTo.event_id;
}