From eb91faf55401754c4b449b53e2e2c80e97495fb9 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 16 Feb 2016 16:05:27 +0000 Subject: [PATCH] Handle redacted events matrix-js-sdk now retains redacted events. Filter them out of the timeline. Also put empty placeholders in the dom so that if we try to scroll to a redacted event, we don't end up blowing up. --- src/components/structures/RoomView.js | 38 +++++++++++++++++++------ src/components/views/rooms/EventTile.js | 1 + 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 25c289ba96..db18fe92c5 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -114,6 +114,7 @@ module.exports = React.createClass({ this.dispatcherRef = dis.register(this.onAction); MatrixClientPeg.get().on("Room", this.onRoom); MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline); + MatrixClientPeg.get().on("Room.redaction", this.onRoomRedaction); MatrixClientPeg.get().on("Room.name", this.onRoomName); MatrixClientPeg.get().on("Room.accountData", this.onRoomAccountData); MatrixClientPeg.get().on("Room.receipt", this.onRoomReceipt); @@ -259,6 +260,7 @@ module.exports = React.createClass({ if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("Room", this.onRoom); MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline); + MatrixClientPeg.get().removeListener("Room.redaction", this.onRoomRedaction); MatrixClientPeg.get().removeListener("Room.name", this.onRoomName); MatrixClientPeg.get().removeListener("Room.accountData", this.onRoomAccountData); MatrixClientPeg.get().removeListener("Room.receipt", this.onRoomReceipt); @@ -377,6 +379,17 @@ module.exports = React.createClass({ } }, + onRoomRedaction: function(ev, room) { + if (this.unmounted) return; + + // ignore events for other rooms + if (room.roomId != this.props.roomId) return; + + // we could skip an update if the event isn't in our timeline, + // but that's probably an early optimisation. + this.forceUpdate(); + }, + _calculatePeekRules: function(room) { var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", ""); if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") { @@ -969,17 +982,31 @@ module.exports = React.createClass({ var readMarkerIndex; for (var i = 0; i < this.state.events.length; i++) { var mxEv = this.state.events[i]; + var eventId = mxEv.getId(); + + // we can't use local echoes as scroll tokens, because their event IDs change. + // Local echos have a send "status". + var scrollToken = mxEv.status ? undefined : eventId; + + var wantTile = true; if (!EventTile.haveTileForEvent(mxEv)) { - continue; + wantTile = false; } - if (this.props.ConferenceHandler && mxEv.getType() === "m.room.member") { + else if (this.props.ConferenceHandler && mxEv.getType() === "m.room.member") { if (this.props.ConferenceHandler.isConferenceUser(mxEv.getSender()) || this.props.ConferenceHandler.isConferenceUser(mxEv.getStateKey())) { - continue; // suppress conf user join/parts + wantTile = false; // suppress conf user join/parts } } + if (!wantTile) { + // if we aren't showing the event, put in a dummy scroll token anyway, so + // that we can scroll to the right place. + ret.push(
  • ); + continue; + } + // now we've decided whether or not to show this message, // add the read up to marker if appropriate // doing this here means we implicitly do not show the marker @@ -1028,13 +1055,8 @@ module.exports = React.createClass({ last = true; } - var eventId = mxEv.getId(); var highlight = (eventId == this.props.highlightedEventId); - // we can't use local echoes as scroll tokens, because their event IDs change. - // Local echos have a send "status". - var scrollToken = mxEv.status ? undefined : eventId; - ret.push(