Fix bug where rooms missing m.room.pinned_events could not pin messages

Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
Travis Ralston 2017-09-29 11:08:22 -06:00
parent f7389b70aa
commit 965a25ba84
1 changed files with 17 additions and 11 deletions

View File

@ -134,18 +134,24 @@ module.exports = React.createClass({
}, },
onPinClick: function() { onPinClick: function() {
MatrixClientPeg.get().getStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', '').then(event => { MatrixClientPeg.get().getStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', '')
const eventIds = (event ? event.pinned : []) || []; .then(null, e => {
if (!eventIds.includes(this.props.mxEvent.getId())) { // Intercept the Event Not Found error and fall through the promise chain with no event.
// Not pinned - add if (e.errcode === "M_NOT_FOUND") return null;
eventIds.push(this.props.mxEvent.getId()); throw e;
} else { })
// Pinned - remove .then(event => {
eventIds.splice(eventIds.indexOf(this.props.mxEvent.getId()), 1); const eventIds = (event ? event.pinned : []) || [];
} if (!eventIds.includes(this.props.mxEvent.getId())) {
// Not pinned - add
eventIds.push(this.props.mxEvent.getId());
} else {
// Pinned - remove
eventIds.splice(eventIds.indexOf(this.props.mxEvent.getId()), 1);
}
MatrixClientPeg.get().sendStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', {pinned: eventIds}, ''); MatrixClientPeg.get().sendStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', {pinned: eventIds}, '');
}); });
this.closeMenu(); this.closeMenu();
}, },