diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 8b0ddc8368..9a2b9ac79c 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -19,12 +19,13 @@ limitations under the License. import React from "react"; import { MatrixClient } from "matrix-js-sdk/src/client"; import { IUploadOpts } from "matrix-js-sdk/src/@types/requests"; -import { MsgType, RelationType } from "matrix-js-sdk/src/@types/event"; +import { MsgType } from "matrix-js-sdk/src/@types/event"; import encrypt from "browser-encrypt-attachment"; import extractPngChunks from "png-chunks-extract"; import { IAbortablePromise, IImageInfo } from "matrix-js-sdk/src/@types/partials"; import { logger } from "matrix-js-sdk/src/logger"; import { IEventRelation, ISendEventResponse } from "matrix-js-sdk/src/matrix"; +import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { IEncryptedFile, IMediaEventInfo } from "./customisations/models/IMediaEventContent"; import dis from './dispatcher/dispatcher'; @@ -658,7 +659,7 @@ export default class ContentMessages { return promBefore; }).then(function() { if (upload.canceled) throw new UploadCanceledError(); - const threadId = relation?.rel_type === RelationType.Thread + const threadId = relation?.rel_type === THREAD_RELATION_TYPE.name ? relation.event_id : null; const prom = matrixClient.sendMessage(roomId, threadId, content); diff --git a/src/components/structures/ThreadPanel.tsx b/src/components/structures/ThreadPanel.tsx index 98c1fff835..30669a8eec 100644 --- a/src/components/structures/ThreadPanel.tsx +++ b/src/components/structures/ThreadPanel.tsx @@ -17,15 +17,18 @@ limitations under the License. import React, { useContext, useEffect, useRef, useState } from 'react'; import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set'; import { Room } from 'matrix-js-sdk/src/models/room'; -import { RelationType } from 'matrix-js-sdk/src/@types/event'; import { MatrixClient } from 'matrix-js-sdk/src/client'; import { Filter, IFilterDefinition, - UNSTABLE_FILTER_RELATED_BY_SENDERS, - UNSTABLE_FILTER_RELATED_BY_REL_TYPES, } from 'matrix-js-sdk/src/filter'; -import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; +import { + FILTER_RELATED_BY_REL_TYPES, + FILTER_RELATED_BY_SENDERS, + Thread, + ThreadEvent, + THREAD_RELATION_TYPE, +} from 'matrix-js-sdk/src/models/thread'; import { EventTimeline } from 'matrix-js-sdk/src/models/event-timeline'; import BaseCard from "../views/right_panel/BaseCard"; @@ -54,13 +57,13 @@ export async function getThreadTimelineSet( const definition: IFilterDefinition = { "room": { "timeline": { - [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread], + [FILTER_RELATED_BY_REL_TYPES.name]: [THREAD_RELATION_TYPE.name], }, }, }; if (filterType === ThreadFilterType.My) { - definition.room.timeline[UNSTABLE_FILTER_RELATED_BY_SENDERS.name] = [myUserId]; + definition.room.timeline[FILTER_RELATED_BY_SENDERS.name] = [myUserId]; } filter.setDefinition(definition); diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index 8a00bbdc65..374ff1a2e4 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -15,8 +15,7 @@ limitations under the License. */ import React, { createRef, KeyboardEvent } from 'react'; -import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; -import { RelationType } from 'matrix-js-sdk/src/@types/event'; +import { Thread, ThreadEvent, THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread'; import { Room } from 'matrix-js-sdk/src/models/room'; import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window'; @@ -181,7 +180,7 @@ export default class ThreadView extends React.Component { this.setState({ thread, lastThreadReply: thread.lastReply((ev: MatrixEvent) => { - return ev.isRelation(RelationType.Thread) && !ev.status; + return ev.isRelation(THREAD_RELATION_TYPE.name) && !ev.status; }), }, async () => { thread.emit(ThreadEvent.ViewThread); @@ -201,7 +200,7 @@ export default class ThreadView extends React.Component { if (this.state.thread) { this.setState({ lastThreadReply: this.state.thread.lastReply((ev: MatrixEvent) => { - return ev.isRelation(RelationType.Thread) && !ev.status; + return ev.isRelation(THREAD_RELATION_TYPE.name) && !ev.status; }), }); } @@ -288,7 +287,7 @@ export default class ThreadView extends React.Component { private get threadRelation(): IEventRelation { return { - "rel_type": RelationType.Thread, + "rel_type": THREAD_RELATION_TYPE.name, "event_id": this.state.thread?.id, "m.in_reply_to": { "event_id": this.state.lastThreadReply?.getId() ?? this.state.thread?.id, diff --git a/src/components/views/location/shareLocation.ts b/src/components/views/location/shareLocation.ts index c7ea31bb26..b2632fa0f8 100644 --- a/src/components/views/location/shareLocation.ts +++ b/src/components/views/location/shareLocation.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { RelationType } from "matrix-js-sdk/src/@types/event"; import { MatrixClient } from "matrix-js-sdk/src/client"; import { makeLocationContent } from "matrix-js-sdk/src/content-helpers"; import { logger } from "matrix-js-sdk/src/logger"; import { IEventRelation } from "matrix-js-sdk/src/models/event"; import { LocationAssetType } from "matrix-js-sdk/src/@types/location"; +import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { _t } from "../../../languageHandler"; import Modal from "../../../Modal"; @@ -41,7 +41,7 @@ export const shareLocation = ( ) => async (uri: string, ts: number) => { if (!uri) return false; try { - const threadId = relation?.rel_type === RelationType.Thread ? relation.event_id : null; + const threadId = relation?.rel_type === THREAD_RELATION_TYPE.name ? relation.event_id : null; const assetType = shareType === LocationShareType.Pin ? LocationAssetType.Pin : LocationAssetType.Self; await client.sendMessage(roomId, threadId, makeLocationContent(undefined, uri, ts, undefined, assetType)); } catch (e) { diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 2ea6740ea8..6bd41fcf93 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -19,8 +19,9 @@ import classNames from 'classnames'; import { IEventRelation, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Room } from "matrix-js-sdk/src/models/room"; import { RoomMember } from "matrix-js-sdk/src/models/room-member"; -import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event'; +import { EventType } from 'matrix-js-sdk/src/@types/event'; import { Optional } from "matrix-events-sdk"; +import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread'; import { _t } from '../../../languageHandler'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; @@ -258,7 +259,7 @@ export default class MessageComposer extends React.Component { private renderPlaceholderText = () => { if (this.props.replyToEvent) { - const replyingToThread = this.props.relation?.rel_type === RelationType.Thread; + const replyingToThread = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name; if (replyingToThread && this.props.e2eStatus) { return _t('Reply to encrypted thread…'); } else if (replyingToThread) { @@ -426,7 +427,7 @@ export default class MessageComposer extends React.Component { />; } - const threadId = this.props.relation?.rel_type === RelationType.Thread + const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name ? this.props.relation.event_id : null; diff --git a/src/components/views/rooms/MessageComposerButtons.tsx b/src/components/views/rooms/MessageComposerButtons.tsx index 4dee986b03..fc7dd1ed84 100644 --- a/src/components/views/rooms/MessageComposerButtons.tsx +++ b/src/components/views/rooms/MessageComposerButtons.tsx @@ -20,7 +20,7 @@ import { M_POLL_START } from "matrix-events-sdk"; import React, { createContext, ReactElement, useContext, useRef } from 'react'; import { Room } from 'matrix-js-sdk/src/models/room'; import { MatrixClient } from 'matrix-js-sdk/src/client'; -import { RelationType } from 'matrix-js-sdk/src/@types/event'; +import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread'; import { _t } from '../../../languageHandler'; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; @@ -318,7 +318,7 @@ class PollButton extends React.PureComponent { }, ); } else { - const threadId = this.props.relation?.rel_type === RelationType.Thread + const threadId = this.props.relation?.rel_type === THREAD_RELATION_TYPE.name ? this.props.relation.event_id : null; @@ -339,7 +339,7 @@ class PollButton extends React.PureComponent { public render() { // do not allow sending polls within threads at this time - if (this.props.relation?.rel_type === RelationType.Thread) return null; + if (this.props.relation?.rel_type === THREAD_RELATION_TYPE.name) return null; return ( { const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0]; expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.All}`); expect(filter.getDefinition().room.timeline).toEqual({ - [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread], + related_by_rel_types: ["m.thread"], }); }); @@ -189,8 +186,8 @@ describe('ThreadPanel', () => { const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0]; expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.My}`); expect(filter.getDefinition().room.timeline).toEqual({ - [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread], - [UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: [aliceId], + related_by_rel_types: ["m.thread"], + related_by_senders: [aliceId], }); }); }); diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index cd98593385..1ae7b141f4 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -18,7 +18,6 @@ import React from "react"; import { act } from "react-dom/test-utils"; import { sleep } from "matrix-js-sdk/src/utils"; import { mount } from 'enzyme'; -import { RelationType } from 'matrix-js-sdk/src/@types/event'; import '../../../skinned-sdk'; // Must be first for skinning to work import SendMessageComposer, { @@ -298,7 +297,7 @@ describe('', () => { placeholder="" permalinkCreator={new MatrixToPermalinkConstructor() as any} relation={{ - rel_type: RelationType.Thread, + rel_type: "m.thread", event_id: "myFakeThreadId", }} includeReplyLegacyFallback={false} diff --git a/test/test-utils/threads.ts b/test/test-utils/threads.ts index 1df62e51d7..ebed292eb5 100644 --- a/test/test-utils/threads.ts +++ b/test/test-utils/threads.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { MatrixClient, MatrixEvent, RelationType, Room } from "matrix-js-sdk/src/matrix"; +import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; import { Thread } from "matrix-js-sdk/src/models/thread"; import { mkMessage, MessageEventProps } from "./test-utils"; @@ -25,7 +25,7 @@ export const makeThreadEvent = ({ rootEventId, replyToEventId, ...props }: Messa ...props, relatesTo: { event_id: rootEventId, - rel_type: RelationType.Thread, + rel_type: "m.thread", ['m.in_reply_to']: { event_id: replyToEventId, }, @@ -79,7 +79,7 @@ export const makeThreadEvents = ({ rootEvent.setUnsigned({ "m.relations": { - [RelationType.Thread]: { + "m.thread": { latest_event: events[events.length - 1], count: length, current_user_participated: [...participantUserIds, authorId].includes(currentUserId),