fix(app): invite member & presence counts (#59)

This commit is contained in:
hampus-fluxer 2026-01-06 06:28:27 +01:00 committed by GitHub
parent e6ef9150b9
commit 915959a021
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 74 additions and 18 deletions

View File

@ -42,7 +42,6 @@ import {Tooltip} from '~/components/uikit/Tooltip/Tooltip';
import {ComponentDispatch} from '~/lib/ComponentDispatch';
import {Routes} from '~/Routes';
import {UserRecord} from '~/records/UserRecord';
import ChannelStore from '~/stores/ChannelStore';
import GuildMemberStore from '~/stores/GuildMemberStore';
import GuildStore from '~/stores/GuildStore';
import InviteStore from '~/stores/InviteStore';
@ -51,6 +50,7 @@ import UserStore from '~/stores/UserStore';
import {isGroupDmInvite, isGuildInvite, isPackInvite as isPackInviteGuard} from '~/types/InviteTypes';
import * as AvatarUtils from '~/utils/AvatarUtils';
import {getGroupDmInviteCounts} from '~/utils/invite/GroupDmInviteCounts';
import {
GuildInvitePrimaryAction,
getGuildInviteActionState,
@ -58,7 +58,6 @@ import {
isGuildInviteActionDisabled,
} from '~/utils/invite/GuildInviteActionState';
import * as RouterUtils from '~/utils/RouterUtils';
import {getGroupDMTitle, getGuildEmbedSplashAspectRatio, getImageAspectRatioFromBase64} from './InviteEmbed/utils';
import styles from './InviteEmbed.module.css';
@ -146,8 +145,12 @@ export const InviteEmbed = observer(function InviteEmbed({code}: InviteEmbedProp
const groupDMPath = Routes.dmChannel(invite.channel.id);
const handleAcceptInvite = () => InviteActionCreators.acceptAndTransitionToChannel(invite.code, i18n);
const handleNavigateToGroup = () => RouterUtils.transitionTo(groupDMPath);
const isAlreadyInGroupDM = !!ChannelStore.getChannel(invite.channel.id);
const memberCount = invite.member_count ?? 0;
const groupDMCounts = getGroupDmInviteCounts({
channelId: invite.channel.id,
inviteMemberCount: invite.member_count,
});
const isAlreadyInGroupDM = groupDMCounts.hasLocalChannel;
const memberCount = groupDMCounts.memberCount;
return (
<EmbedCard

View File

@ -32,6 +32,7 @@ import foodPatternUrl from '~/images/i-like-food.svg';
import InviteStore from '~/stores/InviteStore';
import {isGroupDmInvite, isGuildInvite, isPackInvite as isPackInviteGuard} from '~/types/InviteTypes';
import * as AvatarUtils from '~/utils/AvatarUtils';
import {getGroupDmInviteCounts} from '~/utils/invite/GroupDmInviteCounts';
import {
GuildInvitePrimaryAction,
getGuildInviteActionState,
@ -57,6 +58,13 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code}: Inv
}, [code, inviteState]);
const isGroupDM = invite != null && isGroupDmInvite(invite);
const groupDMCounts =
invite && isGroupDM
? getGroupDmInviteCounts({
channelId: invite.channel.id,
inviteMemberCount: invite.member_count,
})
: null;
const isPackInvite = invite != null && isPackInviteGuard(invite);
const guildActionState = getGuildInviteActionState({invite});
@ -64,12 +72,18 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code}: Inv
const inviteForHeader = React.useMemo(() => {
if (!invite) return null;
if (isGroupDM && groupDMCounts) {
return {
...invite,
member_count: groupDMCounts.memberCount,
};
}
return {
...invite,
presence_count: presenceCount,
member_count: memberCount,
};
}, [invite, presenceCount, memberCount]);
}, [invite, isGroupDM, presenceCount, memberCount, groupDMCounts?.memberCount]);
const splashUrl = React.useMemo(() => {
if (!invite || !isGuildInvite(invite)) {

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import AuthenticationStore from '~/stores/AuthenticationStore';
import ChannelStore from '~/stores/ChannelStore';
export interface GroupDmInviteCounts {
memberCount: number;
hasLocalChannel: boolean;
}
export const getGroupDmInviteCounts = (params: {
channelId: string;
inviteMemberCount?: number | null;
}): GroupDmInviteCounts => {
const channel = ChannelStore.getChannel(params.channelId);
if (!channel) {
return {
memberCount: params.inviteMemberCount ?? 0,
hasLocalChannel: false,
};
}
const memberIds = new Set(channel.recipientIds);
const currentUserId = AuthenticationStore.currentUserId;
if (currentUserId) {
memberIds.add(currentUserId);
}
return {
memberCount: memberIds.size,
hasLocalChannel: true,
};
};

View File

@ -22,7 +22,6 @@ import type {Guild, GuildRecord} from '~/records/GuildRecord';
import type {Invite} from '~/records/MessageRecord';
import AuthenticationStore from '~/stores/AuthenticationStore';
import GuildMemberStore from '~/stores/GuildMemberStore';
import PresenceStore from '~/stores/PresenceStore';
import {isGuildInvite} from '~/types/InviteTypes';
const normalizeFeatures = (features?: Iterable<string> | null): Array<string> => {
@ -55,18 +54,8 @@ export const getGuildInviteActionState = (params: {
const guildId = guildRecord?.id ?? null;
const currentUserId = AuthenticationStore.currentUserId;
const isMember = Boolean(guildId && currentUserId && GuildMemberStore.getMember(guildId, currentUserId));
const presenceCount =
guildId && isMember
? PresenceStore.getPresenceCount(guildId)
: params.invite && isGuildInvite(params.invite)
? params.invite.presence_count
: 0;
const memberCount =
guildId && isMember
? GuildMemberStore.getMemberCount(guildId)
: params.invite && isGuildInvite(params.invite)
? params.invite.member_count
: 0;
const presenceCount = params.invite && isGuildInvite(params.invite) ? (params.invite.presence_count ?? 0) : 0;
const memberCount = params.invite && isGuildInvite(params.invite) ? (params.invite.member_count ?? 0) : 0;
const features = normalizeFeatures(guildRecord?.features ?? inviteGuild?.features);
return {