Store read pinned events as an array to avoid racing saves.

Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
Travis Ralston 2017-11-03 18:12:57 -06:00
parent 4f6cd6b23a
commit 3656fdb571
2 changed files with 10 additions and 9 deletions

View file

@ -79,21 +79,22 @@ module.exports = React.createClass({
const pinnedEvents = this.props.room.currentState.getStateEvents("m.room.pinned_events", ""); const pinnedEvents = this.props.room.currentState.getStateEvents("m.room.pinned_events", "");
if (!pinnedEvents) return; // nothing to read if (!pinnedEvents) return; // nothing to read
let lastReadEvent = null; let readStateEvents = null;
const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins"); const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins");
if (readPinsEvent) { if (readPinsEvent && readPinsEvent.getContent()) {
lastReadEvent = readPinsEvent.getContent().last_read_id; 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", { MatrixClientPeg.get().setRoomAccountData(this.props.room.roomId, "im.vector.room.read_pins", {
last_read_id: pinnedEvents.getId(), event_ids: readStateEvents,
}); });
} }
}, },
_getPinnedTiles: function() { _getPinnedTiles: function() {
if (this.state.pinned.length == 0) { if (this.state.pinned.length === 0) {
return (<div>{ _t("No pinned messages.") }</div>); return (<div>{ _t("No pinned messages.") }</div>);
} }

View file

@ -157,9 +157,9 @@ module.exports = React.createClass({
const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins"); const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins");
if (readPinsEvent) { if (readPinsEvent) {
const lastReadEvent = readPinsEvent.getContent().last_read_id; const readStateEvents = readPinsEvent.getContent().event_ids;
if (lastReadEvent) { if (readStateEvents) {
return currentPinEvent.getId() !== lastReadEvent; return !readStateEvents.includes(currentPinEvent.getId());
} }
} }