From de4773ba935bfc06391fb819e39680a41de9d31b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Feb 2017 15:50:30 +0000 Subject: [PATCH] Show when you've been kicked or banned Update the room state when you've been kicked or banned, and show a message in the preview bar, including the reason. --- src/components/structures/RoomView.js | 11 +++++ src/components/views/rooms/RoomPreviewBar.js | 50 +++++++++++++++++--- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 662d322fb4..5bf192dfc6 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -159,6 +159,7 @@ module.exports = React.createClass({ MatrixClientPeg.get().on("Room.name", this.onRoomName); MatrixClientPeg.get().on("Room.accountData", this.onRoomAccountData); MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember); + MatrixClientPeg.get().on("RoomMember.membership", this.onRoomMemberMembership); MatrixClientPeg.get().on("accountData", this.onAccountData); this.tabComplete = new TabComplete({ @@ -347,6 +348,7 @@ module.exports = React.createClass({ MatrixClientPeg.get().removeListener("Room.name", this.onRoomName); MatrixClientPeg.get().removeListener("Room.accountData", this.onRoomAccountData); MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember); + MatrixClientPeg.get().removeListener("RoomMember.membership", this.onRoomMemberMembership); MatrixClientPeg.get().removeListener("accountData", this.onAccountData); } @@ -612,6 +614,12 @@ module.exports = React.createClass({ this._updateRoomMembers(); }, + onRoomMemberMembership: function(ev, member, oldMembership) { + if (member.userId == MatrixClientPeg.get().credentials.userId) { + this.forceUpdate(); + } + }, + // rate limited because a power level change will emit an event for every // member in the room. _updateRoomMembers: new rate_limited_func(function() { @@ -1456,6 +1464,7 @@ module.exports = React.createClass({ />
{ name } : fallback; + }, + render: function() { var joinBlock, previewBlock; @@ -89,6 +96,16 @@ module.exports = React.createClass({
); } + const myMember = this.props.room ? this.props.room.currentState.members[ + MatrixClientPeg.get().credentials.userId + ] : null; + const kicked = ( + myMember && + myMember.membership == 'leave' && + myMember.events.member.getSender() != MatrixClientPeg.get().credentials.userId + ); + const banned = myMember && myMember.membership == 'ban'; + if (this.props.inviterName) { var emailMatchBlock; if (this.props.invitedEmail) { @@ -122,8 +139,31 @@ module.exports = React.createClass({
); - } - else if (this.props.error) { + } else if (kicked || banned) { + const verb = kicked ? 'kicked' : 'banned'; + const roomName = this._roomNameElement('this room'); + const kicker = MatrixClientPeg.get().getUser( + myMember.events.member.getSender() + ); + let reason; + if (myMember.events.member.getContent().reason) { + reason =
Reason: {myMember.events.member.getContent().reason}
+ } + let rejoinBlock; + if (!banned) { + rejoinBlock = Rejoin; + } + joinBlock = ( +
+
+ You have been {verb} from {roomName} by {kicker.displayName}.
+ {reason} + Forget
+ {rejoinBlock} +
+
+ ); + } else if (this.props.error) { var name = this.props.roomAlias || "This room"; var error; if (this.props.error.errcode == 'M_NOT_FOUND') { @@ -138,10 +178,8 @@ module.exports = React.createClass({ ); - } - else { - var name = this.props.room ? this.props.room.name : (this.props.room_alias || ""); - name = name ? { name } : "a room"; + } else { + const name = this._roomNameElement(); joinBlock = (