From f9d5c11d8d373ce6d521ce436b5e6ccdaa4604aa Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 4 Nov 2018 19:47:24 -0700 Subject: [PATCH 1/2] Regenerate the room list when m.fully_read is issued Not doing so results in the RoomListStore tracking stale data when the user reads messages on another device. The visual effect of this is rooms being incorrectly pinned in places they shouldn't be, such as the top of the list. This also fixes another visual bug where rooms don't move down once their timelines are read. This second issue is mot prominent when multiple rooms have been pinned to the top, and the middle one is read ahead of the others - it'll stick around until some other condition decides to wipe the room's cached state. Fixes https://github.com/vector-im/riot-web/issues/7653 --- src/actions/MatrixActionCreators.js | 30 +++++++++++++++++++++++++++++ src/stores/RoomListStore.js | 7 +++++++ 2 files changed, 37 insertions(+) diff --git a/src/actions/MatrixActionCreators.js b/src/actions/MatrixActionCreators.js index 31bcac3e52..2f2c23d06f 100644 --- a/src/actions/MatrixActionCreators.js +++ b/src/actions/MatrixActionCreators.js @@ -62,6 +62,35 @@ function createAccountDataAction(matrixClient, accountDataEvent) { }; } +/** + * @typedef RoomAccountDataAction + * @type {Object} + * @property {string} action 'MatrixActions.Room.accountData'. + * @property {MatrixEvent} event the MatrixEvent that triggered the dispatch. + * @property {string} event_type the type of the MatrixEvent, e.g. "m.direct". + * @property {Object} event_content the content of the MatrixEvent. + * @property {Room} room the room where the account data was changed. + */ + +/** + * Create a MatrixActions.Room.accountData action that represents a MatrixClient `Room.accountData` + * matrix event. + * + * @param {MatrixClient} matrixClient the matrix client. + * @param {MatrixEvent} accountDataEvent the account data event. + * @param {Room} room the room where account data was changed + * @returns {RoomAccountDataAction} an action of type MatrixActions.accountData. + */ +function createRoomAccountDataAction(matrixClient, accountDataEvent, room) { + return { + action: 'MatrixActions.Room.accountData', + event: accountDataEvent, + event_type: accountDataEvent.getType(), + event_content: accountDataEvent.getContent(), + room: room, + }; +} + /** * @typedef RoomAction * @type {Object} @@ -201,6 +230,7 @@ export default { start(matrixClient) { this._addMatrixClientListener(matrixClient, 'sync', createSyncAction); this._addMatrixClientListener(matrixClient, 'accountData', createAccountDataAction); + this._addMatrixClientListener(matrixClient, 'Room.accountData', createRoomAccountDataAction); this._addMatrixClientListener(matrixClient, 'Room', createRoomAction); this._addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction); this._addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction); diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index 2b70d53b59..0f8e5d7b4d 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -142,6 +142,13 @@ class RoomListStore extends Store { this._generateRoomLists(); } break; + case 'MatrixActions.Room.accountData': { + if (payload.event_type === 'm.fully_read') { + this._clearCachedRoomState(payload.room.roomId); + this._generateRoomLists(); + } + } + break; case 'MatrixActions.Room.myMembership': { this._generateRoomLists(); } From ec2528e8b5f1c015e1c35e2f87c9c9eb9f748344 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 4 Nov 2018 23:00:47 -0700 Subject: [PATCH 2/2] Update MatrixActionCreators.js --- src/actions/MatrixActionCreators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/MatrixActionCreators.js b/src/actions/MatrixActionCreators.js index 2f2c23d06f..c1d42ffd0d 100644 --- a/src/actions/MatrixActionCreators.js +++ b/src/actions/MatrixActionCreators.js @@ -79,7 +79,7 @@ function createAccountDataAction(matrixClient, accountDataEvent) { * @param {MatrixClient} matrixClient the matrix client. * @param {MatrixEvent} accountDataEvent the account data event. * @param {Room} room the room where account data was changed - * @returns {RoomAccountDataAction} an action of type MatrixActions.accountData. + * @returns {RoomAccountDataAction} an action of type MatrixActions.Room.accountData. */ function createRoomAccountDataAction(matrixClient, accountDataEvent, room) { return {