From 3838569625ab2114ca127a1fc620d456670e19c3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 22 Sep 2015 16:37:39 +0100 Subject: [PATCH] Port memberlist branch fixes --- src/Modal.js | 4 +- src/controllers/molecules/MemberInfo.js | 94 ++++++++++++------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Modal.js b/src/Modal.js index d18b39e68b..ba7660bf9d 100644 --- a/src/Modal.js +++ b/src/Modal.js @@ -47,11 +47,11 @@ module.exports = { // FIXME: If a dialog uses getDefaultProps it clobbers the onFinished // property set here so you can't close the dialog from a button click! var dialog = ( -
+
-
+
); diff --git a/src/controllers/molecules/MemberInfo.js b/src/controllers/molecules/MemberInfo.js index 8c34127b73..0fcbb22f87 100644 --- a/src/controllers/molecules/MemberInfo.js +++ b/src/controllers/molecules/MemberInfo.js @@ -16,8 +16,6 @@ limitations under the License. /* * State vars: - * 'presence' : string (online|offline|unavailable etc) - * 'active' : number (ms ago; can be -1) * 'can': { * kick: boolean, * ban: boolean, @@ -32,59 +30,22 @@ var MatrixClientPeg = require("../../MatrixClientPeg"); var dis = require("../../dispatcher"); var Modal = require("../../Modal"); var sdk = require('../../index'); +var Loader = require("react-loader"); module.exports = { componentDidMount: function() { var self = this; - // listen for presence changes - function updateUserState(event, user) { - if (!self.props.member) { return; } - - if (user.userId === self.props.member.userId) { - self.setState({ - presence: user.presence, - active: user.lastActiveAgo - }); - } - } - MatrixClientPeg.get().on("User.presence", updateUserState); - this.userPresenceFn = updateUserState; - - // listen for power level changes - function updatePowerLevel(event, member) { - if (!self.props.member) { return; } - - if (member.roomId !== self.props.member.roomId) { - return; - } - // only interested in changes to us or them - var myUserId = MatrixClientPeg.get().credentials.userId; - if ([myUserId, self.props.member.userId].indexOf(member.userId) === -1) { - return; - } - self.setState(self._calculateOpsPermissions()); - } - MatrixClientPeg.get().on("RoomMember.powerLevel", updatePowerLevel); - this.updatePowerLevelFn = updatePowerLevel; // work out the current state if (this.props.member) { var usr = MatrixClientPeg.get().getUser(this.props.member.userId) || {}; var memberState = this._calculateOpsPermissions(); - memberState.presence = usr.presence || "offline"; - memberState.active = usr.lastActiveAgo || -1; this.setState(memberState); } }, - componentWillUnmount: function() { - MatrixClientPeg.get().removeListener("User.presence", this.userPresenceFn); - MatrixClientPeg.get().removeListener( - "RoomMember.powerLevel", this.updatePowerLevelFn - ); - }, - onKick: function() { + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); var roomId = this.props.member.roomId; var target = this.props.member.userId; var self = this; @@ -93,15 +54,16 @@ module.exports = { // get out of sync if we force setState here! console.log("Kick success"); }, function(err) { - var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); Modal.createDialog(ErrorDialog, { title: "Kick error", description: err.message }); }); + this.props.onFinished(); }, onBan: function() { + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); var roomId = this.props.member.roomId; var target = this.props.member.userId; var self = this; @@ -110,26 +72,29 @@ module.exports = { // get out of sync if we force setState here! console.log("Ban success"); }, function(err) { - var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); Modal.createDialog(ErrorDialog, { title: "Ban error", description: err.message }); }); + this.props.onFinished(); }, onMuteToggle: function() { + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); var roomId = this.props.member.roomId; var target = this.props.member.userId; var self = this; var room = MatrixClientPeg.get().getRoom(roomId); if (!room) { + this.props.onFinished(); return; } var powerLevelEvent = room.currentState.getStateEvents( "m.room.power_levels", "" ); if (!powerLevelEvent) { + this.props.onFinished(); return; } var isMuted = this.state.muted; @@ -152,29 +117,33 @@ module.exports = { // get out of sync if we force setState here! console.log("Mute toggle success"); }, function(err) { - var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); Modal.createDialog(ErrorDialog, { title: "Mute error", description: err.message }); }); + this.props.onFinished(); }, onModToggle: function() { + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); var roomId = this.props.member.roomId; var target = this.props.member.userId; var room = MatrixClientPeg.get().getRoom(roomId); if (!room) { + this.props.onFinished(); return; } var powerLevelEvent = room.currentState.getStateEvents( "m.room.power_levels", "" ); if (!powerLevelEvent) { + this.props.onFinished(); return; } var me = room.getMember(MatrixClientPeg.get().credentials.userId); if (!me) { + this.props.onFinished(); return; } var defaultLevel = powerLevelEvent.getContent().users_default; @@ -187,12 +156,12 @@ module.exports = { // get out of sync if we force setState here! console.log("Mod toggle success"); }, function(err) { - var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); Modal.createDialog(ErrorDialog, { title: "Mod error", description: err.message }); }); + this.props.onFinished(); }, onChatClick: function() { @@ -242,12 +211,43 @@ module.exports = { ); }); } + this.props.onFinished(); + }, + + // FIXME: this is horribly duplicated with MemberTile's onLeaveClick. + // Not sure what the right solution to this is. + onLeaveClick: function() { + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); + var QuestionDialog = sdk.getComponent("organisms.QuestionDialog"); + + var roomId = this.props.member.roomId; + Modal.createDialog(QuestionDialog, { + title: "Leave room", + description: "Are you sure you want to leave the room?", + onFinished: function(should_leave) { + if (should_leave) { + var d = MatrixClientPeg.get().leave(roomId); + + var modal = Modal.createDialog(Loader); + + d.then(function() { + modal.close(); + dis.dispatch({action: 'view_next_room'}); + }, function(err) { + modal.close(); + Modal.createDialog(ErrorDialog, { + title: "Failed to leave room", + description: err.toString() + }); + }); + } + } + }); + this.props.onFinished(); }, getInitialState: function() { return { - presence: "offline", - active: -1, can: { kick: false, ban: false,