2021-03-25 19:15:34 +03:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2021-03-26 14:55:22 +03:00
|
|
|
import { sortBy } from "lodash";
|
2021-03-25 19:15:34 +03:00
|
|
|
|
|
|
|
import MemberAvatar from "../avatars/MemberAvatar";
|
|
|
|
import { _t } from "../../../languageHandler";
|
|
|
|
import DMRoomMap from "../../../utils/DMRoomMap";
|
2021-03-26 03:05:05 +03:00
|
|
|
import TextWithTooltip from "../elements/TextWithTooltip";
|
2021-03-25 19:15:34 +03:00
|
|
|
|
|
|
|
const DEFAULT_NUM_FACES = 5;
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
room: Room;
|
|
|
|
numShown?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FacePile = ({ room, numShown = DEFAULT_NUM_FACES }: IProps) => {
|
2021-03-26 14:55:22 +03:00
|
|
|
const knownMembers = sortBy(room.getJoinedMembers().filter(member => {
|
2021-03-25 19:15:34 +03:00
|
|
|
return !!DMRoomMap.shared().getDMRoomsForUserId(member.userId)?.length;
|
2021-03-26 14:55:22 +03:00
|
|
|
}), member => member.getMxcAvatarUrl() ? 0 : 1); // sort users with an explicit avatar first
|
2021-03-25 19:15:34 +03:00
|
|
|
|
|
|
|
if (knownMembers.length < 1) return null;
|
|
|
|
const shownMembers = knownMembers.slice(0, numShown);
|
|
|
|
|
|
|
|
return <div className="mx_FacePile">
|
|
|
|
<div className="mx_FacePile_faces">
|
2021-03-26 03:05:05 +03:00
|
|
|
{ shownMembers.map(member => {
|
|
|
|
return <TextWithTooltip key={member.userId} tooltip={member.name}>
|
|
|
|
<MemberAvatar member={member} width={28} height={28} />
|
|
|
|
</TextWithTooltip>;
|
|
|
|
}) }
|
2021-03-25 19:15:34 +03:00
|
|
|
</div>
|
|
|
|
<span>
|
|
|
|
{ _t("%(count)s people you know have already joined", { count: knownMembers.length }) }
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FacePile;
|