2015-06-23 18:41:25 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-07-25 17:56:16 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-03-19 19:47:12 +03:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2021-06-23 14:45:55 +03:00
|
|
|
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
2015-06-23 18:41:25 +03: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.
|
|
|
|
*/
|
2017-09-22 15:15:02 +03:00
|
|
|
|
|
|
|
import React from 'react';
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2018-03-19 19:47:12 +03:00
|
|
|
import SdkConfig from '../../../SdkConfig';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2021-06-23 14:45:55 +03:00
|
|
|
import { isValid3pidInvite } from "../../../RoomInvite";
|
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
|
|
|
import { CommunityPrototypeStore } from "../../../stores/CommunityPrototypeStore";
|
2020-09-08 12:19:51 +03:00
|
|
|
import BaseCard from "../right_panel/BaseCard";
|
2021-06-23 14:45:55 +03:00
|
|
|
import { RightPanelPhases } from "../../../stores/RightPanelStorePhases";
|
2021-03-02 12:51:11 +03:00
|
|
|
import RoomAvatar from "../avatars/RoomAvatar";
|
|
|
|
import RoomName from "../elements/RoomName";
|
2021-06-23 14:45:55 +03:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-05-06 01:59:07 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2021-06-23 14:45:55 +03:00
|
|
|
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
|
|
|
import { Room } from 'matrix-js-sdk/src/models/room';
|
|
|
|
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
|
|
|
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
|
|
|
|
import { User } from "matrix-js-sdk/src/models/user";
|
|
|
|
import TruncatedList from '../elements/TruncatedList';
|
|
|
|
import Spinner from "../elements/Spinner";
|
|
|
|
import SearchBox from "../../structures/SearchBox";
|
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
|
|
|
import EntityTile from "./EntityTile";
|
|
|
|
import MemberTile from "./MemberTile";
|
|
|
|
import BaseAvatar from '../avatars/BaseAvatar';
|
2021-07-01 20:35:38 +03:00
|
|
|
import { throttle } from 'lodash';
|
2015-06-22 13:42:09 +03:00
|
|
|
|
2017-09-22 15:15:02 +03:00
|
|
|
const INITIAL_LOAD_NUM_MEMBERS = 30;
|
2017-09-22 18:50:54 +03:00
|
|
|
const INITIAL_LOAD_NUM_INVITED = 5;
|
2017-09-22 19:01:14 +03:00
|
|
|
const SHOW_MORE_INCREMENT = 100;
|
2016-01-15 18:18:55 +03:00
|
|
|
|
2019-12-27 20:04:14 +03:00
|
|
|
// Regex applied to filter our punctuation in member names before applying sort, to fuzzy it a little
|
|
|
|
// matches all ASCII punctuation: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
|
|
|
|
const SORT_REGEX = /[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]+/g;
|
2019-12-26 22:27:04 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
interface IProps {
|
|
|
|
roomId: string;
|
|
|
|
onClose(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
loading: boolean;
|
|
|
|
members: Array<RoomMember>;
|
|
|
|
filteredJoinedMembers: Array<RoomMember>;
|
|
|
|
filteredInvitedMembers: Array<RoomMember | MatrixEvent>;
|
|
|
|
canInvite: boolean;
|
|
|
|
truncateAtJoined: number;
|
|
|
|
truncateAtInvited: number;
|
|
|
|
searchQuery: string;
|
|
|
|
}
|
|
|
|
|
2021-03-09 06:12:00 +03:00
|
|
|
@replaceableComponent("views.rooms.MemberList")
|
2021-06-23 14:45:55 +03:00
|
|
|
export default class MemberList extends React.Component<IProps, IState> {
|
|
|
|
private showPresence = true;
|
|
|
|
private mounted = false;
|
|
|
|
private collator: Intl.Collator;
|
|
|
|
private sortNames = new Map<RoomMember, string>(); // RoomMember -> sortName
|
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-02-15 01:37:59 +03:00
|
|
|
|
2018-09-03 12:13:56 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
if (cli.hasLazyLoadMembersEnabled()) {
|
2018-09-17 20:18:55 +03:00
|
|
|
// show an empty list
|
2021-06-23 14:45:55 +03:00
|
|
|
this.state = this.getMembersState([]);
|
2018-09-03 12:13:56 +03:00
|
|
|
} else {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.state = this.getMembersState(this.roomMembers());
|
2018-09-03 12:13:56 +03:00
|
|
|
}
|
2018-08-29 11:30:25 +03:00
|
|
|
|
2018-09-13 19:43:24 +03:00
|
|
|
cli.on("Room", this.onRoom); // invites & joining after peek
|
2018-09-07 13:00:19 +03:00
|
|
|
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
|
|
|
|
const hsUrl = MatrixClientPeg.get().baseUrl;
|
2021-06-24 15:15:44 +03:00
|
|
|
this.showPresence = enablePresenceByHsUrl?.[hsUrl] ?? true;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-09-07 13:00:19 +03:00
|
|
|
|
2020-09-03 12:34:19 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
UNSAFE_componentWillMount() {
|
2020-08-29 14:51:37 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2021-06-23 14:45:55 +03:00
|
|
|
this.mounted = true;
|
2020-08-29 14:51:37 +03:00
|
|
|
if (cli.hasLazyLoadMembersEnabled()) {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.showMembersAccordingToMembershipWithLL();
|
2020-08-29 14:51:37 +03:00
|
|
|
cli.on("Room.myMembership", this.onMyMembership);
|
|
|
|
} else {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.listenForMembersChanges();
|
2020-08-29 14:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
2018-09-07 13:00:19 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private listenForMembersChanges(): void {
|
2017-10-11 19:56:17 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2015-06-22 13:42:09 +03:00
|
|
|
cli.on("RoomState.members", this.onRoomStateMember);
|
2015-10-28 18:15:35 +03:00
|
|
|
cli.on("RoomMember.name", this.onRoomMemberName);
|
2016-01-22 18:11:36 +03:00
|
|
|
cli.on("RoomState.events", this.onRoomStateEvent);
|
2016-07-14 12:05:40 +03: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).
|
2018-12-21 00:56:18 +03:00
|
|
|
cli.on("User.lastPresenceTs", this.onUserPresenceChange);
|
|
|
|
cli.on("User.presence", this.onUserPresenceChange);
|
|
|
|
cli.on("User.currentlyActive", this.onUserPresenceChange);
|
2016-04-18 03:35:40 +03:00
|
|
|
// cli.on("Room.timeline", this.onRoomTimeline);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-08-29 12:09:55 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentWillUnmount() {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.mounted = false;
|
2017-10-11 19:56:17 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2016-04-18 03:35:40 +03:00
|
|
|
if (cli) {
|
|
|
|
cli.removeListener("RoomState.members", this.onRoomStateMember);
|
|
|
|
cli.removeListener("RoomMember.name", this.onRoomMemberName);
|
2018-09-17 20:14:52 +03:00
|
|
|
cli.removeListener("Room.myMembership", this.onMyMembership);
|
2016-04-18 03:35:40 +03:00
|
|
|
cli.removeListener("RoomState.events", this.onRoomStateEvent);
|
|
|
|
cli.removeListener("Room", this.onRoom);
|
2018-12-21 00:56:18 +03:00
|
|
|
cli.removeListener("User.lastPresenceTs", this.onUserPresenceChange);
|
|
|
|
cli.removeListener("User.presence", this.onUserPresenceChange);
|
|
|
|
cli.removeListener("User.currentlyActive", this.onUserPresenceChange);
|
2015-06-22 13:42:09 +03:00
|
|
|
}
|
2016-08-10 15:39:47 +03:00
|
|
|
|
|
|
|
// cancel any pending calls to the rate_limited_funcs
|
2021-07-01 20:35:38 +03:00
|
|
|
this.updateList.cancel();
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-06-22 13:42:09 +03:00
|
|
|
|
2018-09-17 20:20:26 +03:00
|
|
|
/**
|
|
|
|
* If lazy loading is enabled, either:
|
|
|
|
* show a spinner and load the members if the user is joined,
|
2018-09-17 21:03:01 +03:00
|
|
|
* or show the members available so far if the user is invited
|
2018-09-17 20:20:26 +03:00
|
|
|
*/
|
2021-06-23 14:45:55 +03:00
|
|
|
private async showMembersAccordingToMembershipWithLL(): Promise<void> {
|
2018-08-29 11:30:25 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2018-09-13 19:43:24 +03:00
|
|
|
if (cli.hasLazyLoadMembersEnabled()) {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const room = cli.getRoom(this.props.roomId);
|
2018-09-17 21:03:01 +03:00
|
|
|
const membership = room && room.getMyMembership();
|
|
|
|
if (membership === "join") {
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ loading: true });
|
2018-09-13 19:43:24 +03:00
|
|
|
try {
|
|
|
|
await room.loadMembersIfNeeded();
|
2018-09-17 21:01:55 +03:00
|
|
|
} catch (ex) {/* already logged in RoomView */}
|
2021-06-23 14:45:55 +03:00
|
|
|
if (this.mounted) {
|
|
|
|
this.setState(this.getMembersState(this.roomMembers()));
|
|
|
|
this.listenForMembersChanges();
|
2018-09-13 19:43:24 +03:00
|
|
|
}
|
2020-10-01 14:30:41 +03:00
|
|
|
} else {
|
|
|
|
// show the members we already have loaded
|
2021-06-23 14:45:55 +03:00
|
|
|
this.setState(this.getMembersState(this.roomMembers()));
|
2018-09-13 19:43:24 +03:00
|
|
|
}
|
2018-08-29 11:30:25 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-08-29 11:30:25 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private get canInvite(): boolean {
|
2021-05-19 15:16:10 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const room = cli.getRoom(this.props.roomId);
|
|
|
|
return room && room.canInvite(cli.getUserId());
|
|
|
|
}
|
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getMembersState(members: Array<RoomMember>): IState {
|
|
|
|
// set the state after determining showPresence to make sure it's
|
|
|
|
// taken into account while rendering
|
2018-09-03 12:13:56 +03:00
|
|
|
return {
|
|
|
|
loading: false,
|
|
|
|
members: members,
|
2021-06-23 14:45:55 +03:00
|
|
|
filteredJoinedMembers: this.filterMembers(members, 'join'),
|
|
|
|
filteredInvitedMembers: this.filterMembers(members, 'invite'),
|
2021-05-19 15:16:10 +03:00
|
|
|
canInvite: this.canInvite,
|
2018-09-03 12:13:56 +03:00
|
|
|
|
|
|
|
// ideally we'd size this to the page height, but
|
|
|
|
// in practice I find that a little constraining
|
|
|
|
truncateAtJoined: INITIAL_LOAD_NUM_MEMBERS,
|
|
|
|
truncateAtInvited: INITIAL_LOAD_NUM_INVITED,
|
|
|
|
searchQuery: "",
|
|
|
|
};
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-09-03 12:13:56 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onUserPresenceChange = (event: MatrixEvent, user: User): void => {
|
2015-09-18 20:39:16 +03: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
|
2018-12-21 00:56:18 +03:00
|
|
|
// ever attaching their own listener.
|
2017-10-11 19:56:17 +03:00
|
|
|
const tile = this.refs[user.userId];
|
2018-12-21 00:57:27 +03:00
|
|
|
// console.log(`Got presence update for ${user.userId}. hasTile=${!!tile}`);
|
2016-04-18 03:35:40 +03:00
|
|
|
if (tile) {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.updateList(); // reorder the membership list
|
2015-09-18 20:39:16 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-01-20 17:41:48 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onRoom = (room: Room): void => {
|
2015-09-18 20:39:16 +03:00
|
|
|
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.
|
2021-06-23 14:45:55 +03:00
|
|
|
this.showMembersAccordingToMembershipWithLL();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-09-13 19:43:24 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onMyMembership = (room: Room, membership: string, oldMembership: string): void => {
|
2018-09-17 20:14:52 +03:00
|
|
|
if (room.roomId === this.props.roomId && membership === "join") {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.showMembersAccordingToMembershipWithLL();
|
2018-09-13 19:43:24 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2015-09-18 20:39:16 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onRoomStateMember = (ev: MatrixEvent, state: RoomState, member: RoomMember): void => {
|
2018-09-07 15:05:26 +03:00
|
|
|
if (member.roomId !== this.props.roomId) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-23 14:45:55 +03:00
|
|
|
this.updateList();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2015-09-18 20:39:16 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onRoomMemberName = (ev: MatrixEvent, member: RoomMember): void => {
|
2018-09-07 15:05:26 +03:00
|
|
|
if (member.roomId !== this.props.roomId) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-23 14:45:55 +03:00
|
|
|
this.updateList();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2015-10-28 18:15:35 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onRoomStateEvent = (event: MatrixEvent, state: RoomState): void => {
|
2018-09-07 15:05:26 +03:00
|
|
|
if (event.getRoomId() === this.props.roomId &&
|
|
|
|
event.getType() === "m.room.third_party_invite") {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.updateList();
|
2016-01-22 18:11:36 +03:00
|
|
|
}
|
2021-05-19 12:01:04 +03:00
|
|
|
|
2021-05-19 15:16:10 +03:00
|
|
|
if (this.canInvite !== this.state.canInvite) this.setState({ canInvite: this.canInvite });
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-01-22 18:11:36 +03:00
|
|
|
|
2021-07-01 20:35:38 +03:00
|
|
|
private updateList = throttle(() => {
|
2021-06-23 14:45:55 +03:00
|
|
|
this.updateListNow();
|
2021-07-01 20:35:38 +03:00
|
|
|
}, 500, { leading: true, trailing: true });
|
2019-01-04 07:55:52 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private updateListNow(): void {
|
2021-06-29 15:11:58 +03:00
|
|
|
const members = this.roomMembers();
|
2021-06-23 14:45:55 +03:00
|
|
|
|
|
|
|
this.setState({
|
2018-09-13 19:43:24 +03:00
|
|
|
loading: false,
|
2021-06-23 14:45:55 +03:00
|
|
|
members: members,
|
|
|
|
filteredJoinedMembers: this.filterMembers(members, 'join', this.state.searchQuery),
|
|
|
|
filteredInvitedMembers: this.filterMembers(members, 'invite', this.state.searchQuery),
|
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-06-24 15:48:39 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getMembersWithUser(): Array<RoomMember> {
|
2018-09-08 00:44:20 +03:00
|
|
|
if (!this.props.roomId) return [];
|
2017-10-11 19:56:17 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const room = cli.getRoom(this.props.roomId);
|
2018-09-10 18:32:40 +03:00
|
|
|
if (!room) return [];
|
2015-10-09 19:24:48 +03:00
|
|
|
|
2018-09-08 00:44:20 +03:00
|
|
|
const allMembers = Object.values(room.currentState.members);
|
2015-09-18 20:39:16 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
allMembers.forEach((member) => {
|
2016-03-04 19:57:20 +03:00
|
|
|
// work around a race where you might have a room member object
|
2021-06-23 14:45:55 +03:00
|
|
|
// before the user object exists. This may or may not cause
|
2016-03-04 19:57:20 +03:00
|
|
|
// https://github.com/vector-im/vector-web/issues/186
|
2021-06-23 14:45:55 +03:00
|
|
|
if (!member.user) {
|
2018-09-05 16:25:08 +03:00
|
|
|
member.user = cli.getUser(member.userId);
|
2016-03-04 19:57:20 +03:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
this.sortNames.set(
|
|
|
|
member,
|
|
|
|
(member.name[0] === '@' ? member.name.substr(1) : member.name).replace(SORT_REGEX, ""),
|
|
|
|
);
|
2021-06-02 12:42:17 +03:00
|
|
|
|
2016-04-18 03:35:40 +03: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 13:32:00 +03:00
|
|
|
});
|
|
|
|
|
2018-09-08 00:44:20 +03:00
|
|
|
return allMembers;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-09-18 20:39:16 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private roomMembers(): Array<RoomMember> {
|
2018-09-08 00:44:20 +03:00
|
|
|
const allMembers = this.getMembersWithUser();
|
2018-09-05 16:25:08 +03:00
|
|
|
const filteredAndSortedMembers = allMembers.filter((m) => {
|
|
|
|
return (
|
|
|
|
m.membership === 'join' || m.membership === 'invite'
|
|
|
|
);
|
|
|
|
});
|
2021-06-02 12:42:17 +03:00
|
|
|
const language = SettingsStore.getValue("language");
|
2021-06-23 14:45:55 +03:00
|
|
|
this.collator = new Intl.Collator(language, { sensitivity: 'base', ignorePunctuation: false });
|
2018-09-05 16:25:08 +03:00
|
|
|
filteredAndSortedMembers.sort(this.memberSort);
|
|
|
|
return filteredAndSortedMembers;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private createOverflowTileJoined = (overflowCount: number, totalCount: number): JSX.Element => {
|
|
|
|
return this.createOverflowTile(overflowCount, totalCount, this.showMoreJoinedMemberList);
|
2020-09-04 11:24:12 +03:00
|
|
|
};
|
2017-09-22 18:50:54 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private createOverflowTileInvited = (overflowCount: number, totalCount: number): JSX.Element => {
|
|
|
|
return this.createOverflowTile(overflowCount, totalCount, this.showMoreInvitedMemberList);
|
2020-09-04 11:24:12 +03:00
|
|
|
};
|
2017-09-22 18:50:54 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private createOverflowTile = (overflowCount: number, totalCount: number, onClick: () => void): JSX.Element=> {
|
2016-01-21 14:41:28 +03:00
|
|
|
// For now we'll pretend this is any entity. It should probably be a separate tile.
|
2017-07-25 17:56:16 +03:00
|
|
|
const text = _t("and %(count)s others...", { count: overflowCount });
|
2016-01-21 14:41:28 +03:00
|
|
|
return (
|
2016-01-21 20:39:12 +03:00
|
|
|
<EntityTile className="mx_EntityTile_ellipsis" avatarJsx={
|
2019-01-11 04:37:28 +03:00
|
|
|
<BaseAvatar url={require("../../../../res/img/ellipsis.svg")} name="..." width={36} height={36} />
|
2016-01-21 18:57:59 +03:00
|
|
|
} name={text} presenceState="online" suppressOnHover={true}
|
2017-09-22 18:50:54 +03:00
|
|
|
onClick={onClick} />
|
2016-01-21 14:41:28 +03:00
|
|
|
);
|
2020-09-04 11:24:12 +03:00
|
|
|
};
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private showMoreJoinedMemberList = (): void => {
|
2017-09-22 18:50:54 +03:00
|
|
|
this.setState({
|
2017-09-22 19:01:14 +03:00
|
|
|
truncateAtJoined: this.state.truncateAtJoined + SHOW_MORE_INCREMENT,
|
2017-09-22 18:50:54 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-09-22 18:50:54 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private showMoreInvitedMemberList = (): void => {
|
2016-01-21 18:57:59 +03:00
|
|
|
this.setState({
|
2017-09-22 19:01:14 +03:00
|
|
|
truncateAtInvited: this.state.truncateAtInvited + SHOW_MORE_INCREMENT,
|
2016-01-21 18:57:59 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
/**
|
|
|
|
* SHOULD ONLY BE USED BY TESTS
|
|
|
|
*/
|
|
|
|
public memberString(member: RoomMember): string {
|
2016-04-18 03:35:40 +03:00
|
|
|
if (!member) {
|
|
|
|
return "(null)";
|
2017-10-11 19:56:17 +03:00
|
|
|
} else {
|
2018-12-21 00:56:18 +03:00
|
|
|
const u = member.user;
|
2021-06-23 14:45:55 +03:00
|
|
|
return (
|
|
|
|
"(" +
|
|
|
|
member.name +
|
|
|
|
", " +
|
|
|
|
member.powerLevel +
|
|
|
|
", " +
|
|
|
|
(u ? u.lastActiveAgo : "<null>") +
|
|
|
|
", " +
|
|
|
|
(u ? u.getLastActiveTs() : "<null>") +
|
|
|
|
", " +
|
|
|
|
(u ? u.currentlyActive : "<null>") +
|
|
|
|
", " +
|
|
|
|
(u ? u.presence : "<null>") +
|
|
|
|
")"
|
|
|
|
);
|
2016-04-18 03:35:40 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2016-04-18 16:48:55 +03: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.
|
2021-06-23 14:45:55 +03:00
|
|
|
private memberSort = (memberA: RoomMember, memberB: RoomMember): number => {
|
2018-12-21 00:56:18 +03:00
|
|
|
// order by presence, with "active now" first.
|
|
|
|
// ...and then by power level
|
|
|
|
// ...and then by last active
|
|
|
|
// ...and then alphabetically.
|
|
|
|
// We could tiebreak instead by "last recently spoken in this room" if we wanted to.
|
|
|
|
|
2018-12-21 00:57:27 +03:00
|
|
|
// console.log(`Comparing userA=${this.memberString(memberA)} userB=${this.memberString(memberB)}`);
|
2018-12-21 00:56:18 +03:00
|
|
|
|
|
|
|
const userA = memberA.user;
|
|
|
|
const userB = memberB.user;
|
|
|
|
|
2018-12-21 00:57:27 +03:00
|
|
|
// if (!userA) console.log("!! MISSING USER FOR A-SIDE: " + memberA.name + " !!");
|
|
|
|
// if (!userB) console.log("!! MISSING USER FOR B-SIDE: " + memberB.name + " !!");
|
2018-12-21 00:56:18 +03:00
|
|
|
|
|
|
|
if (!userA && !userB) return 0;
|
|
|
|
if (userA && !userB) return -1;
|
|
|
|
if (!userA && userB) return 1;
|
|
|
|
|
|
|
|
// First by presence
|
2021-06-23 14:45:55 +03:00
|
|
|
if (this.showPresence) {
|
2018-12-21 00:56:18 +03:00
|
|
|
const convertPresence = (p) => p === 'unavailable' ? 'online' : p;
|
|
|
|
const presenceIndex = p => {
|
|
|
|
const order = ['active', 'online', 'offline'];
|
|
|
|
const idx = order.indexOf(convertPresence(p));
|
|
|
|
return idx === -1 ? order.length : idx; // unknown states at the end
|
|
|
|
};
|
|
|
|
|
|
|
|
const idxA = presenceIndex(userA.currentlyActive ? 'active' : userA.presence);
|
|
|
|
const idxB = presenceIndex(userB.currentlyActive ? 'active' : userB.presence);
|
2018-12-21 00:57:27 +03:00
|
|
|
// console.log(`userA_presenceGroup=${idxA} userB_presenceGroup=${idxB}`);
|
2018-12-21 00:56:18 +03:00
|
|
|
if (idxA !== idxB) {
|
2018-12-21 00:57:27 +03:00
|
|
|
// console.log("Comparing on presence group - returning");
|
2018-12-21 00:56:18 +03:00
|
|
|
return idxA - idxB;
|
2016-04-18 03:35:40 +03:00
|
|
|
}
|
2018-12-21 00:56:18 +03:00
|
|
|
}
|
2016-04-18 03:35:40 +03:00
|
|
|
|
2018-12-21 00:56:18 +03:00
|
|
|
// Second by power level
|
|
|
|
if (memberA.powerLevel !== memberB.powerLevel) {
|
2018-12-21 00:57:27 +03:00
|
|
|
// console.log("Comparing on power level - returning");
|
2018-12-21 00:56:18 +03:00
|
|
|
return memberB.powerLevel - memberA.powerLevel;
|
|
|
|
}
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2018-12-21 00:56:18 +03:00
|
|
|
// Third by last active
|
2021-06-23 14:45:55 +03:00
|
|
|
if (this.showPresence && userA.getLastActiveTs() !== userB.getLastActiveTs()) {
|
2018-12-21 00:57:27 +03:00
|
|
|
// console.log("Comparing on last active timestamp - returning");
|
2016-06-29 11:45:24 +03:00
|
|
|
return userB.getLastActiveTs() - userA.getLastActiveTs();
|
2018-12-21 00:56:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fourth by name (alphabetical)
|
2021-06-23 14:45:55 +03:00
|
|
|
return this.collator.compare(this.sortNames.get(memberA), this.sortNames.get(memberB));
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onSearchQueryChanged = (searchQuery: string): void => {
|
2017-09-22 15:15:02 +03:00
|
|
|
this.setState({
|
2019-02-24 07:42:04 +03:00
|
|
|
searchQuery,
|
2021-06-23 14:45:55 +03:00
|
|
|
filteredJoinedMembers: this.filterMembers(this.state.members, 'join', searchQuery),
|
|
|
|
filteredInvitedMembers: this.filterMembers(this.state.members, 'invite', searchQuery),
|
2017-09-22 15:15:02 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-01-19 17:51:26 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private onPending3pidInviteClick = (inviteEvent: MatrixEvent): void => {
|
2019-03-29 05:38:15 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_3pid_invite',
|
|
|
|
event: inviteEvent,
|
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2019-03-29 05:38:15 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private filterMembers(members: Array<RoomMember>, membership: string, query?: string): Array<RoomMember> {
|
2018-09-05 16:25:08 +03:00
|
|
|
return members.filter((m) => {
|
2016-07-13 13:56:01 +03:00
|
|
|
if (query) {
|
2017-10-14 19:09:58 +03:00
|
|
|
query = query.toLowerCase();
|
2016-07-13 13:56:01 +03:00
|
|
|
const matchesName = m.name.toLowerCase().indexOf(query) !== -1;
|
|
|
|
const matchesId = m.userId.toLowerCase().indexOf(query) !== -1;
|
|
|
|
|
|
|
|
if (!matchesName && !matchesId) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 17:51:26 +03:00
|
|
|
}
|
2016-07-13 13:56:01 +03:00
|
|
|
|
2017-10-14 19:10:51 +03:00
|
|
|
return m.membership === membership;
|
2017-09-22 15:15:02 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2017-09-22 15:15:02 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getPending3PidInvites(): Array<MatrixEvent> {
|
2018-01-25 15:18:02 +03:00
|
|
|
// 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)
|
|
|
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
|
|
|
|
if (room) {
|
|
|
|
return room.currentState.getStateEvents("m.room.third_party_invite").filter(function(e) {
|
2019-03-29 20:45:07 +03:00
|
|
|
if (!isValid3pidInvite(e)) return false;
|
2018-01-25 15:18:02 +03:00
|
|
|
|
|
|
|
// discard all invites which have a m.room.member event since we've
|
|
|
|
// already added them.
|
|
|
|
const memberEvent = room.currentState.getInviteForThreePidToken(e.getStateKey());
|
|
|
|
if (memberEvent) return false;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-01-25 15:18:02 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private makeMemberTiles(members: Array<RoomMember | MatrixEvent>) {
|
2019-07-03 10:38:08 +03:00
|
|
|
return members.map((m) => {
|
2021-06-23 14:45:55 +03:00
|
|
|
if (m instanceof RoomMember) {
|
2019-07-03 10:38:08 +03:00
|
|
|
// Is a Matrix invite
|
2021-06-23 14:45:55 +03:00
|
|
|
return <MemberTile key={m.userId} member={m} ref={m.userId} showPresence={this.showPresence} />;
|
2019-07-03 10:38:08 +03:00
|
|
|
} else {
|
|
|
|
// Is a 3pid invite
|
|
|
|
return <EntityTile key={m.getStateKey()} name={m.getContent().display_name} suppressOnHover={true}
|
2021-06-23 14:45:55 +03:00
|
|
|
onClick={() => this.onPending3pidInviteClick(m)} />;
|
2019-07-03 10:38:08 +03:00
|
|
|
}
|
2015-11-30 18:13:28 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-11-30 18:13:28 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getChildrenJoined = (start: number, end: number): Array<JSX.Element> => {
|
2021-06-29 15:11:58 +03:00
|
|
|
return this.makeMemberTiles(this.state.filteredJoinedMembers.slice(start, end));
|
2021-06-23 14:45:55 +03:00
|
|
|
};
|
2017-09-22 15:15:02 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getChildCountJoined = (): number => this.state.filteredJoinedMembers.length;
|
2017-09-22 15:15:02 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getChildrenInvited = (start: number, end: number): Array<JSX.Element> => {
|
2019-07-03 10:38:08 +03:00
|
|
|
let targets = this.state.filteredInvitedMembers;
|
|
|
|
if (end > this.state.filteredInvitedMembers.length) {
|
2021-06-23 14:45:55 +03:00
|
|
|
targets = targets.concat(this.getPending3PidInvites());
|
2019-07-03 10:38:08 +03:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
return this.makeMemberTiles(targets.slice(start, end));
|
2020-08-29 14:51:37 +03:00
|
|
|
};
|
2017-09-22 18:50:54 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
private getChildCountInvited = (): number => {
|
|
|
|
return this.state.filteredInvitedMembers.length + (this.getPending3PidInvites() || []).length;
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2017-09-22 18:50:54 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2018-08-29 11:30:25 +03:00
|
|
|
if (this.state.loading) {
|
2020-09-08 12:19:51 +03:00
|
|
|
return <BaseCard
|
|
|
|
className="mx_MemberList"
|
|
|
|
onClose={this.props.onClose}
|
|
|
|
previousPhase={RightPanelPhases.RoomSummary}
|
|
|
|
>
|
|
|
|
<Spinner />
|
|
|
|
</BaseCard>;
|
2018-08-29 11:30:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-24 14:50:58 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const room = cli.getRoom(this.props.roomId);
|
|
|
|
let inviteButton;
|
2019-05-11 21:45:24 +03:00
|
|
|
|
2018-10-24 17:44:18 +03:00
|
|
|
if (room && room.getMyMembership() === 'join') {
|
2020-08-31 19:12:12 +03:00
|
|
|
let inviteButtonText = _t("Invite to this room");
|
2020-08-31 19:19:05 +03:00
|
|
|
const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat();
|
|
|
|
if (chat && chat.roomId === this.props.roomId) {
|
|
|
|
inviteButtonText = _t("Invite to this community");
|
2021-05-06 01:59:07 +03:00
|
|
|
} else if (SettingsStore.getValue("feature_spaces") && room.isSpaceRoom()) {
|
2021-03-02 12:51:11 +03:00
|
|
|
inviteButtonText = _t("Invite to this space");
|
2020-08-31 19:12:12 +03:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
inviteButton = (
|
|
|
|
<AccessibleButton
|
|
|
|
className="mx_MemberList_invite"
|
|
|
|
onClick={this.onInviteButtonClick}
|
|
|
|
disabled={!this.state.canInvite}
|
|
|
|
>
|
2020-08-31 19:12:12 +03:00
|
|
|
<span>{ inviteButtonText }</span>
|
2021-06-23 14:45:55 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2018-10-24 14:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let invitedHeader;
|
|
|
|
let invitedSection;
|
2021-06-23 14:45:55 +03:00
|
|
|
if (this.getChildCountInvited() > 0) {
|
2018-10-24 14:50:58 +03:00
|
|
|
invitedHeader = <h2>{ _t("Invited") }</h2>;
|
2021-06-23 14:45:55 +03:00
|
|
|
invitedSection = (
|
|
|
|
<TruncatedList
|
|
|
|
className="mx_MemberList_section mx_MemberList_invited"
|
|
|
|
truncateAt={this.state.truncateAtInvited}
|
|
|
|
createOverflowElement={this.createOverflowTileInvited}
|
|
|
|
getChildren={this.getChildrenInvited}
|
|
|
|
getChildCount={this.getChildCountInvited}
|
|
|
|
/>
|
|
|
|
);
|
2015-11-30 18:13:28 +03:00
|
|
|
}
|
2016-02-08 18:05:35 +03:00
|
|
|
|
2020-09-08 12:19:51 +03:00
|
|
|
const footer = (
|
|
|
|
<SearchBox
|
|
|
|
className="mx_MemberList_query mx_textinput_icon mx_textinput_search"
|
|
|
|
placeholder={ _t('Filter room members') }
|
|
|
|
onSearch={ this.onSearchQueryChanged } />
|
2015-11-30 18:13:28 +03:00
|
|
|
);
|
2020-09-08 12:19:51 +03:00
|
|
|
|
2021-03-02 12:51:11 +03:00
|
|
|
let previousPhase = RightPanelPhases.RoomSummary;
|
|
|
|
// We have no previousPhase for when viewing a MemberList from a Space
|
|
|
|
let scopeHeader;
|
2021-05-06 01:59:07 +03:00
|
|
|
if (SettingsStore.getValue("feature_spaces") && room?.isSpaceRoom()) {
|
2021-03-02 12:51:11 +03:00
|
|
|
previousPhase = undefined;
|
|
|
|
scopeHeader = <div className="mx_RightPanel_scopeHeader">
|
|
|
|
<RoomAvatar room={room} height={32} width={32} />
|
|
|
|
<RoomName room={room} />
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
2020-09-08 12:19:51 +03:00
|
|
|
return <BaseCard
|
|
|
|
className="mx_MemberList"
|
2021-03-02 12:51:11 +03:00
|
|
|
header={<React.Fragment>
|
|
|
|
{ scopeHeader }
|
|
|
|
{ inviteButton }
|
|
|
|
</React.Fragment>}
|
2020-09-08 12:19:51 +03:00
|
|
|
footer={footer}
|
|
|
|
onClose={this.props.onClose}
|
2021-03-02 12:51:11 +03:00
|
|
|
previousPhase={previousPhase}
|
2020-09-08 12:19:51 +03:00
|
|
|
>
|
|
|
|
<div className="mx_MemberList_wrapper">
|
2021-06-23 14:45:55 +03:00
|
|
|
<TruncatedList
|
|
|
|
className="mx_MemberList_section mx_MemberList_joined"
|
|
|
|
truncateAt={this.state.truncateAtJoined}
|
|
|
|
createOverflowElement={this.createOverflowTileJoined}
|
|
|
|
getChildren={this.getChildrenJoined}
|
|
|
|
getChildCount={this.getChildCountJoined} />
|
2020-09-08 12:19:51 +03:00
|
|
|
{ invitedHeader }
|
|
|
|
{ invitedSection }
|
|
|
|
</div>
|
|
|
|
</BaseCard>;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-10-24 14:50:58 +03:00
|
|
|
|
2021-06-23 14:45:55 +03:00
|
|
|
onInviteButtonClick = (): void => {
|
2018-10-24 14:50:58 +03:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: 'require_registration' });
|
2018-10-24 14:50:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// call AddressPickerDialog
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_invite',
|
|
|
|
roomId: this.props.roomId,
|
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
|
|
|
}
|