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

Commit 9becc39

Browse files
authored
For space invite previews, use room summary API to get the right member count (#6982)
1 parent 974f459 commit 9becc39

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

Diff for: res/css/structures/_SpaceRoomView.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,11 @@ $SpaceRoomViewInnerWidth: 428px;
511511
mask-image: url("$(res)/img/element-icons/lock.svg");
512512
}
513513

514-
.mx_AccessibleButton_kind_link {
514+
.mx_SpaceRoomView_info_memberCount {
515515
color: inherit;
516516
position: relative;
517-
padding-left: 16px;
517+
padding: 0 0 0 16px;
518+
font-size: $font-15px;
518519

519520
&::before {
520521
content: "·"; // visual separator

Diff for: src/components/structures/SpaceRoomView.tsx

+25-5
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,17 @@ const useMyRoomMembership = (room: Room) => {
127127
return membership;
128128
};
129129

130-
const SpaceInfo = ({ space }) => {
130+
const SpaceInfo = ({ space }: { space: Room }) => {
131+
const summary = useAsyncMemo(() => {
132+
if (space.getMyMembership() !== "invite") return;
133+
try {
134+
return space.client.getRoomSummary(space.roomId);
135+
} catch (e) {
136+
return null;
137+
}
138+
}, [space]);
131139
const joinRule = useRoomState(space, state => state.getJoinRule());
140+
const membership = useMyRoomMembership(space);
132141

133142
let visibilitySection;
134143
if (joinRule === "public") {
@@ -141,12 +150,18 @@ const SpaceInfo = ({ space }) => {
141150
</span>;
142151
}
143152

144-
return <div className="mx_SpaceRoomView_info">
145-
{ visibilitySection }
146-
{ joinRule === "public" && <RoomMemberCount room={space}>
153+
let memberSection;
154+
if (membership === "invite" && summary) {
155+
// Don't trust local state and instead use the summary API
156+
memberSection = <span className="mx_SpaceRoomView_info_memberCount">
157+
{ _t("%(count)s members", { count: summary.num_joined_members }) }
158+
</span>;
159+
} else if (summary === null) {
160+
memberSection = <RoomMemberCount room={space}>
147161
{ (count) => count > 0 ? (
148162
<AccessibleButton
149163
kind="link"
164+
className="mx_SpaceRoomView_info_memberCount"
150165
onClick={() => {
151166
defaultDispatcher.dispatch<SetRightPanelPhasePayload>({
152167
action: Action.SetRightPanelPhase,
@@ -158,7 +173,12 @@ const SpaceInfo = ({ space }) => {
158173
{ _t("%(count)s members", { count }) }
159174
</AccessibleButton>
160175
) : null }
161-
</RoomMemberCount> }
176+
</RoomMemberCount>;
177+
}
178+
179+
return <div className="mx_SpaceRoomView_info">
180+
{ visibilitySection }
181+
{ memberSection }
162182
</div>;
163183
};
164184

0 commit comments

Comments
 (0)