element-web/src/components/views/elements/FacePile.tsx

56 lines
1.9 KiB
TypeScript
Raw Normal View History

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";
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";
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) => {
const knownMembers = sortBy(room.getJoinedMembers().filter(member => {
2021-03-25 19:15:34 +03:00
return !!DMRoomMap.shared().getDMRoomsForUserId(member.userId)?.length;
}), 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">
{ 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;