Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

For space invite previews, use room summary API to get the right member count #6982

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions res/css/structures/_SpaceRoomView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,11 @@ $SpaceRoomViewInnerWidth: 428px;
mask-image: url("$(res)/img/element-icons/lock.svg");
}

.mx_AccessibleButton_kind_link {
.mx_SpaceRoomView_info_memberCount {
color: inherit;
position: relative;
padding-left: 16px;
padding: 0 0 0 16px;
font-size: $font-15px;

&::before {
content: "·"; // visual separator
Expand Down
30 changes: 25 additions & 5 deletions src/components/structures/SpaceRoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ const useMyRoomMembership = (room: Room) => {
return membership;
};

const SpaceInfo = ({ space }) => {
const SpaceInfo = ({ space }: { space: Room }) => {
const summary = useAsyncMemo(() => {
if (space.getMyMembership() !== "invite") return;
try {
return space.client.getRoomSummary(space.roomId);
} catch (e) {
return null;
}
}, [space]);
const joinRule = useRoomState(space, state => state.getJoinRule());
const membership = useMyRoomMembership(space);

let visibilitySection;
if (joinRule === "public") {
Expand All @@ -141,12 +150,18 @@ const SpaceInfo = ({ space }) => {
</span>;
}

return <div className="mx_SpaceRoomView_info">
{ visibilitySection }
{ joinRule === "public" && <RoomMemberCount room={space}>
let memberSection;
if (membership === "invite" && summary) {
// Don't trust local state and instead use the summary API
memberSection = <span className="mx_SpaceRoomView_info_memberCount">
{ _t("%(count)s members", { count: summary.num_joined_members }) }
</span>;
} else if (summary === null) {
memberSection = <RoomMemberCount room={space}>
{ (count) => count > 0 ? (
<AccessibleButton
kind="link"
className="mx_SpaceRoomView_info_memberCount"
onClick={() => {
defaultDispatcher.dispatch<SetRightPanelPhasePayload>({
action: Action.SetRightPanelPhase,
Expand All @@ -158,7 +173,12 @@ const SpaceInfo = ({ space }) => {
{ _t("%(count)s members", { count }) }
</AccessibleButton>
) : null }
</RoomMemberCount> }
</RoomMemberCount>;
}

return <div className="mx_SpaceRoomView_info">
{ visibilitySection }
{ memberSection }
</div>;
};

Expand Down