From 9e969e33b7223b839a4774dab4383460c681db0d Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 23 Feb 2018 10:32:33 +0000 Subject: [PATCH] Reorder the RoomListStore lists on Event.decrypted --- src/actions/MatrixActionCreators.js | 21 +++++++++++++++++++++ src/stores/RoomListStore.js | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/actions/MatrixActionCreators.js b/src/actions/MatrixActionCreators.js index 1998ecfef2..6e1d52a88f 100644 --- a/src/actions/MatrixActionCreators.js +++ b/src/actions/MatrixActionCreators.js @@ -163,6 +163,26 @@ function createRoomMembershipAction(matrixClient, membershipEvent, member, oldMe return { action: 'MatrixActions.RoomMember.membership', member }; } +/** + * @typedef EventDecryptedAction + * @type {Object} + * @property {string} action 'MatrixActions.Event.decrypted'. + * @property {MatrixEvent} event the matrix event that was decrypted. + */ + +/** + * Create a MatrixActions.Event.decrypted action that represents + * a MatrixClient `Event.decrypted` matrix event, emitted when a + * matrix event is decrypted. + * + * @param {MatrixClient} matrixClient the matrix client. + * @param {MatrixEvent} event the matrix event that was decrypted. + * @returns {EventDecryptedAction} an action of type `MatrixActions.Event.decrypted`. + */ +function createEventDecryptedAction(matrixClient, event) { + return { action: 'MatrixActions.Event.decrypted', event }; +} + /** * This object is responsible for dispatching actions when certain events are emitted by * the given MatrixClient. @@ -183,6 +203,7 @@ export default { this._addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction); this._addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction); this._addMatrixClientListener(matrixClient, 'RoomMember.membership', createRoomMembershipAction); + this._addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction); }, /** diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index 80db6ca9a8..7660cf8df8 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -87,6 +87,20 @@ class RoomListStore extends Store { this._generateRoomLists(); } break; + // When an event is decrypted, it could mean we need to reorder the room + // list because we now know the type of the event. + case 'MatrixActions.Event.decrypted': { + const room = this._matrixClient.getRoom(payload.event.getRoomId()); + const liveTimeline = room.getLiveTimeline(); + const eventTimeline = room.getTimelineForEvent(payload.event.getId()); + + if (!this._state.ready || + liveTimeline !== eventTimeline || + !this._eventTriggersRecentReorder(payload.event) + ) break; + this._generateRoomLists(); + } + break; case 'MatrixActions.accountData': { if (payload.event_type !== 'm.direct') break; this._generateRoomLists();