From 2acc8fd18b16cf33f3389e6ed70a06eace336589 Mon Sep 17 00:00:00 2001 From: Germain Date: Tue, 15 Mar 2022 13:52:37 +0000 Subject: [PATCH] Implement is_falling_back in accordance to MSC3440 (#8055) --- src/components/structures/ThreadView.tsx | 1 + src/components/views/elements/ReplyChain.tsx | 6 ++--- src/components/views/rooms/EventTile.tsx | 3 +-- .../views/rooms/SendMessageComposer.tsx | 5 +--- src/utils/Reply.ts | 23 +++++++++++-------- ...ReplyChain-test.js => ReplyChain-test.tsx} | 8 +++---- 6 files changed, 23 insertions(+), 23 deletions(-) rename test/components/views/elements/{ReplyChain-test.js => ReplyChain-test.tsx} (96%) diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index 374ff1a2e4..5fc1911ead 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -289,6 +289,7 @@ export default class ThreadView extends React.Component { return { "rel_type": THREAD_RELATION_TYPE.name, "event_id": this.state.thread?.id, + "is_falling_back": true, "m.in_reply_to": { "event_id": this.state.lastThreadReply?.getId() ?? this.state.thread?.id, }, diff --git a/src/components/views/elements/ReplyChain.tsx b/src/components/views/elements/ReplyChain.tsx index 381f7ec08b..6b8d7314ea 100644 --- a/src/components/views/elements/ReplyChain.tsx +++ b/src/components/views/elements/ReplyChain.tsx @@ -35,7 +35,7 @@ import ReplyTile from "../rooms/ReplyTile"; import Pill from './Pill'; import { ButtonEvent } from './AccessibleButton'; import { getParentEventId, shouldDisplayReply } from '../../../utils/Reply'; -import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext"; +import RoomContext from "../../../contexts/RoomContext"; import { MatrixClientPeg } from '../../../MatrixClientPeg'; /** @@ -205,8 +205,6 @@ export default class ReplyChain extends React.Component { render() { let header = null; - - const inThread = this.context.timelineRenderingType === TimelineRenderingType.Thread; if (this.state.err) { header =
{ @@ -214,7 +212,7 @@ export default class ReplyChain extends React.Component { 'it either does not exist or you do not have permission to view it.') }
; - } else if (this.state.loadedEv && shouldDisplayReply(this.state.events[0], inThread)) { + } else if (this.state.loadedEv && shouldDisplayReply(this.state.events[0])) { const ev = this.state.loadedEv; const room = this.matrixClient.getRoom(ev.getRoomId()); header =
diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index 152154d0c9..1f7a5e7c2f 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -1329,8 +1329,7 @@ export class UnwrappedEventTile extends React.Component { msgOption = readAvatars; } - const inThread = this.context.timelineRenderingType === TimelineRenderingType.Thread; - const replyChain = haveTileForEvent(this.props.mxEvent) && shouldDisplayReply(this.props.mxEvent, inThread) + const replyChain = haveTileForEvent(this.props.mxEvent) && shouldDisplayReply(this.props.mxEvent) ? { +export function makeReplyMixIn(ev?: MatrixEvent): RecursivePartial { if (!ev) return {}; const mixin: RecursivePartial = { '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; } diff --git a/test/components/views/elements/ReplyChain-test.js b/test/components/views/elements/ReplyChain-test.tsx similarity index 96% rename from test/components/views/elements/ReplyChain-test.js rename to test/components/views/elements/ReplyChain-test.tsx index 64784835e1..955f321b5b 100644 --- a/test/components/views/elements/ReplyChain-test.js +++ b/test/components/views/elements/ReplyChain-test.tsx @@ -70,7 +70,7 @@ describe("ReplyChain", () => { }, "m.relates_to": { "rel_type": "m.replace", - "event_id": originalEventWithRelation.event_id, + "event_id": originalEventWithRelation.getId(), }, }, user: "some_other_user", @@ -114,7 +114,7 @@ describe("ReplyChain", () => { }, "m.relates_to": { "rel_type": "m.replace", - "event_id": originalEvent.event_id, + "event_id": originalEvent.getId(), }, }, user: "some_other_user", @@ -163,7 +163,7 @@ describe("ReplyChain", () => { }, "m.relates_to": { "rel_type": "m.replace", - "event_id": originalEventWithRelation.event_id, + "event_id": originalEventWithRelation.getId(), }, }, user: "some_other_user", @@ -208,7 +208,7 @@ describe("ReplyChain", () => { }, "m.relates_to": { "rel_type": "m.replace", - "event_id": originalEventWithRelation.event_id, + "event_id": originalEventWithRelation.getId(), }, }, user: "some_other_user",