2015-06-23 17:41:25 +02:00
|
|
|
/*
|
2016-01-07 05:06:39 +01:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-07-25 16:56:16 +02:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-03-19 17:47:12 +01:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2021-06-23 13:45:55 +02:00
|
|
|
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
2015-06-23 17:41:25 +02: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 14:15:02 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import React from "react";
|
2023-08-07 10:24:58 +02:00
|
|
|
import {
|
|
|
|
MatrixEvent,
|
|
|
|
Room,
|
|
|
|
RoomEvent,
|
|
|
|
RoomMember,
|
|
|
|
RoomMemberEvent,
|
|
|
|
RoomState,
|
|
|
|
RoomStateEvent,
|
2023-08-08 09:16:04 +02:00
|
|
|
User,
|
|
|
|
UserEvent,
|
2023-08-08 12:12:12 +02:00
|
|
|
EventType,
|
2023-08-09 09:18:41 +02:00
|
|
|
ClientEvent,
|
2023-08-07 10:24:58 +02:00
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2022-12-12 12:24:14 +01:00
|
|
|
import { throttle } from "lodash";
|
2023-10-20 15:30:37 +02:00
|
|
|
import { Button, Tooltip } from "@vector-im/compound-web";
|
|
|
|
import { Icon as UserAddIcon } from "@vector-im/compound-design-tokens/icons/user-add-solid.svg";
|
2021-12-09 10:10:23 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
|
|
|
import dis from "../../../dispatcher/dispatcher";
|
2021-06-23 13:45:55 +02:00
|
|
|
import { isValid3pidInvite } from "../../../RoomInvite";
|
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2020-09-08 11:19:51 +02:00
|
|
|
import BaseCard from "../right_panel/BaseCard";
|
2021-03-02 10:51:11 +01:00
|
|
|
import RoomAvatar from "../avatars/RoomAvatar";
|
|
|
|
import RoomName from "../elements/RoomName";
|
2022-12-12 12:24:14 +01:00
|
|
|
import TruncatedList from "../elements/TruncatedList";
|
2021-06-23 13:45:55 +02:00
|
|
|
import Spinner from "../elements/Spinner";
|
|
|
|
import SearchBox from "../../structures/SearchBox";
|
2023-10-20 15:30:37 +02:00
|
|
|
import { ButtonEvent } from "../elements/AccessibleButton";
|
2021-06-23 13:45:55 +02:00
|
|
|
import EntityTile from "./EntityTile";
|
|
|
|
import MemberTile from "./MemberTile";
|
2022-12-12 12:24:14 +01:00
|
|
|
import BaseAvatar from "../avatars/BaseAvatar";
|
2021-10-09 00:04:26 +02:00
|
|
|
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
|
|
|
|
import { UIComponent } from "../../../settings/UIFeature";
|
2022-02-09 15:42:08 +01:00
|
|
|
import PosthogTrackers from "../../../PosthogTrackers";
|
2022-12-12 12:24:14 +01:00
|
|
|
import { SDKContext } from "../../../contexts/SDKContext";
|
2023-11-21 02:43:32 +01:00
|
|
|
import { canInviteTo } from "../../../utils/room/canInviteTo";
|
|
|
|
import { inviteToRoom } from "../../../utils/room/inviteToRoom";
|
2015-06-22 12:42:09 +02:00
|
|
|
|
2017-09-22 14:15:02 +02:00
|
|
|
const INITIAL_LOAD_NUM_MEMBERS = 30;
|
2017-09-22 17:50:54 +02:00
|
|
|
const INITIAL_LOAD_NUM_INVITED = 5;
|
2017-09-22 18:01:14 +02:00
|
|
|
const SHOW_MORE_INCREMENT = 100;
|
2016-01-15 16:18:55 +01:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
interface IProps {
|
|
|
|
roomId: string;
|
2021-11-08 10:57:14 +01:00
|
|
|
searchQuery: string;
|
2021-06-23 13:45:55 +02:00
|
|
|
onClose(): void;
|
2021-11-08 10:57:14 +01:00
|
|
|
onSearchQueryChanged: (query: string) => void;
|
2021-06-23 13:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
loading: boolean;
|
|
|
|
filteredJoinedMembers: Array<RoomMember>;
|
|
|
|
filteredInvitedMembers: Array<RoomMember | MatrixEvent>;
|
|
|
|
canInvite: boolean;
|
|
|
|
truncateAtJoined: number;
|
|
|
|
truncateAtInvited: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class MemberList extends React.Component<IProps, IState> {
|
2023-03-01 16:59:27 +01:00
|
|
|
private readonly showPresence: boolean;
|
2021-06-23 13:45:55 +02:00
|
|
|
private mounted = false;
|
2018-08-29 10:30:25 +02:00
|
|
|
|
2022-12-16 13:29:59 +01:00
|
|
|
public static contextType = SDKContext;
|
2022-11-18 20:05:00 +01:00
|
|
|
public context!: React.ContextType<typeof SDKContext>;
|
2023-11-07 11:14:30 +01:00
|
|
|
private tiles: Map<string, MemberTile> = new Map();
|
2018-09-07 12:00:19 +02:00
|
|
|
|
2022-12-16 13:29:59 +01:00
|
|
|
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
|
2022-11-18 20:05:00 +01:00
|
|
|
super(props);
|
|
|
|
this.state = this.getMembersState([], []);
|
2023-04-04 12:41:46 +02:00
|
|
|
this.showPresence = context?.memberListStore.isPresenceEnabled() ?? true;
|
2021-06-23 13:45:55 +02:00
|
|
|
this.mounted = true;
|
2022-11-18 20:05:00 +01:00
|
|
|
this.listenForMembersChanges();
|
2020-08-29 13:51:37 +02:00
|
|
|
}
|
2018-09-07 12:00:19 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private listenForMembersChanges(): void {
|
2023-06-15 09:46:19 +02:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
2022-02-24 15:39:25 +01:00
|
|
|
cli.on(RoomStateEvent.Update, this.onRoomStateUpdate);
|
2022-02-22 13:18:08 +01:00
|
|
|
cli.on(RoomMemberEvent.Name, this.onRoomMemberName);
|
|
|
|
cli.on(RoomStateEvent.Events, this.onRoomStateEvent);
|
2016-07-14 11:05:40 +02: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).
|
2022-02-22 13:18:08 +01:00
|
|
|
cli.on(UserEvent.LastPresenceTs, this.onUserPresenceChange);
|
|
|
|
cli.on(UserEvent.Presence, this.onUserPresenceChange);
|
|
|
|
cli.on(UserEvent.CurrentlyActive, this.onUserPresenceChange);
|
2022-11-18 20:05:00 +01:00
|
|
|
cli.on(ClientEvent.Room, this.onRoom); // invites & joining after peek
|
|
|
|
cli.on(RoomEvent.MyMembership, this.onMyMembership);
|
|
|
|
}
|
|
|
|
|
2022-12-16 13:29:59 +01:00
|
|
|
public componentDidMount(): void {
|
2022-11-18 20:05:00 +01:00
|
|
|
this.updateListNow(true);
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2018-08-29 11:09:55 +02:00
|
|
|
|
2023-01-12 14:25:14 +01:00
|
|
|
public componentWillUnmount(): void {
|
2021-06-23 13:45:55 +02:00
|
|
|
this.mounted = false;
|
2017-10-11 18:56:17 +02:00
|
|
|
const cli = MatrixClientPeg.get();
|
2016-04-18 02:35:40 +02:00
|
|
|
if (cli) {
|
2022-02-24 15:39:25 +01:00
|
|
|
cli.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate);
|
2022-02-22 13:18:08 +01:00
|
|
|
cli.removeListener(RoomMemberEvent.Name, this.onRoomMemberName);
|
|
|
|
cli.removeListener(RoomEvent.MyMembership, this.onMyMembership);
|
|
|
|
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvent);
|
|
|
|
cli.removeListener(ClientEvent.Room, this.onRoom);
|
|
|
|
cli.removeListener(UserEvent.LastPresenceTs, this.onUserPresenceChange);
|
|
|
|
cli.removeListener(UserEvent.Presence, this.onUserPresenceChange);
|
|
|
|
cli.removeListener(UserEvent.CurrentlyActive, this.onUserPresenceChange);
|
2015-06-22 12:42:09 +02:00
|
|
|
}
|
2016-08-10 14:39:47 +02:00
|
|
|
|
|
|
|
// cancel any pending calls to the rate_limited_funcs
|
2021-07-01 19:35:38 +02:00
|
|
|
this.updateList.cancel();
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2015-06-22 12:42:09 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private get canInvite(): boolean {
|
2023-06-15 09:46:19 +02:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
2021-05-19 14:16:10 +02:00
|
|
|
const room = cli.getRoom(this.props.roomId);
|
2021-09-29 15:04:02 +02:00
|
|
|
|
2023-11-21 02:43:32 +01:00
|
|
|
return !!room && canInviteTo(room);
|
2021-05-19 14:16:10 +02:00
|
|
|
}
|
|
|
|
|
2022-11-18 20:05:00 +01:00
|
|
|
private getMembersState(invitedMembers: Array<RoomMember>, joinedMembers: Array<RoomMember>): IState {
|
2018-09-03 11:13:56 +02:00
|
|
|
return {
|
|
|
|
loading: false,
|
2022-11-18 20:05:00 +01:00
|
|
|
filteredJoinedMembers: joinedMembers,
|
|
|
|
filteredInvitedMembers: invitedMembers,
|
2021-05-19 14:16:10 +02:00
|
|
|
canInvite: this.canInvite,
|
2018-09-03 11:13:56 +02: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,
|
|
|
|
};
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2018-09-03 11:13:56 +02:00
|
|
|
|
2023-05-12 10:49:37 +02:00
|
|
|
private onUserPresenceChange = (event: MatrixEvent | undefined, user: User): void => {
|
2015-09-18 19:39:16 +02: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-20 22:56:18 +01:00
|
|
|
// ever attaching their own listener.
|
2023-11-07 11:14:30 +01:00
|
|
|
const tile = this.tiles.get(user.userId);
|
2016-04-18 02:35:40 +02:00
|
|
|
if (tile) {
|
2021-06-23 13:45:55 +02:00
|
|
|
this.updateList(); // reorder the membership list
|
2015-09-18 19:39:16 +02:00
|
|
|
}
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2016-01-20 15:41:48 +01:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private onRoom = (room: Room): void => {
|
2015-09-18 19:39:16 +02: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.
|
2022-11-18 20:05:00 +01:00
|
|
|
this.updateListNow(true);
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2018-09-13 18:43:24 +02:00
|
|
|
|
2023-05-12 10:49:37 +02:00
|
|
|
private onMyMembership = (room: Room, membership: string, oldMembership?: string): void => {
|
2022-11-18 20:05:00 +01:00
|
|
|
if (room.roomId === this.props.roomId && membership === "join" && oldMembership !== "join") {
|
|
|
|
// we just joined the room, load the member list
|
|
|
|
this.updateListNow(true);
|
2018-09-13 18:43:24 +02:00
|
|
|
}
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2015-09-18 19:39:16 +02:00
|
|
|
|
2022-02-24 15:39:25 +01:00
|
|
|
private onRoomStateUpdate = (state: RoomState): void => {
|
|
|
|
if (state.roomId !== this.props.roomId) return;
|
2021-06-23 13:45:55 +02:00
|
|
|
this.updateList();
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2015-09-18 19:39:16 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private onRoomMemberName = (ev: MatrixEvent, member: RoomMember): void => {
|
2018-09-07 14:05:26 +02:00
|
|
|
if (member.roomId !== this.props.roomId) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-23 13:45:55 +02:00
|
|
|
this.updateList();
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2015-10-28 16:15:35 +01:00
|
|
|
|
2022-02-24 15:39:25 +01:00
|
|
|
private onRoomStateEvent = (event: MatrixEvent): void => {
|
|
|
|
if (event.getRoomId() === this.props.roomId && event.getType() === EventType.RoomThirdPartyInvite) {
|
2021-06-23 13:45:55 +02:00
|
|
|
this.updateList();
|
2016-01-22 16:11:36 +01:00
|
|
|
}
|
2021-05-19 11:01:04 +02:00
|
|
|
|
2021-05-19 14:16:10 +02:00
|
|
|
if (this.canInvite !== this.state.canInvite) this.setState({ canInvite: this.canInvite });
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2016-01-22 16:11:36 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
private updateList = throttle(
|
|
|
|
() => {
|
|
|
|
this.updateListNow(false);
|
|
|
|
},
|
|
|
|
500,
|
|
|
|
{ leading: true, trailing: true },
|
|
|
|
);
|
2019-01-04 05:55:52 +01:00
|
|
|
|
2023-02-13 12:39:16 +01:00
|
|
|
// XXX: exported for tests
|
|
|
|
public async updateListNow(showLoadingSpinner?: boolean): Promise<void> {
|
2022-11-18 20:05:00 +01:00
|
|
|
if (!this.mounted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (showLoadingSpinner) {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
}
|
|
|
|
const { joined, invited } = await this.context.memberListStore.loadMemberList(
|
2022-12-12 12:24:14 +01:00
|
|
|
this.props.roomId,
|
|
|
|
this.props.searchQuery,
|
2022-11-18 20:05:00 +01:00
|
|
|
);
|
|
|
|
if (!this.mounted) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-23 13:45:55 +02:00
|
|
|
this.setState({
|
2018-09-13 18:43:24 +02:00
|
|
|
loading: false,
|
2022-11-18 20:05:00 +01:00
|
|
|
filteredJoinedMembers: joined,
|
|
|
|
filteredInvitedMembers: invited,
|
2021-06-23 13:45:55 +02:00
|
|
|
});
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2015-06-24 14:48:39 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private createOverflowTileJoined = (overflowCount: number, totalCount: number): JSX.Element => {
|
|
|
|
return this.createOverflowTile(overflowCount, totalCount, this.showMoreJoinedMemberList);
|
2020-09-04 10:24:12 +02:00
|
|
|
};
|
2017-09-22 17:50:54 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private createOverflowTileInvited = (overflowCount: number, totalCount: number): JSX.Element => {
|
|
|
|
return this.createOverflowTile(overflowCount, totalCount, this.showMoreInvitedMemberList);
|
2020-09-04 10:24:12 +02:00
|
|
|
};
|
2017-09-22 17:50:54 +02:00
|
|
|
|
2022-01-10 13:57:20 +01:00
|
|
|
private createOverflowTile = (overflowCount: number, totalCount: number, onClick: () => void): JSX.Element => {
|
2016-01-21 12:41:28 +01:00
|
|
|
// For now we'll pretend this is any entity. It should probably be a separate tile.
|
2023-10-03 20:17:26 +02:00
|
|
|
const text = _t("common|and_n_others", { count: overflowCount });
|
2016-01-21 12:41:28 +01:00
|
|
|
return (
|
2021-07-23 11:23:45 +02:00
|
|
|
<EntityTile
|
|
|
|
className="mx_EntityTile_ellipsis"
|
|
|
|
avatarJsx={
|
2023-08-24 05:48:35 +02:00
|
|
|
<BaseAvatar url={require("../../../../res/img/ellipsis.svg").default} name="..." size="36px" />
|
2021-07-23 11:23:45 +02:00
|
|
|
}
|
|
|
|
name={text}
|
2023-11-07 11:14:30 +01:00
|
|
|
showPresence={false}
|
2021-07-23 11:23:45 +02:00
|
|
|
onClick={onClick}
|
|
|
|
/>
|
2016-01-21 12:41:28 +01:00
|
|
|
);
|
2020-09-04 10:24:12 +02:00
|
|
|
};
|
2015-11-30 16:13:28 +01:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private showMoreJoinedMemberList = (): void => {
|
2017-09-22 17:50:54 +02:00
|
|
|
this.setState({
|
2017-09-22 18:01:14 +02:00
|
|
|
truncateAtJoined: this.state.truncateAtJoined + SHOW_MORE_INCREMENT,
|
2017-09-22 17:50:54 +02:00
|
|
|
});
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2017-09-22 17:50:54 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private showMoreInvitedMemberList = (): void => {
|
2016-01-21 16:57:59 +01:00
|
|
|
this.setState({
|
2017-09-22 18:01:14 +02:00
|
|
|
truncateAtInvited: this.state.truncateAtInvited + SHOW_MORE_INCREMENT,
|
2016-01-21 16:57:59 +01:00
|
|
|
});
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2015-11-30 16:13:28 +01:00
|
|
|
|
2022-11-18 20:05:00 +01:00
|
|
|
public componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>, snapshot?: any): void {
|
|
|
|
if (prevProps.searchQuery !== this.props.searchQuery) {
|
|
|
|
this.updateListNow(false);
|
2018-12-20 22:56:18 +01:00
|
|
|
}
|
2022-11-18 20:05:00 +01:00
|
|
|
}
|
2015-11-30 16:13:28 +01:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private onSearchQueryChanged = (searchQuery: string): void => {
|
2021-11-08 10:57:14 +01:00
|
|
|
this.props.onSearchQueryChanged(searchQuery);
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2016-01-19 15:51:26 +01:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private onPending3pidInviteClick = (inviteEvent: MatrixEvent): void => {
|
2019-03-29 03:38:15 +01:00
|
|
|
dis.dispatch({
|
2022-12-12 12:24:14 +01:00
|
|
|
action: "view_3pid_invite",
|
2019-03-29 03:38:15 +01:00
|
|
|
event: inviteEvent,
|
|
|
|
});
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
2019-03-29 03:38:15 +01:00
|
|
|
|
2023-04-04 12:41:46 +02:00
|
|
|
private getPending3PidInvites(): MatrixEvent[] {
|
2018-01-25 13:18:02 +01: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)
|
2023-06-15 09:46:19 +02:00
|
|
|
const room = MatrixClientPeg.safeGet().getRoom(this.props.roomId);
|
2018-01-25 13:18:02 +01:00
|
|
|
|
|
|
|
if (room) {
|
2022-12-12 12:24:14 +01:00
|
|
|
return room.currentState.getStateEvents("m.room.third_party_invite").filter(function (e) {
|
2019-03-29 18:45:07 +01:00
|
|
|
if (!isValid3pidInvite(e)) return false;
|
2018-01-25 13:18:02 +01:00
|
|
|
|
|
|
|
// discard all invites which have a m.room.member event since we've
|
|
|
|
// already added them.
|
2023-04-04 12:41:46 +02:00
|
|
|
const memberEvent = room.currentState.getInviteForThreePidToken(e.getStateKey()!);
|
2018-01-25 13:18:02 +01:00
|
|
|
if (memberEvent) return false;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2023-04-04 12:41:46 +02:00
|
|
|
|
|
|
|
return [];
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2018-01-25 13:18:02 +01:00
|
|
|
|
2023-01-12 14:25:14 +01:00
|
|
|
private makeMemberTiles(members: Array<RoomMember | MatrixEvent>): JSX.Element[] {
|
2019-07-03 09:38:08 +02:00
|
|
|
return members.map((m) => {
|
2021-06-23 13:45:55 +02:00
|
|
|
if (m instanceof RoomMember) {
|
2019-07-03 09:38:08 +02:00
|
|
|
// Is a Matrix invite
|
2023-11-07 11:14:30 +01:00
|
|
|
return (
|
|
|
|
<MemberTile
|
|
|
|
key={m.userId}
|
|
|
|
member={m}
|
|
|
|
ref={(tile) => {
|
|
|
|
if (tile) this.tiles.set(m.userId, tile);
|
|
|
|
else this.tiles.delete(m.userId);
|
|
|
|
}}
|
|
|
|
showPresence={this.showPresence}
|
|
|
|
/>
|
|
|
|
);
|
2019-07-03 09:38:08 +02:00
|
|
|
} else {
|
|
|
|
// Is a 3pid invite
|
2022-12-12 12:24:14 +01:00
|
|
|
return (
|
|
|
|
<EntityTile
|
|
|
|
key={m.getStateKey()}
|
|
|
|
name={m.getContent().display_name}
|
2023-11-07 11:14:30 +01:00
|
|
|
showPresence={false}
|
2022-12-12 12:24:14 +01:00
|
|
|
onClick={() => this.onPending3pidInviteClick(m)}
|
|
|
|
/>
|
|
|
|
);
|
2019-07-03 09:38:08 +02:00
|
|
|
}
|
2015-11-30 16:13:28 +01:00
|
|
|
});
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2015-11-30 16:13:28 +01:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private getChildrenJoined = (start: number, end: number): Array<JSX.Element> => {
|
2021-06-29 14:11:58 +02:00
|
|
|
return this.makeMemberTiles(this.state.filteredJoinedMembers.slice(start, end));
|
2021-06-23 13:45:55 +02:00
|
|
|
};
|
2017-09-22 14:15:02 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private getChildCountJoined = (): number => this.state.filteredJoinedMembers.length;
|
2017-09-22 14:15:02 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private getChildrenInvited = (start: number, end: number): Array<JSX.Element> => {
|
2019-07-03 09:38:08 +02:00
|
|
|
let targets = this.state.filteredInvitedMembers;
|
|
|
|
if (end > this.state.filteredInvitedMembers.length) {
|
2021-06-23 13:45:55 +02:00
|
|
|
targets = targets.concat(this.getPending3PidInvites());
|
2019-07-03 09:38:08 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
return this.makeMemberTiles(targets.slice(start, end));
|
2020-08-29 13:51:37 +02:00
|
|
|
};
|
2017-09-22 17:50:54 +02:00
|
|
|
|
2021-06-23 13:45:55 +02:00
|
|
|
private getChildCountInvited = (): number => {
|
|
|
|
return this.state.filteredInvitedMembers.length + (this.getPending3PidInvites() || []).length;
|
2021-06-29 14:11:58 +02:00
|
|
|
};
|
2017-09-22 17:50:54 +02:00
|
|
|
|
2023-02-13 18:01:43 +01:00
|
|
|
public render(): React.ReactNode {
|
2018-08-29 10:30:25 +02:00
|
|
|
if (this.state.loading) {
|
2022-12-12 12:24:14 +01:00
|
|
|
return (
|
|
|
|
<BaseCard className="mx_MemberList" onClose={this.props.onClose}>
|
|
|
|
<Spinner />
|
|
|
|
</BaseCard>
|
|
|
|
);
|
2018-08-29 10:30:25 +02:00
|
|
|
}
|
|
|
|
|
2023-06-15 09:46:19 +02:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
2018-10-24 13:50:58 +02:00
|
|
|
const room = cli.getRoom(this.props.roomId);
|
2023-05-12 12:25:16 +02:00
|
|
|
let inviteButton: JSX.Element | undefined;
|
2019-05-11 20:45:24 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
if (room?.getMyMembership() === "join" && shouldShowComponent(UIComponent.InviteUsers)) {
|
2023-11-21 02:43:32 +01:00
|
|
|
const inviteButtonText = room.isSpaceRoom() ? _t("space|invite_this_space") : _t("room|invite_this_room");
|
|
|
|
|
|
|
|
const button = (
|
|
|
|
<Button
|
|
|
|
size="sm"
|
|
|
|
kind="secondary"
|
|
|
|
className="mx_MemberList_invite"
|
|
|
|
onClick={this.onInviteButtonClick}
|
|
|
|
disabled={!this.state.canInvite}
|
|
|
|
>
|
|
|
|
<UserAddIcon width="1em" height="1em" />
|
|
|
|
{inviteButtonText}
|
|
|
|
</Button>
|
|
|
|
);
|
2020-08-31 18:12:12 +02:00
|
|
|
|
2023-05-12 12:25:16 +02:00
|
|
|
if (this.state.canInvite) {
|
2023-11-21 02:43:32 +01:00
|
|
|
inviteButton = button;
|
2023-05-12 12:25:16 +02:00
|
|
|
} else {
|
2023-11-21 02:43:32 +01:00
|
|
|
inviteButton = <Tooltip label={_t("member_list|invite_button_no_perms_tooltip")}>{button}</Tooltip>;
|
2023-05-12 12:25:16 +02:00
|
|
|
}
|
2018-10-24 13:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let invitedHeader;
|
|
|
|
let invitedSection;
|
2021-06-23 13:45:55 +02:00
|
|
|
if (this.getChildCountInvited() > 0) {
|
2023-09-27 18:15:22 +02:00
|
|
|
invitedHeader = <h2>{_t("member_list|invited_list_heading")}</h2>;
|
2021-06-23 13:45:55 +02: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 16:13:28 +01:00
|
|
|
}
|
2016-02-08 16:05:35 +01:00
|
|
|
|
2020-09-08 11:19:51 +02:00
|
|
|
const footer = (
|
|
|
|
<SearchBox
|
|
|
|
className="mx_MemberList_query mx_textinput_icon mx_textinput_search"
|
2023-09-27 18:15:22 +02:00
|
|
|
placeholder={_t("member_list|filter_placeholder")}
|
2021-08-19 15:48:14 +02:00
|
|
|
onSearch={this.onSearchQueryChanged}
|
2021-11-08 10:57:14 +01:00
|
|
|
initialValue={this.props.searchQuery}
|
2021-08-19 15:48:14 +02:00
|
|
|
/>
|
2015-11-30 16:13:28 +01:00
|
|
|
);
|
2020-09-08 11:19:51 +02:00
|
|
|
|
2021-03-02 10:51:11 +01:00
|
|
|
let scopeHeader;
|
2022-03-23 00:07:37 +01:00
|
|
|
if (room?.isSpaceRoom()) {
|
2022-12-12 12:24:14 +01:00
|
|
|
scopeHeader = (
|
|
|
|
<div className="mx_RightPanel_scopeHeader">
|
2023-08-24 05:48:35 +02:00
|
|
|
<RoomAvatar room={room} size="32px" />
|
2022-12-12 12:24:14 +01:00
|
|
|
<RoomName room={room} />
|
|
|
|
</div>
|
|
|
|
);
|
2021-03-02 10:51:11 +01:00
|
|
|
}
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
return (
|
|
|
|
<BaseCard
|
|
|
|
className="mx_MemberList"
|
2023-10-20 15:30:37 +02:00
|
|
|
header={<React.Fragment>{scopeHeader}</React.Fragment>}
|
2022-12-12 12:24:14 +01:00
|
|
|
footer={footer}
|
|
|
|
onClose={this.props.onClose}
|
|
|
|
>
|
2023-10-20 15:30:37 +02:00
|
|
|
{inviteButton}
|
2022-12-12 12:24:14 +01:00
|
|
|
<div className="mx_MemberList_wrapper">
|
|
|
|
<TruncatedList
|
|
|
|
className="mx_MemberList_section mx_MemberList_joined"
|
|
|
|
truncateAt={this.state.truncateAtJoined}
|
|
|
|
createOverflowElement={this.createOverflowTileJoined}
|
|
|
|
getChildren={this.getChildrenJoined}
|
|
|
|
getChildCount={this.getChildCountJoined}
|
|
|
|
/>
|
|
|
|
{invitedHeader}
|
|
|
|
{invitedSection}
|
|
|
|
</div>
|
|
|
|
</BaseCard>
|
|
|
|
);
|
2020-08-29 13:14:16 +02:00
|
|
|
}
|
2018-10-24 13:50:58 +02:00
|
|
|
|
2022-02-09 15:42:08 +01:00
|
|
|
private onInviteButtonClick = (ev: ButtonEvent): void => {
|
|
|
|
PosthogTrackers.trackInteraction("WebRightPanelMemberListInviteButton", ev);
|
|
|
|
|
2023-11-21 02:43:32 +01:00
|
|
|
const cli = MatrixClientPeg.safeGet();
|
|
|
|
const room = cli.getRoom(this.props.roomId)!;
|
2018-10-24 13:50:58 +02:00
|
|
|
|
2023-11-21 02:43:32 +01:00
|
|
|
inviteToRoom(room);
|
2020-08-29 13:14:16 +02:00
|
|
|
};
|
|
|
|
}
|