@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import React , { useContext , useEffect , useMemo , useRef , useState } from 'react' ;
17
+ import React , { useContext , useEffect , useRef , useState } from 'react' ;
18
18
import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set' ;
19
19
import { Room } from 'matrix-js-sdk/src/models/room' ;
20
20
import { RelationType } from 'matrix-js-sdk/src/@types/event' ;
@@ -25,6 +25,7 @@ import {
25
25
UNSTABLE_FILTER_RELATION_SENDERS ,
26
26
UNSTABLE_FILTER_RELATION_TYPES ,
27
27
} from 'matrix-js-sdk/src/filter' ;
28
+ import { ThreadEvent } from 'matrix-js-sdk/src/models/thread' ;
28
29
29
30
import BaseCard from "../views/right_panel/BaseCard" ;
30
31
import ResizeNotifier from '../../utils/ResizeNotifier' ;
@@ -37,6 +38,7 @@ import TimelinePanel from './TimelinePanel';
37
38
import { Layout } from '../../settings/enums/Layout' ;
38
39
import { TileShape } from '../views/rooms/EventTile' ;
39
40
import { RoomPermalinkCreator } from '../../utils/permalinks/Permalinks' ;
41
+ import { useEventEmitter } from '../../hooks/useEventEmitter' ;
40
42
41
43
async function getThreadTimelineSet (
42
44
client : MatrixClient ,
@@ -84,12 +86,18 @@ async function getThreadTimelineSet(
84
86
// filter fields. We fallback to the threads that have been discovered in
85
87
// the main timeline
86
88
const timelineSet = new EventTimelineSet ( room , { } ) ;
87
- for ( const [ , thread ] of room . threads ) {
88
- const isOwnEvent = thread . rootEvent . getSender ( ) === client . getUserId ( ) ;
89
- if ( filterType !== ThreadFilterType . My || isOwnEvent ) {
90
- timelineSet . getLiveTimeline ( ) . addEvent ( thread . rootEvent , false ) ;
91
- }
92
- }
89
+
90
+ Array . from ( room . threads )
91
+ . sort ( ( [ , threadA ] , [ , threadB ] ) => threadA . lastReply . getTs ( ) - threadB . lastReply . getTs ( ) )
92
+ . forEach ( ( [ , thread ] ) => {
93
+ const isOwnEvent = thread . rootEvent . getSender ( ) === client . getUserId ( ) ;
94
+ if ( filterType !== ThreadFilterType . My || isOwnEvent ) {
95
+ timelineSet . getLiveTimeline ( ) . addEvent ( thread . rootEvent , false ) ;
96
+ }
97
+ } ) ;
98
+
99
+ // for (const [, thread] of room.threads) {
100
+ // }
93
101
return timelineSet ;
94
102
}
95
103
}
@@ -210,18 +218,18 @@ const ThreadPanel: React.FC<IProps> = ({ roomId, onClose, permalinkCreator }) =>
210
218
const ref = useRef < TimelinePanel > ( ) ;
211
219
212
220
const [ timelineSet , setTimelineSet ] = useState < EventTimelineSet | null > ( null ) ;
213
- const timelineSetPromise = useMemo (
214
- async ( ) => {
215
- const timelineSet = getThreadTimelineSet ( mxClient , room , filterOption ) ;
216
- return timelineSet ;
217
- } ,
218
- [ mxClient , room , filterOption ] ,
219
- ) ;
220
221
useEffect ( ( ) => {
221
- timelineSetPromise
222
+ getThreadTimelineSet ( mxClient , room , filterOption )
222
223
. then ( timelineSet => { setTimelineSet ( timelineSet ) ; } )
223
224
. catch ( ( ) => setTimelineSet ( null ) ) ;
224
- } , [ timelineSetPromise ] ) ;
225
+ } , [ mxClient , room , filterOption ] ) ;
226
+
227
+ useEffect ( ( ) => {
228
+ if ( timelineSet ) ref . current . refreshTimeline ( ) ;
229
+ } , [ timelineSet , ref ] ) ;
230
+ useEventEmitter ( room , ThreadEvent . Update , ( ) => {
231
+ if ( timelineSet ) ref . current . refreshTimeline ( ) ;
232
+ } ) ;
225
233
226
234
return (
227
235
< RoomContext . Provider value = { {
0 commit comments