From b3463146baf0d1468e53b10b5ae6ce90b66cbb77 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Wed, 25 Oct 2017 00:58:16 +0100
Subject: [PATCH] Add invite button to MemberInfo if user has left or wasn't in
room
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/components/views/rooms/MemberInfo.js | 68 +++++++++++++++++++-----
src/i18n/strings/en_EN.json | 1 +
2 files changed, 55 insertions(+), 14 deletions(-)
diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js
index 2f8bd30a72..7d64b22cb0 100644
--- a/src/components/views/rooms/MemberInfo.js
+++ b/src/components/views/rooms/MemberInfo.js
@@ -39,6 +39,7 @@ import { findReadReceiptFromUserId } from '../../../utils/Receipt';
import withMatrixClient from '../../../wrappers/withMatrixClient';
import AccessibleButton from '../elements/AccessibleButton';
import GeminiScrollbar from 'react-gemini-scrollbar';
+import RoomViewStore from '../../../stores/RoomViewStore';
module.exports = withMatrixClient(React.createClass({
@@ -81,6 +82,7 @@ module.exports = withMatrixClient(React.createClass({
cli.on("Room.receipt", this.onRoomReceipt);
cli.on("RoomState.events", this.onRoomStateEvents);
cli.on("RoomMember.name", this.onRoomMemberName);
+ cli.on("RoomMember.membership", this.onRoomMemberMembership);
cli.on("accountData", this.onAccountData);
this._checkIgnoreState();
@@ -107,6 +109,7 @@ module.exports = withMatrixClient(React.createClass({
client.removeListener("Room.receipt", this.onRoomReceipt);
client.removeListener("RoomState.events", this.onRoomStateEvents);
client.removeListener("RoomMember.name", this.onRoomMemberName);
+ client.removeListener("RoomMember.membership", this.onRoomMemberMembership);
client.removeListener("accountData", this.onAccountData);
}
if (this._cancelDeviceList) {
@@ -186,6 +189,10 @@ module.exports = withMatrixClient(React.createClass({
this.forceUpdate();
},
+ onRoomMemberMembership: function(ev, member) {
+ if (this.props.member.userId === member.userId) this.forceUpdate();
+ },
+
onAccountData: function(ev) {
if (ev.getType() == 'm.direct') {
this.forceUpdate();
@@ -629,6 +636,7 @@ module.exports = withMatrixClient(React.createClass({
const member = this.props.member;
let ignoreButton = null;
+ let inviteUserButton = null;
let readReceiptButton = null;
// Only allow the user to ignore the user if its not ourselves
@@ -659,9 +667,30 @@ module.exports = withMatrixClient(React.createClass({
);
}
+
+ if (!member || !member.membership || member.membership === 'leave') {
+ const roomId = member && member.roomId ? member.roomId : RoomViewStore.getRoomId();
+ const onInviteUserButton = async () => {
+ try {
+ await cli.invite(roomId, member.userId);
+ } catch (err) {
+ const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');
+ Modal.createTrackedDialog('Failed to invite', '', ErrorDialog, {
+ title: _t('Failed to invite'),
+ description: ((err && err.message) ? err.message : "Operation failed"),
+ });
+ }
+ };
+
+ inviteUserButton = (
+