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
4 changed files with 74 additions and 18 deletions

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 {