Skip to content

Commit 21d3cb0

Browse files
author
Germain
authored
Switch to using stable values for threads (matrix-org#8019)
1 parent d38a1fa commit 21d3cb0

File tree

12 files changed

+49
-47
lines changed

12 files changed

+49
-47
lines changed

src/ContentMessages.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ limitations under the License.
1919
import React from "react";
2020
import { MatrixClient } from "matrix-js-sdk/src/client";
2121
import { IUploadOpts } from "matrix-js-sdk/src/@types/requests";
22-
import { MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
22+
import { MsgType } from "matrix-js-sdk/src/@types/event";
2323
import encrypt from "browser-encrypt-attachment";
2424
import extractPngChunks from "png-chunks-extract";
2525
import { IAbortablePromise, IImageInfo } from "matrix-js-sdk/src/@types/partials";
2626
import { logger } from "matrix-js-sdk/src/logger";
2727
import { IEventRelation, ISendEventResponse } from "matrix-js-sdk/src/matrix";
28+
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
2829

2930
import { IEncryptedFile, IMediaEventInfo } from "./customisations/models/IMediaEventContent";
3031
import dis from './dispatcher/dispatcher';
@@ -658,7 +659,7 @@ export default class ContentMessages {
658659
return promBefore;
659660
}).then(function() {
660661
if (upload.canceled) throw new UploadCanceledError();
661-
const threadId = relation?.rel_type === RelationType.Thread
662+
const threadId = relation?.rel_type === THREAD_RELATION_TYPE.name
662663
? relation.event_id
663664
: null;
664665
const prom = matrixClient.sendMessage(roomId, threadId, content);

src/components/structures/ThreadPanel.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ limitations under the License.
1717
import React, { useContext, useEffect, useRef, useState } from 'react';
1818
import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set';
1919
import { Room } from 'matrix-js-sdk/src/models/room';
20-
import { RelationType } from 'matrix-js-sdk/src/@types/event';
2120
import { MatrixClient } from 'matrix-js-sdk/src/client';
2221
import {
2322
Filter,
2423
IFilterDefinition,
25-
UNSTABLE_FILTER_RELATED_BY_SENDERS,
26-
UNSTABLE_FILTER_RELATED_BY_REL_TYPES,
2724
} from 'matrix-js-sdk/src/filter';
28-
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
25+
import {
26+
FILTER_RELATED_BY_REL_TYPES,
27+
FILTER_RELATED_BY_SENDERS,
28+
Thread,
29+
ThreadEvent,
30+
THREAD_RELATION_TYPE,
31+
} from 'matrix-js-sdk/src/models/thread';
2932
import { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline';
3033

3134
import BaseCard from "../views/right_panel/BaseCard";
@@ -54,13 +57,13 @@ export async function getThreadTimelineSet(
5457
const definition: IFilterDefinition = {
5558
"room": {
5659
"timeline": {
57-
[UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
60+
[FILTER_RELATED_BY_REL_TYPES.name]: [THREAD_RELATION_TYPE.name],
5861
},
5962
},
6063
};
6164

6265
if (filterType === ThreadFilterType.My) {
63-
definition.room.timeline[UNSTABLE_FILTER_RELATED_BY_SENDERS.name] = [myUserId];
66+
definition.room.timeline[FILTER_RELATED_BY_SENDERS.name] = [myUserId];
6467
}
6568

6669
filter.setDefinition(definition);

src/components/structures/ThreadView.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React, { createRef, KeyboardEvent } from 'react';
18-
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
19-
import { RelationType } from 'matrix-js-sdk/src/@types/event';
18+
import { Thread, ThreadEvent, THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
2019
import { Room } from 'matrix-js-sdk/src/models/room';
2120
import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event';
2221
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
@@ -181,7 +180,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
181180
this.setState({
182181
thread,
183182
lastThreadReply: thread.lastReply((ev: MatrixEvent) => {
184-
return ev.isRelation(RelationType.Thread) && !ev.status;
183+
return ev.isRelation(THREAD_RELATION_TYPE.name) && !ev.status;
185184
}),
186185
}, async () => {
187186
thread.emit(ThreadEvent.ViewThread);
@@ -201,7 +200,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
201200
if (this.state.thread) {
202201
this.setState({
203202
lastThreadReply: this.state.thread.lastReply((ev: MatrixEvent) => {
204-
return ev.isRelation(RelationType.Thread) && !ev.status;
203+
return ev.isRelation(THREAD_RELATION_TYPE.name) && !ev.status;
205204
}),
206205
});
207206
}
@@ -288,7 +287,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
288287

289288
private get threadRelation(): IEventRelation {
290289
return {
291-
"rel_type": RelationType.Thread,
290+
"rel_type": THREAD_RELATION_TYPE.name,
292291
"event_id": this.state.thread?.id,
293292
"m.in_reply_to": {
294293
"event_id": this.state.lastThreadReply?.getId() ?? this.state.thread?.id,

src/components/views/location/shareLocation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { RelationType } from "matrix-js-sdk/src/@types/event";
1817
import { MatrixClient } from "matrix-js-sdk/src/client";
1918
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
2019
import { logger } from "matrix-js-sdk/src/logger";
2120
import { IEventRelation } from "matrix-js-sdk/src/models/event";
2221
import { LocationAssetType } from "matrix-js-sdk/src/@types/location";
22+
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
2323

2424
import { _t } from "../../../languageHandler";
2525
import Modal from "../../../Modal";
@@ -41,7 +41,7 @@ export const shareLocation = (
4141
) => async (uri: string, ts: number) => {
4242
if (!uri) return false;
4343
try {
44-
const threadId = relation?.rel_type === RelationType.Thread ? relation.event_id : null;
44+
const threadId = relation?.rel_type === THREAD_RELATION_TYPE.name ? relation.event_id : null;
4545
const assetType = shareType === LocationShareType.Pin ? LocationAssetType.Pin : LocationAssetType.Self;
4646
await client.sendMessage(roomId, threadId, makeLocationContent(undefined, uri, ts, undefined, assetType));
4747
} catch (e) {

src/components/views/rooms/MessageComposer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import classNames from 'classnames';
1919
import { IEventRelation, MatrixEvent } from "matrix-js-sdk/src/models/event";
2020
import { Room } from "matrix-js-sdk/src/models/room";
2121
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
22-
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
22+
import { EventType } from 'matrix-js-sdk/src/@types/event';
2323
import { Optional } from "matrix-events-sdk";
24+
import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
2425

2526
import { _t } from '../../../languageHandler';
2627
import { MatrixClientPeg } from '../../../MatrixClientPeg';
@@ -258,7 +259,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
258259

259260
private renderPlaceholderText = () => {
260261
if (this.props.replyToEvent) {
261-
const replyingToThread = this.props.relation?.rel_type === RelationType.Thread;
262+
const replyingToThread = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name;
262263
if (replyingToThread && this.props.e2eStatus) {
263264
return _t('Reply to encrypted thread…');
264265
} else if (replyingToThread) {
@@ -426,7 +427,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
426427
/>;
427428
}
428429

429-
const threadId = this.props.relation?.rel_type === RelationType.Thread
430+
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
430431
? this.props.relation.event_id
431432
: null;
432433

src/components/views/rooms/MessageComposerButtons.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { M_POLL_START } from "matrix-events-sdk";
2020
import React, { createContext, ReactElement, useContext, useRef } from 'react';
2121
import { Room } from 'matrix-js-sdk/src/models/room';
2222
import { MatrixClient } from 'matrix-js-sdk/src/client';
23-
import { RelationType } from 'matrix-js-sdk/src/@types/event';
23+
import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
2424

2525
import { _t } from '../../../languageHandler';
2626
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
@@ -318,7 +318,7 @@ class PollButton extends React.PureComponent<IPollButtonProps> {
318318
},
319319
);
320320
} else {
321-
const threadId = this.props.relation?.rel_type === RelationType.Thread
321+
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
322322
? this.props.relation.event_id
323323
: null;
324324

@@ -339,7 +339,7 @@ class PollButton extends React.PureComponent<IPollButtonProps> {
339339

340340
public render() {
341341
// do not allow sending polls within threads at this time
342-
if (this.props.relation?.rel_type === RelationType.Thread) return null;
342+
if (this.props.relation?.rel_type === THREAD_RELATION_TYPE.name) return null;
343343

344344
return (
345345
<CollapsibleButton

src/components/views/rooms/SendMessageComposer.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
2222
import { logger } from "matrix-js-sdk/src/logger";
2323
import { Room } from 'matrix-js-sdk/src/models/room';
2424
import { Composer as ComposerEvent } from "matrix-analytics-events/types/typescript/Composer";
25+
import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
2526

2627
import dis from '../../../dispatcher/dispatcher';
2728
import EditorModel from '../../../editor/model';
@@ -132,7 +133,7 @@ export function createMessageContent(
132133
addReplyToMessageContent(content, replyToEvent, {
133134
permalinkCreator,
134135
includeLegacyFallback: includeReplyLegacyFallback,
135-
inThread: relation?.rel_type === RelationType.Thread,
136+
inThread: relation?.rel_type === THREAD_RELATION_TYPE.name,
136137
});
137138
}
138139

@@ -204,7 +205,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
204205
}
205206

206207
public componentDidUpdate(prevProps: ISendMessageComposerProps): void {
207-
const replyingToThread = this.props.relation?.key === RelationType.Thread;
208+
const replyingToThread = this.props.relation?.key === THREAD_RELATION_TYPE.name;
208209
const differentEventTarget = this.props.relation?.event_id !== prevProps.relation?.event_id;
209210

210211
const threadChanged = replyingToThread && (differentEventTarget);
@@ -221,7 +222,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
221222
if (this.editorRef.current?.isComposing(event)) {
222223
return;
223224
}
224-
const replyingToThread = this.props.relation?.key === RelationType.Thread;
225+
const replyingToThread = this.props.relation?.key === THREAD_RELATION_TYPE.name;
225226
const action = getKeyBindingsManager().getMessageComposerAction(event);
226227
switch (action) {
227228
case KeyBindingAction.SendMessage:
@@ -358,7 +359,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
358359
eventName: "Composer",
359360
isEditing: false,
360361
isReply: !!this.props.replyToEvent,
361-
inThread: this.props.relation?.rel_type === RelationType.Thread,
362+
inThread: this.props.relation?.rel_type === THREAD_RELATION_TYPE.name,
362363
};
363364
if (posthogEvent.inThread) {
364365
const threadRoot = this.props.room.findEventById(this.props.relation.event_id);
@@ -383,7 +384,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
383384
if (!containsEmote(model) && isSlashCommand(this.model)) {
384385
const [cmd, args, commandText] = getSlashCommand(this.model);
385386
if (cmd) {
386-
const threadId = this.props.relation?.rel_type === RelationType.Thread
387+
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
387388
? this.props.relation?.event_id
388389
: null;
389390

@@ -398,7 +399,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
398399
addReplyToMessageContent(content, replyToEvent, {
399400
permalinkCreator: this.props.permalinkCreator,
400401
includeLegacyFallback: true,
401-
inThread: this.props.relation?.rel_type === RelationType.Thread,
402+
inThread: this.props.relation?.rel_type === THREAD_RELATION_TYPE.name,
402403
});
403404
}
404405
} else {
@@ -434,7 +435,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
434435
decorateStartSendingTime(content);
435436
}
436437

437-
const threadId = this.props.relation?.rel_type === RelationType.Thread
438+
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
438439
? this.props.relation.event_id
439440
: null;
440441

@@ -453,7 +454,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
453454
if (containsEmoji(content, effect.emojis)) {
454455
// For initial threads launch, chat effects are disabled
455456
// see #19731
456-
const isNotThread = this.props.relation?.rel_type !== RelationType.Thread;
457+
const isNotThread = this.props.relation?.rel_type !== THREAD_RELATION_TYPE.name;
457458
if (!SettingsStore.getValue("feature_thread") || isNotThread) {
458459
dis.dispatch({ action: `effects.${effect.command}` });
459460
}
@@ -497,7 +498,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
497498

498499
private get editorStateKey() {
499500
let key = `mx_cider_state_${this.props.room.roomId}`;
500-
if (this.props.relation?.rel_type === RelationType.Thread) {
501+
if (this.props.relation?.rel_type === THREAD_RELATION_TYPE.name) {
501502
key += `_${this.props.relation.event_id}`;
502503
}
503504
return key;
@@ -508,7 +509,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
508509
}
509510

510511
private restoreStoredEditorState(partCreator: PartCreator): Part[] {
511-
const replyingToThread = this.props.relation?.key === RelationType.Thread;
512+
const replyingToThread = this.props.relation?.key === THREAD_RELATION_TYPE.name;
512513
if (replyingToThread) {
513514
return null;
514515
}
@@ -600,7 +601,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
600601
};
601602

602603
render() {
603-
const threadId = this.props.relation?.rel_type === RelationType.Thread
604+
const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name
604605
? this.props.relation.event_id
605606
: null;
606607
return (

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import {
2929
WidgetEventCapability,
3030
WidgetKind,
3131
} from "matrix-widget-api";
32-
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
32+
import { EventType } from "matrix-js-sdk/src/@types/event";
3333
import { IContent, IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event";
3434
import { Room } from "matrix-js-sdk/src/models/room";
3535
import { logger } from "matrix-js-sdk/src/logger";
36+
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
3637

3738
import { iterableDiff, iterableIntersection } from "../../utils/iterables";
3839
import { MatrixClientPeg } from "../../MatrixClientPeg";
@@ -169,7 +170,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
169170
if (containsEmoji(content, effect.emojis)) {
170171
// For initial threads launch, chat effects are disabled
171172
// see #19731
172-
const isNotThread = content["m.relates_to"].rel_type !== RelationType.Thread;
173+
const isNotThread = content["m.relates_to"].rel_type !== THREAD_RELATION_TYPE.name;
173174
if (!SettingsStore.getValue("feature_thread") || isNotThread) {
174175
dis.dispatch({ action: `effects.${effect.command}` });
175176
}

src/utils/Reply.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ limitations under the License.
1515
*/
1616

1717
import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event";
18-
import { RelationType } from "matrix-js-sdk/src/@types/event";
1918
import sanitizeHtml from "sanitize-html";
2019
import escapeHtml from "escape-html";
20+
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
2121

2222
import { PERMITTED_URL_SCHEMES } from "../HtmlUtils";
2323
import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks";
@@ -163,7 +163,7 @@ export function makeReplyMixIn(ev?: MatrixEvent, inThread = false): RecursivePar
163163
if (ev.isThreadRelation) {
164164
mixin['m.relates_to'] = {
165165
...mixin['m.relates_to'],
166-
rel_type: RelationType.Thread,
166+
rel_type: THREAD_RELATION_TYPE.name,
167167
event_id: ev.threadRootId,
168168
};
169169
}

test/components/structures/ThreadPanel-test.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import React from 'react';
1818
import { shallow, mount } from "enzyme";
1919
import {
2020
MatrixClient,
21-
RelationType,
2221
Room,
23-
UNSTABLE_FILTER_RELATED_BY_REL_TYPES,
24-
UNSTABLE_FILTER_RELATED_BY_SENDERS,
2522
} from 'matrix-js-sdk/src/matrix';
2623
import { mocked } from 'jest-mock';
2724
import '../../skinned-sdk';
@@ -179,7 +176,7 @@ describe('ThreadPanel', () => {
179176
const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0];
180177
expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.All}`);
181178
expect(filter.getDefinition().room.timeline).toEqual({
182-
[UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
179+
related_by_rel_types: ["m.thread"],
183180
});
184181
});
185182

@@ -189,8 +186,8 @@ describe('ThreadPanel', () => {
189186
const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0];
190187
expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.My}`);
191188
expect(filter.getDefinition().room.timeline).toEqual({
192-
[UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
193-
[UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: [aliceId],
189+
related_by_rel_types: ["m.thread"],
190+
related_by_senders: [aliceId],
194191
});
195192
});
196193
});

0 commit comments

Comments
 (0)