Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3f67a38

Browse files
authored
Fix incorrect usage of unstable variant of is_falling_back (#8016)
1 parent 972fcd1 commit 3f67a38

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/components/views/elements/ReplyChain.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ import classNames from 'classnames';
2020
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
2121
import { Room } from 'matrix-js-sdk/src/models/room';
2222
import { Relations } from 'matrix-js-sdk/src/models/relations';
23+
import { MatrixClient } from 'matrix-js-sdk/src/client';
2324

2425
import { _t } from '../../../languageHandler';
2526
import dis from '../../../dispatcher/dispatcher';
2627
import { makeUserPermalink, RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
2728
import SettingsStore from "../../../settings/SettingsStore";
2829
import { Layout } from "../../../settings/enums/Layout";
29-
import MatrixClientContext from "../../../contexts/MatrixClientContext";
3030
import { getUserNameColorClass } from "../../../utils/FormattingUtils";
3131
import { Action } from "../../../dispatcher/actions";
3232
import { replaceableComponent } from "../../../utils/replaceableComponent";
3333
import Spinner from './Spinner';
3434
import ReplyTile from "../rooms/ReplyTile";
3535
import Pill from './Pill';
3636
import { ButtonEvent } from './AccessibleButton';
37-
import { getParentEventId } from '../../../utils/Reply';
37+
import { getParentEventId, shouldDisplayReply } from '../../../utils/Reply';
38+
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
39+
import { MatrixClientPeg } from '../../../MatrixClientPeg';
3840

3941
/**
4042
* This number is based on the previous behavior - if we have message of height
@@ -76,12 +78,14 @@ interface IState {
7678
// be low as each event being loaded (after the first) is triggered by an explicit user action.
7779
@replaceableComponent("views.elements.ReplyChain")
7880
export default class ReplyChain extends React.Component<IProps, IState> {
79-
static contextType = MatrixClientContext;
81+
static contextType = RoomContext;
82+
public context!: React.ContextType<typeof RoomContext>;
83+
8084
private unmounted = false;
8185
private room: Room;
8286
private blockquoteRef = React.createRef<HTMLElement>();
8387

84-
constructor(props, context) {
88+
constructor(props: IProps, context: React.ContextType<typeof RoomContext>) {
8589
super(props, context);
8690

8791
this.state = {
@@ -91,7 +95,11 @@ export default class ReplyChain extends React.Component<IProps, IState> {
9195
err: false,
9296
};
9397

94-
this.room = this.context.getRoom(this.props.parentEv.getRoomId());
98+
this.room = this.matrixClient.getRoom(this.props.parentEv.getRoomId());
99+
}
100+
101+
private get matrixClient(): MatrixClient {
102+
return MatrixClientPeg.get();
95103
}
96104

97105
componentDidMount() {
@@ -158,7 +166,7 @@ export default class ReplyChain extends React.Component<IProps, IState> {
158166
try {
159167
// ask the client to fetch the event we want using the context API, only interface to do so is to ask
160168
// for a timeline with that event, but once it is loaded we can use findEventById to look up the ev map
161-
await this.context.getEventTimeline(this.room.getUnfilteredTimelineSet(), eventId);
169+
await this.matrixClient.getEventTimeline(this.room.getUnfilteredTimelineSet(), eventId);
162170
} catch (e) {
163171
// if it fails catch the error and return early, there's no point trying to find the event in this case.
164172
// Return null as it is falsey and thus should be treated as an error (as the event cannot be resolved).
@@ -198,16 +206,17 @@ export default class ReplyChain extends React.Component<IProps, IState> {
198206
render() {
199207
let header = null;
200208

209+
const inThread = this.context.timelineRenderingType === TimelineRenderingType.Thread;
201210
if (this.state.err) {
202211
header = <blockquote className="mx_ReplyChain mx_ReplyChain_error">
203212
{
204213
_t('Unable to load event that was replied to, ' +
205214
'it either does not exist or you do not have permission to view it.')
206215
}
207216
</blockquote>;
208-
} else if (this.state.loadedEv) {
217+
} else if (this.state.loadedEv && shouldDisplayReply(this.state.events[0], inThread)) {
209218
const ev = this.state.loadedEv;
210-
const room = this.context.getRoom(ev.getRoomId());
219+
const room = this.matrixClient.getRoom(ev.getRoomId());
211220
header = <blockquote className={`mx_ReplyChain ${this.getReplyChainColorClass(ev)}`}>
212221
{
213222
_t('<a>In reply to</a> <pill>', {}, {

src/utils/Reply.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export function makeReplyMixIn(ev?: MatrixEvent, inThread = false): RecursivePar
149149
'm.relates_to': {
150150
'm.in_reply_to': {
151151
'event_id': ev.getId(),
152-
'io.element.is_falling_back': !inThread, // MSC3440 unstable `is_falling_back` field
152+
'io.element.show_reply': inThread, // MSC3440 unstable `is_falling_back` field
153153
},
154154
},
155155
};
@@ -177,6 +177,5 @@ export function shouldDisplayReply(event: MatrixEvent, inThread = false): boolea
177177
if (!inThread) return true;
178178

179179
const inReplyTo = event.getRelation()?.["m.in_reply_to"];
180-
const isFallingBack = inReplyTo?.is_falling_back ?? inReplyTo?.["io.element.is_falling_back"];
181-
return !isFallingBack;
180+
return inReplyTo?.is_falling_back ?? inReplyTo?.["io.element.show_reply"] ?? false;
182181
}

0 commit comments

Comments
 (0)