From 3656fdb571a63b9686856386cb8d78c5c5a572c1 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 3 Nov 2017 18:12:57 -0600 Subject: [PATCH] Store read pinned events as an array to avoid racing saves. Signed-off-by: Travis Ralston --- src/components/views/rooms/PinnedEventsPanel.js | 13 +++++++------ src/components/views/rooms/RoomHeader.js | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/views/rooms/PinnedEventsPanel.js b/src/components/views/rooms/PinnedEventsPanel.js index 5a99d9ab2d..ddadc30258 100644 --- a/src/components/views/rooms/PinnedEventsPanel.js +++ b/src/components/views/rooms/PinnedEventsPanel.js @@ -79,21 +79,22 @@ module.exports = React.createClass({ const pinnedEvents = this.props.room.currentState.getStateEvents("m.room.pinned_events", ""); if (!pinnedEvents) return; // nothing to read - let lastReadEvent = null; + let readStateEvents = null; const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins"); - if (readPinsEvent) { - lastReadEvent = readPinsEvent.getContent().last_read_id; + if (readPinsEvent && readPinsEvent.getContent()) { + readStateEvents = readPinsEvent.getContent().event_ids || []; } - if (lastReadEvent !== pinnedEvents.getId()) { + if (!readStateEvents.includes(pinnedEvents.getId())) { + readStateEvents.push(pinnedEvents.getId()); MatrixClientPeg.get().setRoomAccountData(this.props.room.roomId, "im.vector.room.read_pins", { - last_read_id: pinnedEvents.getId(), + event_ids: readStateEvents, }); } }, _getPinnedTiles: function() { - if (this.state.pinned.length == 0) { + if (this.state.pinned.length === 0) { return (
{ _t("No pinned messages.") }
); } diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index ea5748db60..2a06a90391 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -157,9 +157,9 @@ module.exports = React.createClass({ const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins"); if (readPinsEvent) { - const lastReadEvent = readPinsEvent.getContent().last_read_id; - if (lastReadEvent) { - return currentPinEvent.getId() !== lastReadEvent; + const readStateEvents = readPinsEvent.getContent().event_ids; + if (readStateEvents) { + return !readStateEvents.includes(currentPinEvent.getId()); } }