2015-09-18 17:39:16 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-14 13:57:22 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-09-18 17:39:16 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* State vars:
|
|
|
|
* 'can': {
|
|
|
|
* kick: boolean,
|
|
|
|
* ban: boolean,
|
|
|
|
* mute: boolean,
|
|
|
|
* modifyLevel: boolean
|
|
|
|
* },
|
|
|
|
* 'muted': boolean,
|
|
|
|
* 'isTargetMod': boolean
|
|
|
|
*/
|
2017-02-14 13:40:19 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import dis from '../../../dispatcher';
|
|
|
|
import Modal from '../../../Modal';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import createRoom from '../../../createRoom';
|
|
|
|
import DMRoomMap from '../../../utils/DMRoomMap';
|
|
|
|
import Unread from '../../../Unread';
|
2017-02-14 14:33:21 +00:00
|
|
|
import { findReadReceiptFromUserId } from '../../../utils/Receipt';
|
2017-02-14 13:40:19 +00:00
|
|
|
import WithMatrixClient from '../../../wrappers/WithMatrixClient';
|
2017-01-24 22:41:52 +00:00
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2015-09-18 17:39:16 +00:00
|
|
|
|
2016-11-03 18:55:09 +00:00
|
|
|
module.exports = WithMatrixClient(React.createClass({
|
2015-11-26 17:49:39 +00:00
|
|
|
displayName: 'MemberInfo',
|
2015-09-18 17:39:16 +00:00
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
propTypes: {
|
2016-11-03 18:55:09 +00:00
|
|
|
matrixClient: React.PropTypes.object.isRequired,
|
2016-06-08 12:13:41 +00:00
|
|
|
member: React.PropTypes.object.isRequired,
|
2015-11-30 14:14:30 +00:00
|
|
|
},
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
can: {
|
|
|
|
kick: false,
|
|
|
|
ban: false,
|
|
|
|
mute: false,
|
|
|
|
modifyLevel: false
|
|
|
|
},
|
|
|
|
muted: false,
|
|
|
|
isTargetMod: false,
|
|
|
|
updating: 0,
|
2016-06-08 21:54:48 +00:00
|
|
|
devicesLoading: true,
|
|
|
|
devices: null,
|
2017-01-20 14:22:27 +00:00
|
|
|
};
|
2015-09-18 17:39:16 +00:00
|
|
|
},
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
componentWillMount: function() {
|
|
|
|
this._cancelDeviceList = null;
|
2016-07-17 18:41:53 +00:00
|
|
|
|
2016-11-21 10:25:48 +00:00
|
|
|
// only display the devices list if our client supports E2E
|
|
|
|
this._enableDevices = this.props.matrixClient.isCryptoEnabled();
|
2016-09-09 15:59:59 +00:00
|
|
|
|
2016-11-03 18:55:09 +00:00
|
|
|
const cli = this.props.matrixClient;
|
2016-09-09 15:59:59 +00:00
|
|
|
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
|
|
|
cli.on("Room", this.onRoom);
|
|
|
|
cli.on("deleteRoom", this.onDeleteRoom);
|
|
|
|
cli.on("Room.timeline", this.onRoomTimeline);
|
|
|
|
cli.on("Room.name", this.onRoomName);
|
|
|
|
cli.on("Room.receipt", this.onRoomReceipt);
|
|
|
|
cli.on("RoomState.events", this.onRoomStateEvents);
|
|
|
|
cli.on("RoomMember.name", this.onRoomMemberName);
|
|
|
|
cli.on("accountData", this.onAccountData);
|
2016-06-08 12:13:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
this._updateStateForNewMember(this.props.member);
|
|
|
|
},
|
|
|
|
|
2015-12-04 16:15:55 +00:00
|
|
|
componentWillReceiveProps: function(newProps) {
|
2016-06-08 12:13:41 +00:00
|
|
|
if (this.props.member.userId != newProps.member.userId) {
|
|
|
|
this._updateStateForNewMember(newProps.member);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-11-03 18:55:09 +00:00
|
|
|
var client = this.props.matrixClient;
|
2016-06-08 20:25:42 +00:00
|
|
|
if (client) {
|
2016-06-23 16:27:23 +00:00
|
|
|
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
2016-09-09 15:59:59 +00:00
|
|
|
client.removeListener("Room", this.onRoom);
|
|
|
|
client.removeListener("deleteRoom", this.onDeleteRoom);
|
|
|
|
client.removeListener("Room.timeline", this.onRoomTimeline);
|
|
|
|
client.removeListener("Room.name", this.onRoomName);
|
|
|
|
client.removeListener("Room.receipt", this.onRoomReceipt);
|
|
|
|
client.removeListener("RoomState.events", this.onRoomStateEvents);
|
|
|
|
client.removeListener("RoomMember.name", this.onRoomMemberName);
|
|
|
|
client.removeListener("accountData", this.onAccountData);
|
2016-06-08 20:25:42 +00:00
|
|
|
}
|
2016-06-08 12:13:41 +00:00
|
|
|
if (this._cancelDeviceList) {
|
|
|
|
this._cancelDeviceList();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-17 19:12:56 +00:00
|
|
|
_disambiguateDevices: function(devices) {
|
|
|
|
var names = Object.create(null);
|
|
|
|
for (var i = 0; i < devices.length; i++) {
|
|
|
|
var name = devices[i].getDisplayName();
|
|
|
|
var indexList = names[name] || [];
|
|
|
|
indexList.push(i);
|
|
|
|
names[name] = indexList;
|
|
|
|
}
|
|
|
|
for (name in names) {
|
|
|
|
if (names[name].length > 1) {
|
|
|
|
names[name].forEach((j)=>{
|
|
|
|
devices[j].ambiguous = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-23 16:27:23 +00:00
|
|
|
onDeviceVerificationChanged: function(userId, device) {
|
2016-08-17 08:57:06 +00:00
|
|
|
if (!this._enableDevices) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-08 20:25:42 +00:00
|
|
|
if (userId == this.props.member.userId) {
|
|
|
|
// no need to re-download the whole thing; just update our copy of
|
|
|
|
// the list.
|
2016-11-03 18:55:09 +00:00
|
|
|
var devices = this.props.matrixClient.getStoredDevicesForUser(userId);
|
2016-06-08 20:25:42 +00:00
|
|
|
this.setState({devices: devices});
|
2016-06-08 17:35:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-09 15:59:59 +00:00
|
|
|
onRoom: function(room) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteRoom: function(roomId) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomTimeline: function(ev, room, toStartOfTimeline) {
|
|
|
|
if (toStartOfTimeline) return;
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomName: function(room) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomReceipt: function(receiptEvent, room) {
|
|
|
|
// because if we read a notification, it will affect notification count
|
|
|
|
// only bother updating if there's a receipt from us
|
2017-02-14 13:58:29 +00:00
|
|
|
if (findReadReceiptFromUserId(receiptEvent, this.props.matrixClient.credentials.userId)) {
|
2016-09-09 15:59:59 +00:00
|
|
|
this.forceUpdate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomStateEvents: function(ev, state) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomMemberName: function(ev, member) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onAccountData: function(ev) {
|
|
|
|
if (ev.getType() == 'm.direct') {
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
_updateStateForNewMember: function(member) {
|
|
|
|
var newState = this._calculateOpsPermissions(member);
|
2016-06-08 21:54:48 +00:00
|
|
|
newState.devicesLoading = true;
|
2016-06-08 12:13:41 +00:00
|
|
|
newState.devices = null;
|
|
|
|
this.setState(newState);
|
|
|
|
|
|
|
|
if (this._cancelDeviceList) {
|
|
|
|
this._cancelDeviceList();
|
|
|
|
this._cancelDeviceList = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._downloadDeviceList(member);
|
|
|
|
},
|
|
|
|
|
|
|
|
_downloadDeviceList: function(member) {
|
2016-08-17 08:57:06 +00:00
|
|
|
if (!this._enableDevices) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
var cancelled = false;
|
2017-01-20 14:22:27 +00:00
|
|
|
this._cancelDeviceList = function() { cancelled = true; };
|
2016-06-08 12:13:41 +00:00
|
|
|
|
2016-11-03 18:55:09 +00:00
|
|
|
var client = this.props.matrixClient;
|
2016-06-08 12:13:41 +00:00
|
|
|
var self = this;
|
2016-06-08 21:54:48 +00:00
|
|
|
client.downloadKeys([member.userId], true).finally(function() {
|
|
|
|
self._cancelDeviceList = null;
|
|
|
|
}).done(function() {
|
2016-06-08 12:13:41 +00:00
|
|
|
if (cancelled) {
|
|
|
|
// we got cancelled - presumably a different user now
|
|
|
|
return;
|
|
|
|
}
|
2016-09-04 20:49:32 +00:00
|
|
|
var devices = client.getStoredDevicesForUser(member.userId);
|
2016-09-17 19:12:56 +00:00
|
|
|
self._disambiguateDevices(devices);
|
2016-06-08 21:54:48 +00:00
|
|
|
self.setState({devicesLoading: false, devices: devices});
|
|
|
|
}, function(err) {
|
|
|
|
console.log("Error downloading devices", err);
|
|
|
|
self.setState({devicesLoading: false});
|
2016-06-08 12:13:41 +00:00
|
|
|
});
|
2015-12-04 16:15:55 +00:00
|
|
|
},
|
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
onKick: function() {
|
2017-02-14 13:40:19 +00:00
|
|
|
const ConfirmUserActionDialog = sdk.getComponent("dialogs.ConfirmUserActionDialog");
|
|
|
|
Modal.createDialog(ConfirmUserActionDialog, {
|
|
|
|
member: this.props.member,
|
|
|
|
action: 'Kick',
|
|
|
|
danger: true,
|
|
|
|
onFinished: (proceed) => {
|
|
|
|
if (!proceed) return;
|
|
|
|
|
|
|
|
this.setState({ updating: this.state.updating + 1 });
|
|
|
|
this.props.matrixClient.kick(
|
|
|
|
this.props.member.roomId, this.props.member.userId,
|
|
|
|
).then(function() {
|
|
|
|
// NO-OP; rely on the m.room.member event coming down else we could
|
|
|
|
// get out of sync if we force setState here!
|
|
|
|
console.log("Kick success");
|
|
|
|
}, function(err) {
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Kick error",
|
|
|
|
description: err.message
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).finally(()=>{
|
|
|
|
this.setState({ updating: this.state.updating - 1 });
|
2016-01-18 13:38:40 +00:00
|
|
|
});
|
|
|
|
}
|
2016-04-13 00:46:10 +00:00
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onBan: function() {
|
2017-02-14 13:40:19 +00:00
|
|
|
const ConfirmUserActionDialog = sdk.getComponent("dialogs.ConfirmUserActionDialog");
|
|
|
|
Modal.createDialog(ConfirmUserActionDialog, {
|
|
|
|
member: this.props.member,
|
|
|
|
action: 'Ban',
|
|
|
|
danger: true,
|
|
|
|
onFinished: (proceed) => {
|
|
|
|
if (!proceed) return;
|
|
|
|
|
|
|
|
this.setState({ updating: this.state.updating + 1 });
|
|
|
|
this.props.matrixClient.ban(
|
|
|
|
this.props.member.roomId, this.props.member.userId,
|
|
|
|
).then(
|
|
|
|
function() {
|
|
|
|
// NO-OP; rely on the m.room.member event coming down else we could
|
|
|
|
// get out of sync if we force setState here!
|
|
|
|
console.log("Ban success");
|
|
|
|
}, function(err) {
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Ban error",
|
|
|
|
description: err.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).finally(()=>{
|
|
|
|
this.setState({ updating: this.state.updating - 1 });
|
2016-01-18 13:38:40 +00:00
|
|
|
});
|
2017-02-14 13:40:19 +00:00
|
|
|
},
|
2016-04-13 00:46:10 +00:00
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onMuteToggle: function() {
|
2015-11-30 14:11:04 +00:00
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2015-09-18 17:39:16 +00:00
|
|
|
var roomId = this.props.member.roomId;
|
|
|
|
var target = this.props.member.userId;
|
2016-11-03 18:55:09 +00:00
|
|
|
var room = this.props.matrixClient.getRoom(roomId);
|
2015-09-18 17:39:16 +00:00
|
|
|
if (!room) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var powerLevelEvent = room.currentState.getStateEvents(
|
|
|
|
"m.room.power_levels", ""
|
|
|
|
);
|
|
|
|
if (!powerLevelEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var isMuted = this.state.muted;
|
|
|
|
var powerLevels = powerLevelEvent.getContent();
|
|
|
|
var levelToSend = (
|
|
|
|
(powerLevels.events ? powerLevels.events["m.room.message"] : null) ||
|
|
|
|
powerLevels.events_default
|
|
|
|
);
|
|
|
|
var level;
|
|
|
|
if (isMuted) { // unmute
|
|
|
|
level = levelToSend;
|
|
|
|
}
|
|
|
|
else { // mute
|
|
|
|
level = levelToSend - 1;
|
|
|
|
}
|
2016-01-22 15:29:57 +00:00
|
|
|
level = parseInt(level);
|
2015-09-18 17:39:16 +00:00
|
|
|
|
2016-01-22 15:29:57 +00:00
|
|
|
if (level !== NaN) {
|
2016-04-13 00:46:10 +00:00
|
|
|
this.setState({ updating: this.state.updating + 1 });
|
2016-11-03 18:55:09 +00:00
|
|
|
this.props.matrixClient.setPowerLevel(roomId, target, level, powerLevelEvent).then(
|
2016-01-22 15:29:57 +00:00
|
|
|
function() {
|
|
|
|
// NO-OP; rely on the m.room.member event coming down else we could
|
|
|
|
// get out of sync if we force setState here!
|
|
|
|
console.log("Mute toggle success");
|
|
|
|
}, function(err) {
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Mute error",
|
|
|
|
description: err.message
|
|
|
|
});
|
|
|
|
}
|
2016-04-13 00:46:10 +00:00
|
|
|
).finally(()=>{
|
|
|
|
this.setState({ updating: this.state.updating - 1 });
|
|
|
|
});
|
2016-01-22 15:29:57 +00:00
|
|
|
}
|
2015-09-18 17:39:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onModToggle: function() {
|
2015-11-30 14:11:04 +00:00
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2015-09-18 17:39:16 +00:00
|
|
|
var roomId = this.props.member.roomId;
|
|
|
|
var target = this.props.member.userId;
|
2016-11-03 18:55:09 +00:00
|
|
|
var room = this.props.matrixClient.getRoom(roomId);
|
2015-09-18 17:39:16 +00:00
|
|
|
if (!room) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var powerLevelEvent = room.currentState.getStateEvents(
|
|
|
|
"m.room.power_levels", ""
|
|
|
|
);
|
|
|
|
if (!powerLevelEvent) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-03 18:55:09 +00:00
|
|
|
var me = room.getMember(this.props.matrixClient.credentials.userId);
|
2015-09-18 17:39:16 +00:00
|
|
|
if (!me) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var defaultLevel = powerLevelEvent.getContent().users_default;
|
|
|
|
var modLevel = me.powerLevel - 1;
|
2016-01-18 01:18:02 +00:00
|
|
|
if (modLevel > 50 && defaultLevel < 50) modLevel = 50; // try to stick with the vector level defaults
|
2015-09-18 17:39:16 +00:00
|
|
|
// toggle the level
|
|
|
|
var newLevel = this.state.isTargetMod ? defaultLevel : modLevel;
|
2016-04-13 00:46:10 +00:00
|
|
|
this.setState({ updating: this.state.updating + 1 });
|
2016-11-03 18:55:09 +00:00
|
|
|
this.props.matrixClient.setPowerLevel(roomId, target, parseInt(newLevel), powerLevelEvent).then(
|
2016-01-18 13:38:40 +00:00
|
|
|
function() {
|
|
|
|
// NO-OP; rely on the m.room.member event coming down else we could
|
|
|
|
// get out of sync if we force setState here!
|
|
|
|
console.log("Mod toggle success");
|
|
|
|
}, function(err) {
|
2016-03-22 13:19:29 +00:00
|
|
|
if (err.errcode == 'M_GUEST_ACCESS_FORBIDDEN') {
|
|
|
|
var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog");
|
|
|
|
Modal.createDialog(NeedToRegisterDialog, {
|
|
|
|
title: "Please Register",
|
|
|
|
description: "This action cannot be performed by a guest user. Please register to be able to do this."
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
2016-03-23 18:17:49 +00:00
|
|
|
title: "Moderator toggle error",
|
2016-03-22 13:19:29 +00:00
|
|
|
description: err.message
|
|
|
|
});
|
|
|
|
}
|
2016-01-18 13:38:40 +00:00
|
|
|
}
|
2016-04-13 00:46:10 +00:00
|
|
|
).finally(()=>{
|
|
|
|
this.setState({ updating: this.state.updating - 1 });
|
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
},
|
|
|
|
|
2016-03-21 00:49:18 +00:00
|
|
|
_applyPowerChange: function(roomId, target, powerLevel, powerLevelEvent) {
|
2016-04-13 00:46:10 +00:00
|
|
|
this.setState({ updating: this.state.updating + 1 });
|
2016-11-03 18:55:09 +00:00
|
|
|
this.props.matrixClient.setPowerLevel(roomId, target, parseInt(powerLevel), powerLevelEvent).then(
|
2016-03-21 00:49:18 +00:00
|
|
|
function() {
|
|
|
|
// NO-OP; rely on the m.room.member event coming down else we could
|
|
|
|
// get out of sync if we force setState here!
|
|
|
|
console.log("Power change success");
|
|
|
|
}, function(err) {
|
2017-01-13 15:17:34 +00:00
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2016-03-21 00:49:18 +00:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Failure to change power level",
|
|
|
|
description: err.message
|
|
|
|
});
|
|
|
|
}
|
2016-04-13 00:46:10 +00:00
|
|
|
).finally(()=>{
|
|
|
|
this.setState({ updating: this.state.updating - 1 });
|
2017-01-13 15:17:34 +00:00
|
|
|
}).done();
|
2016-03-21 00:49:18 +00:00
|
|
|
},
|
|
|
|
|
2016-01-18 01:18:02 +00:00
|
|
|
onPowerChange: function(powerLevel) {
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
var roomId = this.props.member.roomId;
|
|
|
|
var target = this.props.member.userId;
|
2016-11-03 18:55:09 +00:00
|
|
|
var room = this.props.matrixClient.getRoom(roomId);
|
2016-03-21 00:49:18 +00:00
|
|
|
var self = this;
|
2016-01-18 01:18:02 +00:00
|
|
|
if (!room) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var powerLevelEvent = room.currentState.getStateEvents(
|
|
|
|
"m.room.power_levels", ""
|
|
|
|
);
|
|
|
|
if (!powerLevelEvent) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-21 00:49:18 +00:00
|
|
|
if (powerLevelEvent.getContent().users) {
|
2016-11-03 18:55:09 +00:00
|
|
|
var myPower = powerLevelEvent.getContent().users[this.props.matrixClient.credentials.userId];
|
2016-03-21 00:49:18 +00:00
|
|
|
if (parseInt(myPower) === parseInt(powerLevel)) {
|
|
|
|
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
Modal.createDialog(QuestionDialog, {
|
|
|
|
title: "Warning",
|
|
|
|
description:
|
|
|
|
<div>
|
|
|
|
You will not be able to undo this change as you are promoting the user to have the same power level as yourself.<br/>
|
|
|
|
Are you sure?
|
|
|
|
</div>,
|
|
|
|
button: "Continue",
|
|
|
|
onFinished: function(confirmed) {
|
|
|
|
if (confirmed) {
|
|
|
|
self._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
|
|
|
}
|
|
|
|
},
|
2016-01-18 13:38:40 +00:00
|
|
|
});
|
|
|
|
}
|
2016-03-21 00:49:18 +00:00
|
|
|
else {
|
|
|
|
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
|
|
|
}
|
2016-04-13 00:46:10 +00:00
|
|
|
},
|
2016-01-18 01:18:02 +00:00
|
|
|
|
2016-09-09 15:15:01 +00:00
|
|
|
onNewDMClick: function() {
|
|
|
|
this.setState({ updating: this.state.updating + 1 });
|
2016-09-09 18:25:00 +00:00
|
|
|
createRoom({dmUserId: this.props.member.userId}).finally(() => {
|
2016-09-09 15:15:01 +00:00
|
|
|
this.setState({ updating: this.state.updating - 1 });
|
|
|
|
}).done();
|
2015-09-22 15:37:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLeaveClick: function() {
|
2015-12-13 13:49:28 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'leave_room',
|
|
|
|
room_id: this.props.member.roomId,
|
2015-09-22 15:37:39 +00:00
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
},
|
|
|
|
|
2015-12-04 16:15:55 +00:00
|
|
|
_calculateOpsPermissions: function(member) {
|
2015-09-18 17:39:16 +00:00
|
|
|
var defaultPerms = {
|
|
|
|
can: {},
|
|
|
|
muted: false,
|
|
|
|
modifyLevel: false
|
|
|
|
};
|
2016-11-03 18:55:09 +00:00
|
|
|
var room = this.props.matrixClient.getRoom(member.roomId);
|
2015-09-18 17:39:16 +00:00
|
|
|
if (!room) {
|
|
|
|
return defaultPerms;
|
|
|
|
}
|
|
|
|
var powerLevels = room.currentState.getStateEvents(
|
|
|
|
"m.room.power_levels", ""
|
|
|
|
);
|
|
|
|
if (!powerLevels) {
|
|
|
|
return defaultPerms;
|
|
|
|
}
|
2016-11-03 18:55:09 +00:00
|
|
|
var me = room.getMember(this.props.matrixClient.credentials.userId);
|
2016-03-23 11:41:10 +00:00
|
|
|
if (!me) {
|
|
|
|
return defaultPerms;
|
|
|
|
}
|
2015-12-04 16:15:55 +00:00
|
|
|
var them = member;
|
2015-09-18 17:39:16 +00:00
|
|
|
return {
|
|
|
|
can: this._calculateCanPermissions(
|
|
|
|
me, them, powerLevels.getContent()
|
|
|
|
),
|
|
|
|
muted: this._isMuted(them, powerLevels.getContent()),
|
|
|
|
isTargetMod: them.powerLevel > powerLevels.getContent().users_default
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_calculateCanPermissions: function(me, them, powerLevels) {
|
|
|
|
var can = {
|
|
|
|
kick: false,
|
|
|
|
ban: false,
|
|
|
|
mute: false,
|
|
|
|
modifyLevel: false
|
|
|
|
};
|
|
|
|
var canAffectUser = them.powerLevel < me.powerLevel;
|
|
|
|
if (!canAffectUser) {
|
|
|
|
//console.log("Cannot affect user: %s >= %s", them.powerLevel, me.powerLevel);
|
|
|
|
return can;
|
|
|
|
}
|
|
|
|
var editPowerLevel = (
|
|
|
|
(powerLevels.events ? powerLevels.events["m.room.power_levels"] : null) ||
|
|
|
|
powerLevels.state_default
|
|
|
|
);
|
2016-01-18 01:40:19 +00:00
|
|
|
var levelToSend = (
|
|
|
|
(powerLevels.events ? powerLevels.events["m.room.message"] : null) ||
|
|
|
|
powerLevels.events_default
|
|
|
|
);
|
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
can.kick = me.powerLevel >= powerLevels.kick;
|
|
|
|
can.ban = me.powerLevel >= powerLevels.ban;
|
|
|
|
can.mute = me.powerLevel >= editPowerLevel;
|
2016-01-18 01:40:19 +00:00
|
|
|
can.toggleMod = me.powerLevel > them.powerLevel && them.powerLevel >= levelToSend;
|
2015-09-18 17:39:16 +00:00
|
|
|
can.modifyLevel = me.powerLevel > them.powerLevel;
|
|
|
|
return can;
|
|
|
|
},
|
|
|
|
|
|
|
|
_isMuted: function(member, powerLevelContent) {
|
|
|
|
if (!powerLevelContent || !member) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var levelToSend = (
|
|
|
|
(powerLevelContent.events ? powerLevelContent.events["m.room.message"] : null) ||
|
|
|
|
powerLevelContent.events_default
|
|
|
|
);
|
|
|
|
return member.powerLevel < levelToSend;
|
2015-11-26 17:49:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onCancel: function(e) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: "view_user",
|
|
|
|
member: null
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-01-20 14:22:27 +00:00
|
|
|
onMemberAvatarClick: function() {
|
2016-08-25 15:20:31 +00:00
|
|
|
var avatarUrl = this.props.member.user ? this.props.member.user.avatarUrl : this.props.member.events.member.getContent().avatar_url;
|
2016-04-02 19:24:23 +00:00
|
|
|
if(!avatarUrl) return;
|
2016-04-03 23:18:18 +00:00
|
|
|
|
2016-11-03 18:55:09 +00:00
|
|
|
var httpUrl = this.props.matrixClient.mxcUrlToHttp(avatarUrl);
|
2016-04-02 19:24:23 +00:00
|
|
|
var ImageView = sdk.getComponent("elements.ImageView");
|
|
|
|
var params = {
|
|
|
|
src: httpUrl,
|
|
|
|
name: this.props.member.name
|
|
|
|
};
|
|
|
|
|
|
|
|
Modal.createDialog(ImageView, params, "mx_Dialog_lightbox");
|
|
|
|
},
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
_renderDevices: function() {
|
2016-08-17 08:57:06 +00:00
|
|
|
if (!this._enableDevices) {
|
2016-06-14 10:57:08 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
var devices = this.state.devices;
|
|
|
|
var MemberDeviceInfo = sdk.getComponent('rooms.MemberDeviceInfo');
|
|
|
|
var Spinner = sdk.getComponent("elements.Spinner");
|
|
|
|
|
|
|
|
var devComponents;
|
2016-06-08 21:54:48 +00:00
|
|
|
if (this.state.devicesLoading) {
|
2016-06-08 12:13:41 +00:00
|
|
|
// still loading
|
|
|
|
devComponents = <Spinner />;
|
2016-06-08 21:54:48 +00:00
|
|
|
} else if (devices === null) {
|
|
|
|
devComponents = "Unable to load device list";
|
|
|
|
} else if (devices.length === 0) {
|
|
|
|
devComponents = "No registered devices";
|
2016-06-08 12:13:41 +00:00
|
|
|
} else {
|
|
|
|
devComponents = [];
|
|
|
|
for (var i = 0; i < devices.length; i++) {
|
|
|
|
devComponents.push(<MemberDeviceInfo key={i}
|
|
|
|
userId={this.props.member.userId}
|
|
|
|
device={devices[i]}/>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h3>Devices</h3>
|
2016-06-23 16:27:23 +00:00
|
|
|
<div className="mx_MemberInfo_devices">
|
|
|
|
{devComponents}
|
|
|
|
</div>
|
2016-06-08 12:13:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-11-26 17:49:39 +00:00
|
|
|
render: function() {
|
2016-01-18 01:18:02 +00:00
|
|
|
var startChat, kickButton, banButton, muteButton, giveModButton, spinner;
|
2016-11-03 18:55:09 +00:00
|
|
|
if (this.props.member.userId !== this.props.matrixClient.credentials.userId) {
|
|
|
|
const dmRoomMap = new DMRoomMap(this.props.matrixClient);
|
2016-09-09 15:15:01 +00:00
|
|
|
const dmRooms = dmRoomMap.getDMRoomsForUserId(this.props.member.userId);
|
|
|
|
|
|
|
|
const RoomTile = sdk.getComponent("rooms.RoomTile");
|
|
|
|
|
|
|
|
const tiles = [];
|
|
|
|
for (const roomId of dmRooms) {
|
2016-11-03 18:55:09 +00:00
|
|
|
const room = this.props.matrixClient.getRoom(roomId);
|
2016-09-09 15:15:01 +00:00
|
|
|
if (room) {
|
2016-11-03 18:55:09 +00:00
|
|
|
const me = room.getMember(this.props.matrixClient.credentials.userId);
|
2016-09-09 15:15:01 +00:00
|
|
|
const highlight = (
|
|
|
|
room.getUnreadNotificationCount('highlight') > 0 ||
|
|
|
|
me.membership == "invite"
|
|
|
|
);
|
|
|
|
tiles.push(
|
|
|
|
<RoomTile key={room.roomId} room={room}
|
|
|
|
collapsed={false}
|
|
|
|
selected={false}
|
|
|
|
unread={Unread.doesRoomHaveUnreadMessages(room)}
|
|
|
|
highlight={highlight}
|
|
|
|
isInvite={me.membership == "invite"}
|
|
|
|
/>
|
|
|
|
);
|
2016-07-17 18:41:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:15:01 +00:00
|
|
|
const labelClasses = classNames({
|
|
|
|
mx_MemberInfo_createRoom_label: true,
|
|
|
|
mx_RoomTile_name: true,
|
|
|
|
});
|
2017-01-13 16:25:26 +00:00
|
|
|
const startNewChat = <AccessibleButton
|
2016-09-09 15:15:01 +00:00
|
|
|
className="mx_MemberInfo_createRoom"
|
|
|
|
onClick={this.onNewDMClick}
|
|
|
|
>
|
|
|
|
<div className="mx_RoomTile_avatar">
|
|
|
|
<img src="img/create-big.svg" width="26" height="26" />
|
|
|
|
</div>
|
2016-09-20 14:06:48 +00:00
|
|
|
<div className={labelClasses}><i>Start new chat</i></div>
|
2017-01-24 20:47:24 +00:00
|
|
|
</AccessibleButton>;
|
2016-09-09 15:15:01 +00:00
|
|
|
|
|
|
|
startChat = <div>
|
2016-09-16 13:35:43 +00:00
|
|
|
<h3>Direct chats</h3>
|
2016-09-09 15:15:01 +00:00
|
|
|
{tiles}
|
|
|
|
{startNewChat}
|
|
|
|
</div>;
|
2015-11-26 17:49:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 00:46:10 +00:00
|
|
|
if (this.state.updating) {
|
2015-11-26 17:49:39 +00:00
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
spinner = <Loader imgClassName="mx_ContextualMenu_spinner"/>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.can.kick) {
|
2017-01-24 22:41:52 +00:00
|
|
|
const membership = this.props.member.membership;
|
|
|
|
const kickLabel = membership === "invite" ? "Disinvite" : "Kick";
|
|
|
|
kickButton = (
|
|
|
|
<AccessibleButton className="mx_MemberInfo_field"
|
|
|
|
onClick={this.onKick}>
|
|
|
|
{kickLabel}
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2015-11-26 17:49:39 +00:00
|
|
|
}
|
|
|
|
if (this.state.can.ban) {
|
2017-01-24 22:41:52 +00:00
|
|
|
banButton = (
|
|
|
|
<AccessibleButton className="mx_MemberInfo_field"
|
|
|
|
onClick={this.onBan}>
|
|
|
|
Ban
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2015-11-26 17:49:39 +00:00
|
|
|
}
|
|
|
|
if (this.state.can.mute) {
|
2017-01-24 22:41:52 +00:00
|
|
|
const muteLabel = this.state.muted ? "Unmute" : "Mute";
|
|
|
|
muteButton = (
|
|
|
|
<AccessibleButton className="mx_MemberInfo_field"
|
|
|
|
onClick={this.onMuteToggle}>
|
|
|
|
{muteLabel}
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2015-11-26 17:49:39 +00:00
|
|
|
}
|
2016-01-18 01:40:19 +00:00
|
|
|
if (this.state.can.toggleMod) {
|
2016-01-18 01:18:02 +00:00
|
|
|
var giveOpLabel = this.state.isTargetMod ? "Revoke Moderator" : "Make Moderator";
|
2017-01-13 16:25:26 +00:00
|
|
|
giveModButton = <AccessibleButton className="mx_MemberInfo_field" onClick={this.onModToggle}>
|
2015-11-26 17:49:39 +00:00
|
|
|
{giveOpLabel}
|
2017-01-24 20:47:24 +00:00
|
|
|
</AccessibleButton>;
|
2015-11-26 17:49:39 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 01:26:15 +00:00
|
|
|
// TODO: we should have an invite button if this MemberInfo is showing a user who isn't actually in the current room yet
|
|
|
|
// e.g. clicking on a linkified userid in a room
|
|
|
|
|
2016-01-18 01:18:02 +00:00
|
|
|
var adminTools;
|
|
|
|
if (kickButton || banButton || muteButton || giveModButton) {
|
2016-04-13 00:46:10 +00:00
|
|
|
adminTools =
|
2016-01-18 01:18:02 +00:00
|
|
|
<div>
|
|
|
|
<h3>Admin tools</h3>
|
|
|
|
|
|
|
|
<div className="mx_MemberInfo_buttons">
|
|
|
|
{muteButton}
|
|
|
|
{kickButton}
|
|
|
|
{banButton}
|
|
|
|
{giveModButton}
|
|
|
|
</div>
|
2017-01-20 14:22:27 +00:00
|
|
|
</div>;
|
2016-01-18 01:18:02 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 19:01:51 +00:00
|
|
|
const memberName = this.props.member.name;
|
2016-07-05 04:54:18 +00:00
|
|
|
|
2015-11-26 17:49:39 +00:00
|
|
|
var MemberAvatar = sdk.getComponent('avatars.MemberAvatar');
|
2016-01-18 01:18:02 +00:00
|
|
|
var PowerSelector = sdk.getComponent('elements.PowerSelector');
|
2016-08-11 02:25:12 +00:00
|
|
|
const EmojiText = sdk.getComponent('elements.EmojiText');
|
2015-11-26 17:49:39 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_MemberInfo">
|
2017-01-13 16:25:26 +00:00
|
|
|
<AccessibleButton className="mx_MemberInfo_cancel" onClick={this.onCancel}> <img src="img/cancel.svg" width="18" height="18"/></AccessibleButton>
|
2015-11-26 17:49:39 +00:00
|
|
|
<div className="mx_MemberInfo_avatar">
|
2016-04-02 19:24:23 +00:00
|
|
|
<MemberAvatar onClick={this.onMemberAvatarClick} member={this.props.member} width={48} height={48} />
|
2015-11-26 17:49:39 +00:00
|
|
|
</div>
|
2016-01-18 01:18:02 +00:00
|
|
|
|
2016-08-11 10:34:14 +00:00
|
|
|
<EmojiText element="h2">{memberName}</EmojiText>
|
2016-01-18 01:18:02 +00:00
|
|
|
|
|
|
|
<div className="mx_MemberInfo_profile">
|
|
|
|
<div className="mx_MemberInfo_profileField">
|
|
|
|
{ this.props.member.userId }
|
|
|
|
</div>
|
|
|
|
<div className="mx_MemberInfo_profileField">
|
2016-03-22 17:17:40 +00:00
|
|
|
Level: <b><PowerSelector controlled={true} value={ parseInt(this.props.member.powerLevel) } disabled={ !this.state.can.modifyLevel } onChange={ this.onPowerChange }/></b>
|
2016-01-18 01:18:02 +00:00
|
|
|
</div>
|
2015-11-26 17:49:39 +00:00
|
|
|
</div>
|
2016-01-18 01:18:02 +00:00
|
|
|
|
2016-09-17 14:07:41 +00:00
|
|
|
{ adminTools }
|
|
|
|
|
2016-01-18 01:18:02 +00:00
|
|
|
{ startChat }
|
|
|
|
|
2016-06-08 12:13:41 +00:00
|
|
|
{ this._renderDevices() }
|
|
|
|
|
2016-01-18 01:18:02 +00:00
|
|
|
{ spinner }
|
2015-11-26 17:49:39 +00:00
|
|
|
</div>
|
|
|
|
);
|
2015-09-18 17:39:16 +00:00
|
|
|
}
|
2016-11-03 18:55:09 +00:00
|
|
|
}));
|