Merge remote-tracking branch 'origin/develop' into travis/room-list/sticky

pull/21833/head
Travis Ralston 2020-06-07 13:06:30 -06:00
commit a7fe7cb28d
3 changed files with 46 additions and 16 deletions

View File

@ -165,13 +165,19 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
// First see if the receipt event is for our own user. If it was, trigger // First see if the receipt event is for our own user. If it was, trigger
// a room update (we probably read the room on a different device). // a room update (we probably read the room on a different device).
if (readReceiptChangeIsFor(payload.event, this.matrixClient)) { if (readReceiptChangeIsFor(payload.event, this.matrixClient)) {
// TODO: Update room now that it's been read console.log(`[RoomListDebug] Got own read receipt in ${payload.event.roomId}`);
console.log(payload); const room = this.matrixClient.getRoom(payload.event.roomId);
if (!room) {
console.warn(`Own read receipt was in unknown room ${payload.event.roomId}`);
return;
}
await this.handleRoomUpdate(room, RoomUpdateCause.ReadReceipt);
return; return;
} }
} else if (payload.action === 'MatrixActions.Room.tags') { } else if (payload.action === 'MatrixActions.Room.tags') {
// TODO: Update room from tags const roomPayload = (<any>payload); // TODO: Type out the dispatcher types
console.log(payload); console.log(`[RoomListDebug] Got tag change in ${roomPayload.room.roomId}`);
await this.handleRoomUpdate(roomPayload.room, RoomUpdateCause.PossibleTagChange);
} else if (payload.action === 'MatrixActions.Room.timeline') { } else if (payload.action === 'MatrixActions.Room.timeline') {
const eventPayload = (<any>payload); // TODO: Type out the dispatcher types const eventPayload = (<any>payload); // TODO: Type out the dispatcher types
@ -209,23 +215,39 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
// cause inaccuracies with the list ordering. We may have to decrypt the last N messages of every room :( // cause inaccuracies with the list ordering. We may have to decrypt the last N messages of every room :(
await this.handleRoomUpdate(room, RoomUpdateCause.Timeline); await this.handleRoomUpdate(room, RoomUpdateCause.Timeline);
} else if (payload.action === 'MatrixActions.accountData' && payload.event_type === 'm.direct') { } else if (payload.action === 'MatrixActions.accountData' && payload.event_type === 'm.direct') {
// TODO: Update DMs const eventPayload = (<any>payload); // TODO: Type out the dispatcher types
console.log(payload); console.log(`[RoomListDebug] Received updated DM map`);
const dmMap = eventPayload.event.getContent();
for (const userId of Object.keys(dmMap)) {
const roomIds = dmMap[userId];
for (const roomId of roomIds) {
const room = this.matrixClient.getRoom(roomId);
if (!room) {
console.warn(`${roomId} was found in DMs but the room is not in the store`);
continue;
}
// We expect this RoomUpdateCause to no-op if there's no change, and we don't expect
// the user to have hundreds of rooms to update in one event. As such, we just hammer
// away at updates until the problem is solved. If we were expecting more than a couple
// of rooms to be updated at once, we would consider batching the rooms up.
await this.handleRoomUpdate(room, RoomUpdateCause.PossibleTagChange);
}
}
} else if (payload.action === 'MatrixActions.Room.myMembership') { } else if (payload.action === 'MatrixActions.Room.myMembership') {
// TODO: Improve new room check
const membershipPayload = (<any>payload); // TODO: Type out the dispatcher types const membershipPayload = (<any>payload); // TODO: Type out the dispatcher types
if (!membershipPayload.oldMembership && membershipPayload.membership === "join") { if (membershipPayload.oldMembership !== "join" && membershipPayload.membership === "join") {
console.log(`[RoomListDebug] Handling new room ${membershipPayload.room.roomId}`); console.log(`[RoomListDebug] Handling new room ${membershipPayload.room.roomId}`);
await this.algorithm.handleRoomUpdate(membershipPayload.room, RoomUpdateCause.NewRoom); await this.algorithm.handleRoomUpdate(membershipPayload.room, RoomUpdateCause.NewRoom);
return;
} }
// TODO: Update room from membership change // If it's not a join, it's transitioning into a different list (possibly historical)
console.log(payload); if (membershipPayload.oldMembership !== membershipPayload.membership) {
} else if (payload.action === 'MatrixActions.Room') { console.log(`[RoomListDebug] Handling membership change in ${membershipPayload.room.roomId}`);
// TODO: Improve new room check await this.algorithm.handleRoomUpdate(membershipPayload.room, RoomUpdateCause.PossibleTagChange);
// const roomPayload = (<any>payload); // TODO: Type out the dispatcher types return;
// console.log(`[RoomListDebug] Handling new room ${roomPayload.room.roomId}`); }
// await this.algorithm.handleRoomUpdate(roomPayload.room, RoomUpdateCause.NewRoom);
} }
} }

View File

@ -177,6 +177,13 @@ export class ImportanceAlgorithm extends Algorithm {
} }
public async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise<boolean> { public async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise<boolean> {
if (cause === RoomUpdateCause.PossibleTagChange) {
// TODO: Be smarter and splice rather than regen the planet.
// TODO: No-op if no change.
await this.setKnownRooms(this.rooms);
return;
}
if (cause === RoomUpdateCause.NewRoom) { if (cause === RoomUpdateCause.NewRoom) {
// TODO: Be smarter and insert rather than regen the planet. // TODO: Be smarter and insert rather than regen the planet.
await this.setKnownRooms([room, ...this.rooms]); await this.setKnownRooms([room, ...this.rooms]);

View File

@ -38,7 +38,8 @@ export type TagID = string | DefaultTagID;
export enum RoomUpdateCause { export enum RoomUpdateCause {
Timeline = "TIMELINE", Timeline = "TIMELINE",
RoomRead = "ROOM_READ", // TODO: Use this. PossibleTagChange = "POSSIBLE_TAG_CHANGE",
ReadReceipt = "READ_RECEIPT",
NewRoom = "NEW_ROOM", NewRoom = "NEW_ROOM",
RoomRemoved = "ROOM_REMOVED", RoomRemoved = "ROOM_REMOVED",
} }