@@ -15,9 +15,13 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from 'react' ;
18
- import { IEventRelation , MatrixEvent , Room } from 'matrix-js-sdk/src' ;
19
18
import { Thread , ThreadEvent } from 'matrix-js-sdk/src/models/thread' ;
20
19
import { RelationType } from 'matrix-js-sdk/src/@types/event' ;
20
+ import { Room } from 'matrix-js-sdk/src/models/room' ;
21
+ import { IEventRelation , MatrixEvent } from 'matrix-js-sdk/src/models/event' ;
22
+ import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window' ;
23
+ import { Direction } from 'matrix-js-sdk/src/models/event-timeline' ;
24
+ import { IRelationsRequestOpts } from 'matrix-js-sdk/src/@types/requests' ;
21
25
import classNames from "classnames" ;
22
26
23
27
import BaseCard from "../views/right_panel/BaseCard" ;
@@ -141,7 +145,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
141
145
private setupThread = ( mxEv : MatrixEvent ) => {
142
146
let thread = this . props . room . threads ?. get ( mxEv . getId ( ) ) ;
143
147
if ( ! thread ) {
144
- thread = this . props . room . createThread ( [ mxEv ] ) ;
148
+ thread = this . props . room . createThread ( mxEv ) ;
145
149
}
146
150
thread . on ( ThreadEvent . Update , this . updateLastThreadReply ) ;
147
151
thread . once ( ThreadEvent . Ready , this . updateThread ) ;
@@ -167,10 +171,13 @@ export default class ThreadView extends React.Component<IProps, IState> {
167
171
this . setState ( {
168
172
thread,
169
173
lastThreadReply : thread . lastReply ( ( ev : MatrixEvent ) => {
170
- return ! ev . status ;
174
+ return ev . isThreadRelation && ! ev . status ;
171
175
} ) ,
172
- } , ( ) => {
176
+ } , async ( ) => {
173
177
thread . emit ( ThreadEvent . ViewThread ) ;
178
+ if ( ! thread . initialEventsFetched ) {
179
+ await thread . fetchInitialEvents ( ) ;
180
+ }
174
181
this . timelinePanelRef . current ?. refreshTimeline ( ) ;
175
182
} ) ;
176
183
}
@@ -180,7 +187,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
180
187
if ( this . state . thread ) {
181
188
this . setState ( {
182
189
lastThreadReply : this . state . thread . lastReply ( ( ev : MatrixEvent ) => {
183
- return ! ev . status ;
190
+ return ev . isThreadRelation && ! ev . status ;
184
191
} ) ,
185
192
} ) ;
186
193
}
@@ -207,6 +214,31 @@ export default class ThreadView extends React.Component<IProps, IState> {
207
214
</ div > ;
208
215
} ;
209
216
217
+ private onPaginationRequest = async (
218
+ timelineWindow : TimelineWindow | null ,
219
+ direction = Direction . Backward ,
220
+ limit = 20 ,
221
+ ) : Promise < boolean > => {
222
+ if ( ! this . state . thread . hasServerSideSupport ) {
223
+ return false ;
224
+ }
225
+
226
+ const timelineIndex = timelineWindow . getTimelineIndex ( direction ) ;
227
+
228
+ const paginationKey = direction === Direction . Backward ? "from" : "to" ;
229
+ const paginationToken = timelineIndex . timeline . getPaginationToken ( direction ) ;
230
+
231
+ const opts : IRelationsRequestOpts = {
232
+ limit,
233
+ [ paginationKey ] : paginationToken ,
234
+ direction,
235
+ } ;
236
+
237
+ await this . state . thread . fetchEvents ( opts ) ;
238
+
239
+ return timelineWindow . paginate ( direction , limit ) ;
240
+ } ;
241
+
210
242
public render ( ) : JSX . Element {
211
243
const highlightedEventId = this . props . isInitialEventHighlighted
212
244
? this . props . initialEvent ?. getId ( )
@@ -262,6 +294,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
262
294
eventId = { this . props . initialEvent ?. getId ( ) }
263
295
highlightedEventId = { highlightedEventId }
264
296
onUserScroll = { this . onScroll }
297
+ onPaginationRequest = { this . onPaginationRequest }
265
298
/>
266
299
) }
267
300
0 commit comments