From 391ec4c7e2ddeb34513c6e6e9254f803a7f5e2c4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 12 Apr 2022 14:42:35 +0100 Subject: [PATCH] Handle thread bundled relationships coming from the server via MSC3666 (#8292) --- src/components/structures/RoomView.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 46183cdadb..1d363b649e 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -23,7 +23,7 @@ limitations under the License. import React, { createRef } from 'react'; import classNames from 'classnames'; import { IRecommendedVersion, NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models/room"; -import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event"; +import { IThreadBundledRelationship, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event"; import { EventSubscription } from "fbemitter"; import { ISearchResults } from 'matrix-js-sdk/src/@types/search'; import { logger } from "matrix-js-sdk/src/logger"; @@ -35,6 +35,7 @@ import { throttle } from "lodash"; import { MatrixError } from 'matrix-js-sdk/src/http-api'; import { ClientEvent } from "matrix-js-sdk/src/client"; import { CryptoEvent } from "matrix-js-sdk/src/crypto"; +import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread'; import shouldHideEvent from '../../shouldHideEvent'; import { _t } from '../../languageHandler'; @@ -1358,7 +1359,7 @@ export class RoomView extends React.Component { this.handleSearchResult(searchPromise); }; - private handleSearchResult(searchPromise: Promise): Promise { + private handleSearchResult(searchPromise: Promise): Promise { // keep a record of the current search id, so that if the search terms // change before we get a response, we can ignore the results. const localSearchId = this.searchId; @@ -1367,7 +1368,7 @@ export class RoomView extends React.Component { searchInProgress: true, }); - return searchPromise.then((results) => { + return searchPromise.then(async (results) => { debuglog("search complete"); if (this.unmounted || this.state.timelineRenderingType !== TimelineRenderingType.Search || @@ -1394,6 +1395,18 @@ export class RoomView extends React.Component { return b.length - a.length; }); + // Process all thread roots returned in this batch of search results + // XXX: This won't work for results coming from Seshat which won't include the bundled relationship + for (const result of results.results) { + for (const event of result.context.getTimeline()) { + const bundledRelationship = event + .getServerAggregatedRelation(THREAD_RELATION_TYPE.name); + if (!bundledRelationship || event.getThread()) continue; + const room = this.context.getRoom(event.getRoomId()); + event.setThread(room.findThreadForEvent(event) ?? room.createThread(event, [], true)); + } + } + this.setState({ searchHighlights: highlights, searchResults: results,