2015-06-23 15:41:25 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-06-23 15:41:25 +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.
|
|
|
|
*/
|
2015-11-30 15:13:28 +00:00
|
|
|
var React = require('react');
|
|
|
|
var classNames = require('classnames');
|
2016-01-13 16:55:28 +00:00
|
|
|
var Matrix = require("matrix-js-sdk");
|
2016-01-15 15:18:55 +00:00
|
|
|
var q = require('q');
|
2015-11-30 15:13:28 +00:00
|
|
|
var MatrixClientPeg = require("../../../MatrixClientPeg");
|
|
|
|
var Modal = require("../../../Modal");
|
2016-01-15 09:58:48 +00:00
|
|
|
var Entities = require("../../../Entities");
|
2015-11-30 15:13:28 +00:00
|
|
|
var sdk = require('../../../index');
|
|
|
|
var GeminiScrollbar = require('react-gemini-scrollbar');
|
2016-02-04 18:06:24 +00:00
|
|
|
var rate_limited_func = require('../../../ratelimitedfunc');
|
2016-04-12 00:54:51 +00:00
|
|
|
var CallHandler = require("../../../CallHandler");
|
2015-06-22 10:42:09 +00:00
|
|
|
|
2016-01-24 18:24:26 +00:00
|
|
|
var INITIAL_LOAD_NUM_MEMBERS = 30;
|
2016-03-03 15:02:11 +00:00
|
|
|
var SHARE_HISTORY_WARNING =
|
|
|
|
<span>
|
|
|
|
Newly invited users will see the history of this room. <br/>
|
|
|
|
If you'd prefer invited users not to see messages that were sent before they joined, <br/>
|
|
|
|
turn off, 'Share message history with new users' in the settings for this room.
|
|
|
|
</span>
|
2016-01-15 15:18:55 +00:00
|
|
|
|
|
|
|
var shown_invite_warning_this_session = false;
|
2016-01-28 11:56:20 +00:00
|
|
|
// global promise so people can bulk invite and they all get resolved
|
|
|
|
var invite_defer = q.defer();
|
2015-06-25 13:57:35 +00:00
|
|
|
|
2015-11-30 15:13:28 +00:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MemberList',
|
2016-02-14 22:37:59 +00:00
|
|
|
|
2015-06-25 13:57:35 +00:00
|
|
|
getInitialState: function() {
|
2016-02-14 22:37:59 +00:00
|
|
|
var state = {
|
|
|
|
members: [],
|
|
|
|
// ideally we'd size this to the page height, but
|
|
|
|
// in practice I find that a little constraining
|
|
|
|
truncateAt: INITIAL_LOAD_NUM_MEMBERS,
|
|
|
|
};
|
|
|
|
if (!this.props.roomId) return state;
|
2015-10-09 16:24:48 +00:00
|
|
|
var cli = MatrixClientPeg.get();
|
|
|
|
var room = cli.getRoom(this.props.roomId);
|
2016-02-14 22:37:59 +00:00
|
|
|
if (!room) return state;
|
2015-10-09 16:24:48 +00:00
|
|
|
|
|
|
|
this.memberDict = this.getMemberDict();
|
|
|
|
|
2016-07-14 17:37:57 +00:00
|
|
|
state.members = this.roomMembers();
|
2016-02-14 22:37:59 +00:00
|
|
|
return state;
|
2015-06-25 13:57:35 +00:00
|
|
|
},
|
|
|
|
|
2015-06-22 10:42:09 +00:00
|
|
|
componentWillMount: function() {
|
|
|
|
var cli = MatrixClientPeg.get();
|
|
|
|
cli.on("RoomState.members", this.onRoomStateMember);
|
2015-10-28 15:15:35 +00:00
|
|
|
cli.on("RoomMember.name", this.onRoomMemberName);
|
2016-01-22 15:11:36 +00:00
|
|
|
cli.on("RoomState.events", this.onRoomStateEvent);
|
2015-09-18 17:39:16 +00:00
|
|
|
cli.on("Room", this.onRoom); // invites
|
2016-07-14 09:05:40 +00:00
|
|
|
// We listen for changes to the lastPresenceTs which is essentially
|
|
|
|
// listening for all presence events (we display most of not all of
|
|
|
|
// the information contained in presence events).
|
|
|
|
cli.on("User.lastPresenceTs", this.onUserLastPresenceTs);
|
2016-04-18 00:35:40 +00:00
|
|
|
// cli.on("Room.timeline", this.onRoomTimeline);
|
2015-06-22 10:42:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-04-18 00:35:40 +00:00
|
|
|
var cli = MatrixClientPeg.get();
|
|
|
|
if (cli) {
|
|
|
|
cli.removeListener("RoomState.members", this.onRoomStateMember);
|
|
|
|
cli.removeListener("RoomMember.name", this.onRoomMemberName);
|
|
|
|
cli.removeListener("RoomState.events", this.onRoomStateEvent);
|
|
|
|
cli.removeListener("Room", this.onRoom);
|
2016-07-14 09:05:40 +00:00
|
|
|
cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs);
|
2016-04-18 00:35:40 +00:00
|
|
|
// cli.removeListener("Room.timeline", this.onRoomTimeline);
|
2015-06-22 10:42:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-18 00:35:40 +00:00
|
|
|
/*
|
|
|
|
onRoomTimeline: function(ev, room, toStartOfTimeline, removed, data) {
|
|
|
|
// ignore anything but real-time updates at the end of the room:
|
|
|
|
// updates from pagination will happen when the paginate completes.
|
|
|
|
if (toStartOfTimeline || !data || !data.liveEvent) return;
|
|
|
|
|
|
|
|
// treat any activity from a user as implicit presence to update the
|
|
|
|
// ordering of the list whenever someone says something.
|
|
|
|
// Except right now we're not tiebreaking "active now" users in this way
|
|
|
|
// so don't bother for now.
|
|
|
|
if (ev.getSender()) {
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log("implicit presence from " + ev.getSender());
|
2016-04-18 00:35:40 +00:00
|
|
|
|
|
|
|
var tile = this.refs[ev.getSender()];
|
|
|
|
if (tile) {
|
|
|
|
// work around a race where you might have a room member object
|
|
|
|
// before the user object exists. XXX: why does this ever happen?
|
|
|
|
var all_members = room.currentState.members;
|
|
|
|
var userId = ev.getSender();
|
|
|
|
if (all_members[userId].user === null) {
|
|
|
|
all_members[userId].user = MatrixClientPeg.get().getUser(userId);
|
|
|
|
}
|
|
|
|
this._updateList(); // reorder the membership list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
*/
|
2015-06-25 13:57:35 +00:00
|
|
|
|
2016-07-14 09:05:40 +00:00
|
|
|
onUserLastPresenceTs(event, user) {
|
2015-09-18 17:39:16 +00:00
|
|
|
// Attach a SINGLE listener for global presence changes then locate the
|
|
|
|
// member tile and re-render it. This is more efficient than every tile
|
|
|
|
// evar attaching their own listener.
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log("explicit presence from " + user.userId);
|
2016-04-18 00:35:40 +00:00
|
|
|
var tile = this.refs[user.userId];
|
|
|
|
if (tile) {
|
|
|
|
this._updateList(); // reorder the membership list
|
2015-09-18 17:39:16 +00:00
|
|
|
}
|
|
|
|
},
|
2016-01-20 14:41:48 +00:00
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
onRoom: function(room) {
|
|
|
|
if (room.roomId !== this.props.roomId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We listen for room events because when we accept an invite
|
|
|
|
// we need to wait till the room is fully populated with state
|
|
|
|
// before refreshing the member list else we get a stale list.
|
|
|
|
this._updateList();
|
|
|
|
},
|
|
|
|
|
2015-06-22 10:42:09 +00:00
|
|
|
onRoomStateMember: function(ev, state, member) {
|
2015-09-18 17:39:16 +00:00
|
|
|
this._updateList();
|
|
|
|
},
|
|
|
|
|
2015-10-28 15:15:35 +00:00
|
|
|
onRoomMemberName: function(ev, member) {
|
|
|
|
this._updateList();
|
|
|
|
},
|
|
|
|
|
2016-01-22 15:11:36 +00:00
|
|
|
onRoomStateEvent: function(event, state) {
|
|
|
|
if (event.getType() === "m.room.third_party_invite") {
|
|
|
|
this._updateList();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-02-04 18:06:24 +00:00
|
|
|
_updateList: new rate_limited_func(function() {
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log("Updating memberlist");
|
2015-10-09 16:24:48 +00:00
|
|
|
this.memberDict = this.getMemberDict();
|
|
|
|
|
|
|
|
var self = this;
|
2015-06-22 10:42:09 +00:00
|
|
|
this.setState({
|
2015-10-09 16:24:48 +00:00
|
|
|
members: self.roomMembers()
|
2015-06-22 10:42:09 +00:00
|
|
|
});
|
2016-02-04 18:06:24 +00:00
|
|
|
}, 500),
|
2015-06-24 12:48:39 +00:00
|
|
|
|
2016-06-01 22:42:34 +00:00
|
|
|
onThirdPartyInvite: function(inputText) {
|
|
|
|
var TextInputDialog = sdk.getComponent("dialogs.TextInputDialog");
|
|
|
|
Modal.createDialog(TextInputDialog, {
|
|
|
|
title: "Invite members by email",
|
2016-06-02 20:07:47 +00:00
|
|
|
description: "Please enter one or more email addresses",
|
2016-06-01 22:42:34 +00:00
|
|
|
value: inputText,
|
|
|
|
button: "Invite",
|
|
|
|
onFinished: (should_invite, addresses)=>{
|
|
|
|
if (should_invite) {
|
2016-06-02 20:07:47 +00:00
|
|
|
// defer the actual invite to the next event loop to give this
|
|
|
|
// Modal a chance to unmount in case onInvite() triggers a new one
|
|
|
|
setTimeout(()=>{
|
|
|
|
this.onInvite(addresses);
|
|
|
|
}, 0);
|
2016-06-01 22:42:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
onInvite: function(inputText) {
|
2015-11-30 14:11:04 +00:00
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2016-03-22 10:57:05 +00:00
|
|
|
var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog");
|
2015-09-18 17:39:16 +00:00
|
|
|
var self = this;
|
|
|
|
inputText = inputText.trim(); // react requires es5-shim so we know trim() exists
|
2016-01-28 11:56:20 +00:00
|
|
|
|
2016-03-22 10:57:05 +00:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
Modal.createDialog(NeedToRegisterDialog, {
|
|
|
|
title: "Unable to Invite",
|
|
|
|
description: "Guest user can't invite new users. Please register to be able to invite new users into a room."
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-28 11:56:20 +00:00
|
|
|
// email addresses and user IDs do not allow space, comma, semicolon so split
|
|
|
|
// on them for bulk inviting.
|
|
|
|
var separators =[ ";", " ", "," ];
|
|
|
|
for (var i = 0; i < separators.length; i++) {
|
|
|
|
if (inputText.indexOf(separators[i]) >= 0) {
|
|
|
|
var inputs = inputText.split(separators[i]);
|
|
|
|
inputs.forEach(function(input) {
|
|
|
|
self.onInvite(input);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 17:36:14 +00:00
|
|
|
var isEmailAddress = /^\S+@\S+\.\S+$/.test(inputText);
|
|
|
|
|
|
|
|
// sanity check the input for user IDs
|
|
|
|
if (!isEmailAddress && (inputText[0] !== '@' || inputText.indexOf(":") === -1)) {
|
2016-01-24 19:02:18 +00:00
|
|
|
console.error("Bad ID to invite: %s", inputText);
|
2015-09-18 17:39:16 +00:00
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Invite Error",
|
2016-01-24 19:02:18 +00:00
|
|
|
description: "Malformed ID. Should be an email address or a Matrix ID like '@localpart:domain'"
|
2015-09-18 17:39:16 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 17:36:14 +00:00
|
|
|
|
2016-01-28 11:56:20 +00:00
|
|
|
var inviteWarningDefer = q.defer();
|
2016-01-15 15:18:55 +00:00
|
|
|
|
|
|
|
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
var history_visibility = room.currentState.getStateEvents('m.room.history_visibility', '');
|
|
|
|
if (history_visibility) history_visibility = history_visibility.getContent().history_visibility;
|
|
|
|
|
|
|
|
if (history_visibility == 'shared' && !shown_invite_warning_this_session) {
|
2016-01-28 11:56:20 +00:00
|
|
|
inviteWarningDefer = invite_defer; // whether we continue depends on this defer
|
2016-01-15 15:18:55 +00:00
|
|
|
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
Modal.createDialog(QuestionDialog, {
|
|
|
|
title: "Warning",
|
|
|
|
description: SHARE_HISTORY_WARNING,
|
|
|
|
button: "Invite",
|
|
|
|
onFinished: function(should_invite) {
|
|
|
|
if (should_invite) {
|
|
|
|
shown_invite_warning_this_session = true;
|
|
|
|
invite_defer.resolve();
|
|
|
|
} else {
|
|
|
|
invite_defer.reject(null);
|
2016-01-28 11:56:20 +00:00
|
|
|
// reset the promise so we don't auto-reject all invites from
|
|
|
|
// now on.
|
|
|
|
invite_defer = q.defer();
|
2016-01-15 15:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2016-01-28 11:56:20 +00:00
|
|
|
inviteWarningDefer.resolve();
|
2016-01-15 15:18:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 11:56:20 +00:00
|
|
|
var promise = inviteWarningDefer.promise;
|
2015-11-09 17:36:14 +00:00
|
|
|
if (isEmailAddress) {
|
2016-01-15 15:18:55 +00:00
|
|
|
promise = promise.then(function() {
|
2016-03-09 18:48:38 +00:00
|
|
|
return MatrixClientPeg.get().inviteByEmail(self.props.roomId, inputText);
|
2016-01-15 15:18:55 +00:00
|
|
|
});
|
2015-11-09 17:36:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-01-15 15:18:55 +00:00
|
|
|
promise = promise.then(function() {
|
2016-03-09 18:48:38 +00:00
|
|
|
return MatrixClientPeg.get().invite(self.props.roomId, inputText);
|
2016-01-15 15:18:55 +00:00
|
|
|
});
|
2015-11-09 17:36:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
self.setState({
|
|
|
|
inviting: true
|
|
|
|
});
|
2015-11-09 17:36:14 +00:00
|
|
|
console.log(
|
|
|
|
"Invite %s to %s - isEmail=%s", inputText, this.props.roomId, isEmailAddress
|
|
|
|
);
|
2016-03-17 18:49:34 +00:00
|
|
|
promise.then(function(res) {
|
2016-01-28 11:56:20 +00:00
|
|
|
console.log("Invited %s", inputText);
|
2015-09-18 17:39:16 +00:00
|
|
|
}, function(err) {
|
2016-01-15 15:18:55 +00:00
|
|
|
if (err !== null) {
|
|
|
|
console.error("Failed to invite: %s", JSON.stringify(err));
|
2016-03-22 16:33:39 +00:00
|
|
|
if (err.errcode == 'M_FORBIDDEN') {
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Unable to Invite",
|
|
|
|
description: "You do not have permission to invite people to this room."
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Server error whilst inviting",
|
|
|
|
description: err.message
|
|
|
|
});
|
|
|
|
}
|
2016-01-15 15:18:55 +00:00
|
|
|
}
|
2016-03-17 18:49:34 +00:00
|
|
|
}).finally(function() {
|
2015-09-18 17:39:16 +00:00
|
|
|
self.setState({
|
|
|
|
inviting: false
|
|
|
|
});
|
2016-03-17 18:49:34 +00:00
|
|
|
// XXX: hacky focus on the invite box
|
|
|
|
setTimeout(function() {
|
|
|
|
var inviteBox = document.getElementById("mx_SearchableEntityList_query");
|
|
|
|
if (inviteBox) {
|
|
|
|
inviteBox.focus();
|
|
|
|
}
|
|
|
|
}, 0);
|
2015-09-18 17:39:16 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-09 16:24:48 +00:00
|
|
|
getMemberDict: function() {
|
2015-09-18 17:39:16 +00:00
|
|
|
if (!this.props.roomId) return {};
|
2015-06-24 12:48:39 +00:00
|
|
|
var cli = MatrixClientPeg.get();
|
2015-09-18 17:39:16 +00:00
|
|
|
var room = cli.getRoom(this.props.roomId);
|
|
|
|
if (!room) return {};
|
2015-10-09 16:24:48 +00:00
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
var all_members = room.currentState.members;
|
|
|
|
|
2015-10-09 16:24:48 +00:00
|
|
|
Object.keys(all_members).map(function(userId) {
|
2016-03-04 16:57:20 +00:00
|
|
|
// work around a race where you might have a room member object
|
|
|
|
// before the user object exists. This may or may not cause
|
|
|
|
// https://github.com/vector-im/vector-web/issues/186
|
|
|
|
if (all_members[userId].user === null) {
|
|
|
|
all_members[userId].user = MatrixClientPeg.get().getUser(userId);
|
|
|
|
}
|
|
|
|
|
2016-04-18 00:35:40 +00:00
|
|
|
// XXX: this user may have no lastPresenceTs value!
|
|
|
|
// the right solution here is to fix the race rather than leave it as 0
|
2015-09-28 10:32:00 +00:00
|
|
|
});
|
|
|
|
|
2015-10-09 16:24:48 +00:00
|
|
|
return all_members;
|
|
|
|
},
|
2015-09-18 17:39:16 +00:00
|
|
|
|
2016-07-14 17:40:43 +00:00
|
|
|
roomMembers: function() {
|
2015-10-21 13:45:39 +00:00
|
|
|
var all_members = this.memberDict || {};
|
2015-10-09 16:24:48 +00:00
|
|
|
var all_user_ids = Object.keys(all_members);
|
2016-04-12 00:54:51 +00:00
|
|
|
var ConferenceHandler = CallHandler.getConferenceHandler();
|
2015-09-18 17:39:16 +00:00
|
|
|
|
2016-04-18 13:07:20 +00:00
|
|
|
all_user_ids.sort(this.memberSort);
|
2015-09-18 17:39:16 +00:00
|
|
|
|
2015-10-09 16:24:48 +00:00
|
|
|
var to_display = [];
|
2015-06-25 13:57:35 +00:00
|
|
|
var count = 0;
|
2016-07-14 17:40:43 +00:00
|
|
|
for (var i = 0; i < all_user_ids.length; ++i) {
|
2015-06-24 13:01:59 +00:00
|
|
|
var user_id = all_user_ids[i];
|
2015-06-24 12:48:39 +00:00
|
|
|
var m = all_members[user_id];
|
|
|
|
|
|
|
|
if (m.membership == 'join' || m.membership == 'invite') {
|
2016-04-12 00:54:51 +00:00
|
|
|
if ((ConferenceHandler && !ConferenceHandler.isConferenceUser(user_id)) || !ConferenceHandler) {
|
|
|
|
to_display.push(user_id);
|
|
|
|
++count;
|
|
|
|
}
|
2015-06-24 12:48:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return to_display;
|
2015-11-30 15:13:28 +00:00
|
|
|
},
|
|
|
|
|
2016-01-21 11:41:28 +00:00
|
|
|
_createOverflowTile: function(overflowCount, totalCount) {
|
|
|
|
// For now we'll pretend this is any entity. It should probably be a separate tile.
|
|
|
|
var EntityTile = sdk.getComponent("rooms.EntityTile");
|
2016-01-24 19:02:18 +00:00
|
|
|
var BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
2016-01-22 07:54:40 +00:00
|
|
|
var text = "and " + overflowCount + " other" + (overflowCount > 1 ? "s" : "") + "...";
|
2016-01-21 11:41:28 +00:00
|
|
|
return (
|
2016-01-21 17:39:12 +00:00
|
|
|
<EntityTile className="mx_EntityTile_ellipsis" avatarJsx={
|
|
|
|
<BaseAvatar url="img/ellipsis.svg" name="..." width={36} height={36} />
|
2016-01-21 15:57:59 +00:00
|
|
|
} name={text} presenceState="online" suppressOnHover={true}
|
|
|
|
onClick={this._showFullMemberList} />
|
2016-01-21 11:41:28 +00:00
|
|
|
);
|
|
|
|
},
|
2015-11-30 15:13:28 +00:00
|
|
|
|
2016-01-21 11:41:28 +00:00
|
|
|
_showFullMemberList: function() {
|
2016-01-21 15:57:59 +00:00
|
|
|
this.setState({
|
|
|
|
truncateAt: -1
|
|
|
|
});
|
2016-01-21 11:41:28 +00:00
|
|
|
},
|
2015-11-30 15:13:28 +00:00
|
|
|
|
2016-04-18 00:35:40 +00:00
|
|
|
memberString: function(member) {
|
|
|
|
if (!member) {
|
|
|
|
return "(null)";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "(" + member.name + ", " + member.powerLevel + ", " + member.user.lastActiveAgo + ", " + member.user.currentlyActive + ")";
|
|
|
|
}
|
|
|
|
},
|
2015-11-30 15:13:28 +00:00
|
|
|
|
2016-04-18 13:48:55 +00:00
|
|
|
// returns negative if a comes before b,
|
|
|
|
// returns 0 if a and b are equivalent in ordering
|
|
|
|
// returns positive if a comes after b.
|
2016-04-18 13:07:20 +00:00
|
|
|
memberSort: function(userIdA, userIdB) {
|
2016-04-18 00:35:40 +00:00
|
|
|
// order by last active, with "active now" first.
|
|
|
|
// ...and then by power
|
|
|
|
// ...and then alphabetically.
|
|
|
|
// We could tiebreak instead by "last recently spoken in this room" if we wanted to.
|
2015-11-30 15:13:28 +00:00
|
|
|
|
2016-04-18 00:35:40 +00:00
|
|
|
var memberA = this.memberDict[userIdA];
|
|
|
|
var memberB = this.memberDict[userIdB];
|
|
|
|
var userA = memberA.user;
|
|
|
|
var userB = memberB.user;
|
2015-11-30 15:13:28 +00:00
|
|
|
|
2016-04-18 00:45:46 +00:00
|
|
|
// if (!userA || !userB) {
|
|
|
|
// console.log("comparing " + memberA.name + " user=" + memberA.user + " with " + memberB.name + " user=" + memberB.user);
|
|
|
|
// }
|
2016-04-18 00:35:40 +00:00
|
|
|
|
|
|
|
if (!userA && !userB) return 0;
|
|
|
|
if (userA && !userB) return -1;
|
|
|
|
if (!userA && userB) return 1;
|
|
|
|
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log("comparing " + this.memberString(memberA) + " and " + this.memberString(memberB));
|
2016-04-18 00:35:40 +00:00
|
|
|
|
|
|
|
if (userA.currentlyActive && userB.currentlyActive) {
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log(memberA.name + " and " + memberB.name + " are both active");
|
2016-04-18 00:35:40 +00:00
|
|
|
if (memberA.powerLevel === memberB.powerLevel) {
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log(memberA + " and " + memberB + " have same power level");
|
2016-04-18 00:35:40 +00:00
|
|
|
if (memberA.name && memberB.name) {
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log("comparing names: " + memberA.name + " and " + memberB.name);
|
2016-05-19 22:00:28 +00:00
|
|
|
var nameA = memberA.name[0] === '@' ? memberA.name.substr(1) : memberA.name;
|
|
|
|
var nameB = memberB.name[0] === '@' ? memberB.name.substr(1) : memberB.name;
|
|
|
|
return nameA.localeCompare(nameB);
|
2016-04-18 00:35:40 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-04-18 00:45:46 +00:00
|
|
|
// console.log("comparing power: " + memberA.powerLevel + " and " + memberB.powerLevel);
|
2016-04-18 00:35:40 +00:00
|
|
|
return memberB.powerLevel - memberA.powerLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userA.currentlyActive && !userB.currentlyActive) return -1;
|
|
|
|
if (!userA.currentlyActive && userB.currentlyActive) return 1;
|
2015-11-30 15:13:28 +00:00
|
|
|
|
2016-06-29 08:33:41 +00:00
|
|
|
// For now, let's just order things by timestamp. It's really annoying
|
|
|
|
// that a user disappears from sight just because they temporarily go offline
|
2016-06-29 08:45:24 +00:00
|
|
|
return userB.getLastActiveTs() - userA.getLastActiveTs();
|
2015-11-30 15:13:28 +00:00
|
|
|
},
|
|
|
|
|
2016-01-19 14:51:26 +00:00
|
|
|
onSearchQueryChanged: function(input) {
|
|
|
|
this.setState({
|
|
|
|
searchQuery: input
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
makeMemberTiles: function(membership, query) {
|
2015-11-30 15:13:28 +00:00
|
|
|
var MemberTile = sdk.getComponent("rooms.MemberTile");
|
2016-01-19 14:51:26 +00:00
|
|
|
query = (query || "").toLowerCase();
|
2015-11-30 15:13:28 +00:00
|
|
|
|
|
|
|
var self = this;
|
2016-01-13 15:55:28 +00:00
|
|
|
|
|
|
|
var memberList = self.state.members.filter(function(userId) {
|
2015-11-30 15:13:28 +00:00
|
|
|
var m = self.memberDict[userId];
|
2016-07-13 10:56:01 +00:00
|
|
|
|
|
|
|
if (query) {
|
|
|
|
const matchesName = m.name.toLowerCase().indexOf(query) !== -1;
|
|
|
|
const matchesId = m.userId.toLowerCase().indexOf(query) !== -1;
|
|
|
|
|
|
|
|
if (!matchesName && !matchesId) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 14:51:26 +00:00
|
|
|
}
|
2016-07-13 10:56:01 +00:00
|
|
|
|
2015-11-30 15:13:28 +00:00
|
|
|
return m.membership == membership;
|
|
|
|
}).map(function(userId) {
|
|
|
|
var m = self.memberDict[userId];
|
|
|
|
return (
|
|
|
|
<MemberTile key={userId} member={m} ref={userId} />
|
|
|
|
);
|
|
|
|
});
|
2016-01-13 15:55:28 +00:00
|
|
|
|
2016-03-11 14:18:30 +00:00
|
|
|
// XXX: surely this is not the right home for this logic.
|
2016-01-13 15:55:28 +00:00
|
|
|
if (membership === "invite") {
|
|
|
|
// include 3pid invites (m.room.third_party_invite) state events.
|
|
|
|
// The HS may have already converted these into m.room.member invites so
|
|
|
|
// we shouldn't add them if the 3pid invite state key (token) is in the
|
|
|
|
// member invite (content.third_party_invite.signed.token)
|
|
|
|
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
2016-01-18 16:55:51 +00:00
|
|
|
var EntityTile = sdk.getComponent("rooms.EntityTile");
|
2016-01-13 15:55:28 +00:00
|
|
|
if (room) {
|
|
|
|
room.currentState.getStateEvents("m.room.third_party_invite").forEach(
|
|
|
|
function(e) {
|
2016-03-11 14:18:30 +00:00
|
|
|
// any events without these keys are not valid 3pid invites, so we ignore them
|
|
|
|
var required_keys = ['key_validity_url', 'public_key', 'display_name'];
|
|
|
|
for (var i = 0; i < required_keys.length; ++i) {
|
|
|
|
if (e.getContent()[required_keys[i]] === undefined) return;
|
|
|
|
}
|
|
|
|
|
2016-01-13 15:55:28 +00:00
|
|
|
// discard all invites which have a m.room.member event since we've
|
|
|
|
// already added them.
|
|
|
|
var memberEvent = room.currentState.getInviteForThreePidToken(e.getStateKey());
|
|
|
|
if (memberEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memberList.push(
|
2016-01-21 15:57:59 +00:00
|
|
|
<EntityTile key={e.getStateKey()} name={e.getContent().display_name} />
|
2016-01-13 16:55:28 +00:00
|
|
|
)
|
2016-01-13 15:55:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return memberList;
|
2015-11-30 15:13:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2016-02-08 15:05:35 +00:00
|
|
|
var InviteMemberList = sdk.getComponent("rooms.InviteMemberList");
|
|
|
|
|
2015-11-30 15:13:28 +00:00
|
|
|
var invitedSection = null;
|
2016-01-19 14:51:26 +00:00
|
|
|
var invitedMemberTiles = this.makeMemberTiles('invite', this.state.searchQuery);
|
2015-11-30 15:13:28 +00:00
|
|
|
if (invitedMemberTiles.length > 0) {
|
|
|
|
invitedSection = (
|
|
|
|
<div className="mx_MemberList_invited">
|
|
|
|
<h2>Invited</h2>
|
2016-08-01 16:10:46 +00:00
|
|
|
<div className="mx_MemberList_wrapper">
|
2015-11-30 15:13:28 +00:00
|
|
|
{invitedMemberTiles}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-02-08 15:05:35 +00:00
|
|
|
|
|
|
|
var inviteMemberListSection;
|
|
|
|
if (this.state.inviting) {
|
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
inviteMemberListSection = (
|
|
|
|
<Loader />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inviteMemberListSection = (
|
|
|
|
<InviteMemberList roomId={this.props.roomId}
|
|
|
|
onSearchQueryChanged={this.onSearchQueryChanged}
|
2016-06-01 22:42:34 +00:00
|
|
|
onThirdPartyInvite={this.onThirdPartyInvite}
|
2016-02-08 15:05:35 +00:00
|
|
|
onInvite={this.onInvite} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-21 11:30:37 +00:00
|
|
|
var TruncatedList = sdk.getComponent("elements.TruncatedList");
|
2015-11-30 15:13:28 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_MemberList">
|
2016-02-08 15:05:35 +00:00
|
|
|
{inviteMemberListSection}
|
2016-04-20 11:25:19 +00:00
|
|
|
<GeminiScrollbar autoshow={true}
|
|
|
|
className="mx_MemberList_joined mx_MemberList_outerWrapper">
|
2016-01-21 15:57:59 +00:00
|
|
|
<TruncatedList className="mx_MemberList_wrapper" truncateAt={this.state.truncateAt}
|
2016-01-21 11:41:28 +00:00
|
|
|
createOverflowElement={this._createOverflowTile}>
|
2016-01-19 14:51:26 +00:00
|
|
|
{this.makeMemberTiles('join', this.state.searchQuery)}
|
2016-01-21 11:30:37 +00:00
|
|
|
</TruncatedList>
|
2016-01-20 22:04:49 +00:00
|
|
|
{invitedSection}
|
2016-01-20 22:11:58 +00:00
|
|
|
</GeminiScrollbar>
|
2015-11-30 15:13:28 +00:00
|
|
|
</div>
|
|
|
|
);
|
2015-06-22 10:42:09 +00:00
|
|
|
}
|
2015-11-30 15:13:28 +00:00
|
|
|
});
|