@@ -4,7 +4,7 @@ import { debounce } from '@ember/runloop';
4
4
import Service , { service } from '@ember/service' ;
5
5
import { cached , tracked } from '@glimmer/tracking' ;
6
6
7
- import { task , timeout , restartableTask } from 'ember-concurrency' ;
7
+ import { restartableTask , task } from 'ember-concurrency' ;
8
8
import window from 'ember-window-mock' ;
9
9
import { cloneDeep } from 'lodash' ;
10
10
import {
@@ -14,12 +14,7 @@ import {
14
14
type EmittedEvents ,
15
15
type ISendEventResponse ,
16
16
} from 'matrix-js-sdk' ;
17
- import {
18
- SlidingSync ,
19
- MSC3575List ,
20
- SlidingSyncEvent ,
21
- } from 'matrix-js-sdk/lib/sliding-sync' ;
22
- import { SlidingSyncState } from 'matrix-js-sdk/lib/sliding-sync' ;
17
+ import { SlidingSync , MSC3575List } from 'matrix-js-sdk/lib/sliding-sync' ;
23
18
import stringify from 'safe-stable-stringify' ;
24
19
import { md5 } from 'super-fast-md5' ;
25
20
import { TrackedMap } from 'tracked-built-ins' ;
@@ -123,7 +118,7 @@ const MAX_CARD_SIZE_KB = 60;
123
118
const STATE_EVENTS_OF_INTEREST = [ 'm.room.create' , 'm.room.name' ] ;
124
119
const SLIDING_SYNC_AI_ROOM_LIST_NAME = 'ai-room' ;
125
120
const SLIDING_SYNC_AUTH_ROOM_LIST_NAME = 'auth-room' ;
126
- const SLIDING_SYNC_LIST_RANGE_SIZE = 2 ;
121
+ const SLIDING_SYNC_LIST_RANGE_SIZE = 10 ;
127
122
const SLIDING_SYNC_LIST_TIMELINE_LIMIT = 1 ;
128
123
129
124
const realmEventsLogger = logger ( 'realm:events' ) ;
@@ -151,10 +146,6 @@ export default class MatrixService extends Service {
151
146
@tracked private _currentRoomId : string | undefined ;
152
147
@tracked private timelineLoadingState : Map < string , boolean > =
153
148
new TrackedMap ( ) ;
154
- @tracked private currentAiRoomListRange = SLIDING_SYNC_LIST_RANGE_SIZE ;
155
- @tracked private totalAiRooms ?: number ;
156
- @tracked private totalAuthRooms ?: number ;
157
- @tracked private currentAuthRoomListRange = SLIDING_SYNC_LIST_RANGE_SIZE ;
158
149
159
150
profile = getMatrixProfile ( this , ( ) => this . userId ) ;
160
151
@@ -198,7 +189,7 @@ export default class MatrixService extends Service {
198
189
set currentRoomId ( value : string | undefined ) {
199
190
this . _currentRoomId = value ;
200
191
if ( value ) {
201
- this . loadAllTimelineEvents ( value ) ;
192
+ this . loadAllTimelineEvents . perform ( value ) ;
202
193
window . localStorage . setItem ( CurrentRoomIdPersistenceKey , value ) ;
203
194
} else {
204
195
window . localStorage . removeItem ( CurrentRoomIdPersistenceKey ) ;
@@ -545,98 +536,9 @@ export default class MatrixService extends Service {
545
536
3000 ,
546
537
) ;
547
538
548
- this . slidingSync . on ( SlidingSyncEvent . Lifecycle , ( state , response ) => {
549
- if ( state !== SlidingSyncState . Complete || ! response ) {
550
- return ;
551
- }
552
-
553
- // Handle AI rooms
554
- if (
555
- response . lists [ SLIDING_SYNC_AI_ROOM_LIST_NAME ] ?. ops ?. [ 0 ] . op === 'SYNC'
556
- ) {
557
- if (
558
- response . lists ?. [ SLIDING_SYNC_AI_ROOM_LIST_NAME ] ?. count !== undefined
559
- ) {
560
- this . totalAiRooms =
561
- response . lists [ SLIDING_SYNC_AI_ROOM_LIST_NAME ] . count ;
562
- const currentRange =
563
- response . lists [ SLIDING_SYNC_AI_ROOM_LIST_NAME ] . ops ?. [ 0 ] ?. range ;
564
-
565
- if ( currentRange ) {
566
- this . currentAiRoomListRange = currentRange [ 1 ] ;
567
- this . maybeLoadMoreAiRooms . perform ( ) ;
568
- }
569
- }
570
- }
571
-
572
- // Handle Auth rooms
573
- if (
574
- response . lists [ SLIDING_SYNC_AUTH_ROOM_LIST_NAME ] ?. ops ?. [ 0 ] . op === 'SYNC'
575
- ) {
576
- if (
577
- response . lists ?. [ SLIDING_SYNC_AUTH_ROOM_LIST_NAME ] ?. count !==
578
- undefined
579
- ) {
580
- this . totalAuthRooms =
581
- response . lists [ SLIDING_SYNC_AUTH_ROOM_LIST_NAME ] . count ;
582
- const currentAuthRange =
583
- response . lists [ SLIDING_SYNC_AUTH_ROOM_LIST_NAME ] . ops ?. [ 0 ] ?. range ;
584
-
585
- if ( currentAuthRange ) {
586
- this . currentAuthRoomListRange = currentAuthRange [ 1 ] ;
587
- this . maybeLoadMoreAuthRooms . perform ( ) ;
588
- }
589
- }
590
- }
591
- } ) ;
592
-
593
539
return this . slidingSync ;
594
540
}
595
541
596
- private maybeLoadMoreAiRooms = restartableTask ( async ( ) => {
597
- if ( ! this . totalAiRooms || ! this . slidingSync ) {
598
- return ;
599
- }
600
-
601
- while ( this . currentAiRoomListRange < this . totalAiRooms ) {
602
- const nextRange = Math . min (
603
- this . currentAiRoomListRange + 2 ,
604
- this . totalAiRooms ,
605
- ) ;
606
-
607
- try {
608
- await this . slidingSync . setListRanges ( 'ai-room' , [ [ 0 , nextRange ] ] ) ;
609
- this . currentAiRoomListRange = nextRange ;
610
- await timeout ( 500 ) ;
611
- } catch ( error ) {
612
- console . error ( 'Error expanding room range:' , error ) ;
613
- break ;
614
- }
615
- }
616
- } ) ;
617
-
618
- private maybeLoadMoreAuthRooms = restartableTask ( async ( ) => {
619
- if ( ! this . totalAuthRooms || ! this . slidingSync ) {
620
- return ;
621
- }
622
-
623
- while ( this . currentAuthRoomListRange < this . totalAuthRooms ) {
624
- const nextRange = Math . min (
625
- this . currentAuthRoomListRange + 2 ,
626
- this . totalAuthRooms ,
627
- ) ;
628
-
629
- try {
630
- await this . slidingSync . setListRanges ( 'auth-room' , [ [ 0 , nextRange ] ] ) ;
631
- this . currentAuthRoomListRange = nextRange ;
632
- await timeout ( 500 ) ;
633
- } catch ( error ) {
634
- console . error ( 'Error expanding auth room range:' , error ) ;
635
- break ;
636
- }
637
- }
638
- } ) ;
639
-
640
542
private async loginToRealms ( ) {
641
543
// This is where we would actually load user-specific choices out of the
642
544
// user's profile based on this.client.getUserId();
@@ -1270,7 +1172,7 @@ export default class MatrixService extends Service {
1270
1172
return await this . client . isUsernameAvailable ( username ) ;
1271
1173
}
1272
1174
1273
- private async loadAllTimelineEvents ( roomId : string ) {
1175
+ private loadAllTimelineEvents = restartableTask ( async ( roomId : string ) => {
1274
1176
let roomData = this . ensureRoomData ( roomId ) ;
1275
1177
let room = this . client . getRoom ( roomId ) ;
1276
1178
@@ -1282,25 +1184,15 @@ export default class MatrixService extends Service {
1282
1184
try {
1283
1185
while ( room . oldState . paginationToken != null ) {
1284
1186
await this . client . scrollback ( room ) ;
1285
- await timeout ( 1000 ) ;
1286
1187
let rs = room . getLiveTimeline ( ) . getState ( 'f' as MatrixSDK . Direction ) ;
1287
1188
if ( rs ) {
1288
1189
roomData . notifyRoomStateUpdated ( rs ) ;
1289
1190
}
1290
1191
}
1291
-
1292
- const timeline = room . getLiveTimeline ( ) ;
1293
- const events = timeline . getEvents ( ) ;
1294
- for ( let event of events ) {
1295
- await this . processDecryptedEvent ( this . buildEventForProcessing ( event ) ) ;
1296
- }
1297
- } catch ( error ) {
1298
- console . error ( 'Error loading timeline events:' , error ) ;
1299
- throw error ;
1300
1192
} finally {
1301
1193
this . timelineLoadingState . set ( roomId , false ) ;
1302
1194
}
1303
- }
1195
+ } ) ;
1304
1196
1305
1197
get isLoadingTimeline ( ) {
1306
1198
if ( ! this . currentRoomId ) {
@@ -1575,7 +1467,7 @@ export default class MatrixService extends Service {
1575
1467
return ;
1576
1468
}
1577
1469
1578
- let roomData = await this . getRoomData ( roomId ) ;
1470
+ let roomData = this . getRoomData ( roomId ) ;
1579
1471
// patch in any missing room events--this will support dealing with local
1580
1472
// echoes, migrating older histories as well as handle any matrix syncing gaps
1581
1473
// that might occur
0 commit comments