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

Commit 391ec4c

Browse files
authored
Handle thread bundled relationships coming from the server via MSC3666 (#8292)
1 parent 1e442b2 commit 391ec4c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/components/structures/RoomView.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License.
2323
import React, { createRef } from 'react';
2424
import classNames from 'classnames';
2525
import { IRecommendedVersion, NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models/room";
26-
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
26+
import { IThreadBundledRelationship, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
2727
import { EventSubscription } from "fbemitter";
2828
import { ISearchResults } from 'matrix-js-sdk/src/@types/search';
2929
import { logger } from "matrix-js-sdk/src/logger";
@@ -35,6 +35,7 @@ import { throttle } from "lodash";
3535
import { MatrixError } from 'matrix-js-sdk/src/http-api';
3636
import { ClientEvent } from "matrix-js-sdk/src/client";
3737
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
38+
import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread';
3839

3940
import shouldHideEvent from '../../shouldHideEvent';
4041
import { _t } from '../../languageHandler';
@@ -1358,7 +1359,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
13581359
this.handleSearchResult(searchPromise);
13591360
};
13601361

1361-
private handleSearchResult(searchPromise: Promise<any>): Promise<boolean> {
1362+
private handleSearchResult(searchPromise: Promise<ISearchResults>): Promise<boolean> {
13621363
// keep a record of the current search id, so that if the search terms
13631364
// change before we get a response, we can ignore the results.
13641365
const localSearchId = this.searchId;
@@ -1367,7 +1368,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
13671368
searchInProgress: true,
13681369
});
13691370

1370-
return searchPromise.then((results) => {
1371+
return searchPromise.then(async (results) => {
13711372
debuglog("search complete");
13721373
if (this.unmounted ||
13731374
this.state.timelineRenderingType !== TimelineRenderingType.Search ||
@@ -1394,6 +1395,18 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
13941395
return b.length - a.length;
13951396
});
13961397

1398+
// Process all thread roots returned in this batch of search results
1399+
// XXX: This won't work for results coming from Seshat which won't include the bundled relationship
1400+
for (const result of results.results) {
1401+
for (const event of result.context.getTimeline()) {
1402+
const bundledRelationship = event
1403+
.getServerAggregatedRelation<IThreadBundledRelationship>(THREAD_RELATION_TYPE.name);
1404+
if (!bundledRelationship || event.getThread()) continue;
1405+
const room = this.context.getRoom(event.getRoomId());
1406+
event.setThread(room.findThreadForEvent(event) ?? room.createThread(event, [], true));
1407+
}
1408+
}
1409+
13971410
this.setState({
13981411
searchHighlights: highlights,
13991412
searchResults: results,

0 commit comments

Comments
 (0)