@@ -145,13 +145,19 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
145
145
// First see if the receipt event is for our own user. If it was, trigger
146
146
// a room update (we probably read the room on a different device).
147
147
if ( readReceiptChangeIsFor ( payload . event , this . matrixClient ) ) {
148
- // TODO: Update room now that it's been read
149
- console . log ( payload ) ;
148
+ console . log ( `[RoomListDebug] Got own read receipt in ${ payload . event . roomId } ` ) ;
149
+ const room = this . matrixClient . getRoom ( payload . event . roomId ) ;
150
+ if ( ! room ) {
151
+ console . warn ( `Own read receipt was in unknown room ${ payload . event . roomId } ` ) ;
152
+ return ;
153
+ }
154
+ await this . handleRoomUpdate ( room , RoomUpdateCause . ReadReceipt ) ;
150
155
return ;
151
156
}
152
157
} else if ( payload . action === 'MatrixActions.Room.tags' ) {
153
- // TODO: Update room from tags
154
- console . log ( payload ) ;
158
+ const roomPayload = ( < any > payload ) ; // TODO: Type out the dispatcher types
159
+ console . log ( `[RoomListDebug] Got tag change in ${ roomPayload . room . roomId } ` ) ;
160
+ await this . handleRoomUpdate ( roomPayload . room , RoomUpdateCause . PossibleTagChange ) ;
155
161
} else if ( payload . action === 'MatrixActions.Room.timeline' ) {
156
162
const eventPayload = ( < any > payload ) ; // TODO: Type out the dispatcher types
157
163
@@ -189,23 +195,39 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
189
195
// cause inaccuracies with the list ordering. We may have to decrypt the last N messages of every room :(
190
196
await this . handleRoomUpdate ( room , RoomUpdateCause . Timeline ) ;
191
197
} else if ( payload . action === 'MatrixActions.accountData' && payload . event_type === 'm.direct' ) {
192
- // TODO: Update DMs
193
- console . log ( payload ) ;
198
+ const eventPayload = ( < any > payload ) ; // TODO: Type out the dispatcher types
199
+ console . log ( `[RoomListDebug] Received updated DM map` ) ;
200
+ const dmMap = eventPayload . event . getContent ( ) ;
201
+ for ( const userId of Object . keys ( dmMap ) ) {
202
+ const roomIds = dmMap [ userId ] ;
203
+ for ( const roomId of roomIds ) {
204
+ const room = this . matrixClient . getRoom ( roomId ) ;
205
+ if ( ! room ) {
206
+ console . warn ( `${ roomId } was found in DMs but the room is not in the store` ) ;
207
+ continue ;
208
+ }
209
+
210
+ // We expect this RoomUpdateCause to no-op if there's no change, and we don't expect
211
+ // the user to have hundreds of rooms to update in one event. As such, we just hammer
212
+ // away at updates until the problem is solved. If we were expecting more than a couple
213
+ // of rooms to be updated at once, we would consider batching the rooms up.
214
+ await this . handleRoomUpdate ( room , RoomUpdateCause . PossibleTagChange ) ;
215
+ }
216
+ }
194
217
} else if ( payload . action === 'MatrixActions.Room.myMembership' ) {
195
- // TODO: Improve new room check
196
218
const membershipPayload = ( < any > payload ) ; // TODO: Type out the dispatcher types
197
- if ( ! membershipPayload . oldMembership && membershipPayload . membership === "join" ) {
219
+ if ( membershipPayload . oldMembership !== "join" && membershipPayload . membership === "join" ) {
198
220
console . log ( `[RoomListDebug] Handling new room ${ membershipPayload . room . roomId } ` ) ;
199
221
await this . algorithm . handleRoomUpdate ( membershipPayload . room , RoomUpdateCause . NewRoom ) ;
222
+ return ;
200
223
}
201
224
202
- // TODO: Update room from membership change
203
- console . log ( payload ) ;
204
- } else if ( payload . action === 'MatrixActions.Room' ) {
205
- // TODO: Improve new room check
206
- // const roomPayload = (<any>payload); // TODO: Type out the dispatcher types
207
- // console.log(`[RoomListDebug] Handling new room ${roomPayload.room.roomId}`);
208
- // await this.algorithm.handleRoomUpdate(roomPayload.room, RoomUpdateCause.NewRoom);
225
+ // If it's not a join, it's transitioning into a different list (possibly historical)
226
+ if ( membershipPayload . oldMembership !== membershipPayload . membership ) {
227
+ console . log ( `[RoomListDebug] Handling membership change in ${ membershipPayload . room . roomId } ` ) ;
228
+ await this . algorithm . handleRoomUpdate ( membershipPayload . room , RoomUpdateCause . PossibleTagChange ) ;
229
+ return ;
230
+ }
209
231
} else if ( payload . action === 'view_room' ) {
210
232
// TODO: Update sticky room
211
233
console . log ( payload ) ;
0 commit comments