@@ -103,7 +103,29 @@ export class RoomResource extends Resource<Args> {
103
103
if ( ! memberIds || ! memberIds . includes ( this . matrixService . aiBotUserId ) ) {
104
104
return ;
105
105
}
106
- await this . loadFromEvents ( roomId ) ;
106
+
107
+ let index = this . _messageCache . size ;
108
+ // This is brought up to this level so if the
109
+ // load task is rerun we can stop processing
110
+ for ( let event of this . sortedEvents ) {
111
+ switch ( event . type ) {
112
+ case 'm.room.member' :
113
+ await this . loadRoomMemberEvent ( roomId , event ) ;
114
+ break ;
115
+ case 'm.room.message' :
116
+ await this . loadRoomMessage ( { roomId, event, index } ) ;
117
+ break ;
118
+ case APP_BOXEL_COMMAND_RESULT_EVENT_TYPE :
119
+ this . updateMessageCommandResult ( { roomId, event, index } ) ;
120
+ break ;
121
+ case 'm.room.create' :
122
+ await this . loadRoomCreateEvent ( event ) ;
123
+ break ;
124
+ case 'm.room.name' :
125
+ await this . loadRoomNameEvent ( event ) ;
126
+ break ;
127
+ }
128
+ }
107
129
} catch ( e ) {
108
130
throw new Error ( `Error loading room ${ e } ` ) ;
109
131
}
@@ -280,30 +302,6 @@ export class RoomResource extends Resource<Args> {
280
302
}
281
303
} ) ;
282
304
283
- private async loadFromEvents ( roomId : string ) {
284
- let index = this . _messageCache . size ;
285
-
286
- for ( let event of this . sortedEvents ) {
287
- switch ( event . type ) {
288
- case 'm.room.member' :
289
- await this . loadRoomMemberEvent ( roomId , event ) ;
290
- break ;
291
- case 'm.room.message' :
292
- this . loadRoomMessage ( { roomId, event, index } ) ;
293
- break ;
294
- case APP_BOXEL_COMMAND_RESULT_EVENT_TYPE :
295
- this . updateMessageCommandResult ( { roomId, event, index } ) ;
296
- break ;
297
- case 'm.room.create' :
298
- await this . loadRoomCreateEvent ( event ) ;
299
- break ;
300
- case 'm.room.name' :
301
- await this . loadRoomNameEvent ( event ) ;
302
- break ;
303
- }
304
- }
305
- }
306
-
307
305
private async loadRoomMemberEvent (
308
306
roomId : string ,
309
307
event : InviteEvent | JoinEvent | LeaveEvent ,
0 commit comments