@@ -23,7 +23,7 @@ limitations under the License.
2323import React , { createRef } from 'react' ;
2424import classNames from 'classnames' ;
2525import { 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" ;
2727import { EventSubscription } from "fbemitter" ;
2828import { ISearchResults } from 'matrix-js-sdk/src/@types/search' ;
2929import { logger } from "matrix-js-sdk/src/logger" ;
@@ -35,6 +35,7 @@ import { throttle } from "lodash";
3535import { MatrixError } from 'matrix-js-sdk/src/http-api' ;
3636import { ClientEvent } from "matrix-js-sdk/src/client" ;
3737import { CryptoEvent } from "matrix-js-sdk/src/crypto" ;
38+ import { THREAD_RELATION_TYPE } from 'matrix-js-sdk/src/models/thread' ;
3839
3940import shouldHideEvent from '../../shouldHideEvent' ;
4041import { _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