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

This commit is contained in:
Michael Telatynski 2021-10-19 16:17:09 +01:00 committed by GitHub
parent 974f45930c
commit 9becc392dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View file

@ -511,10 +511,11 @@ $SpaceRoomViewInnerWidth: 428px;
mask-image: url("$(res)/img/element-icons/lock.svg"); mask-image: url("$(res)/img/element-icons/lock.svg");
} }
.mx_AccessibleButton_kind_link { .mx_SpaceRoomView_info_memberCount {
color: inherit; color: inherit;
position: relative; position: relative;
padding-left: 16px; padding: 0 0 0 16px;
font-size: $font-15px;
&::before { &::before {
content: "·"; // visual separator content: "·"; // visual separator

View file

@ -127,8 +127,17 @@ const useMyRoomMembership = (room: Room) => {
return membership; 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 joinRule = useRoomState(space, state => state.getJoinRule());
const membership = useMyRoomMembership(space);
let visibilitySection; let visibilitySection;
if (joinRule === "public") { if (joinRule === "public") {
@ -141,12 +150,18 @@ const SpaceInfo = ({ space }) => {
</span>; </span>;
} }
return <div className="mx_SpaceRoomView_info"> let memberSection;
{ visibilitySection } if (membership === "invite" && summary) {
{ joinRule === "public" && <RoomMemberCount room={space}> // 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 ? ( { (count) => count > 0 ? (
<AccessibleButton <AccessibleButton
kind="link" kind="link"
className="mx_SpaceRoomView_info_memberCount"
onClick={() => { onClick={() => {
defaultDispatcher.dispatch<SetRightPanelPhasePayload>({ defaultDispatcher.dispatch<SetRightPanelPhasePayload>({
action: Action.SetRightPanelPhase, action: Action.SetRightPanelPhase,
@ -158,7 +173,12 @@ const SpaceInfo = ({ space }) => {
{ _t("%(count)s members", { count }) } { _t("%(count)s members", { count }) }
</AccessibleButton> </AccessibleButton>
) : null } ) : null }
</RoomMemberCount> } </RoomMemberCount>;
}
return <div className="mx_SpaceRoomView_info">
{ visibilitySection }
{ memberSection }
</div>; </div>;
}; };