fix(app): invite member & presence counts (#59)
This commit is contained in:
parent
e6ef9150b9
commit
915959a021
@ -42,7 +42,6 @@ import {Tooltip} from '~/components/uikit/Tooltip/Tooltip';
|
|||||||
import {ComponentDispatch} from '~/lib/ComponentDispatch';
|
import {ComponentDispatch} from '~/lib/ComponentDispatch';
|
||||||
import {Routes} from '~/Routes';
|
import {Routes} from '~/Routes';
|
||||||
import {UserRecord} from '~/records/UserRecord';
|
import {UserRecord} from '~/records/UserRecord';
|
||||||
import ChannelStore from '~/stores/ChannelStore';
|
|
||||||
import GuildMemberStore from '~/stores/GuildMemberStore';
|
import GuildMemberStore from '~/stores/GuildMemberStore';
|
||||||
import GuildStore from '~/stores/GuildStore';
|
import GuildStore from '~/stores/GuildStore';
|
||||||
import InviteStore from '~/stores/InviteStore';
|
import InviteStore from '~/stores/InviteStore';
|
||||||
@ -51,6 +50,7 @@ import UserStore from '~/stores/UserStore';
|
|||||||
|
|
||||||
import {isGroupDmInvite, isGuildInvite, isPackInvite as isPackInviteGuard} from '~/types/InviteTypes';
|
import {isGroupDmInvite, isGuildInvite, isPackInvite as isPackInviteGuard} from '~/types/InviteTypes';
|
||||||
import * as AvatarUtils from '~/utils/AvatarUtils';
|
import * as AvatarUtils from '~/utils/AvatarUtils';
|
||||||
|
import {getGroupDmInviteCounts} from '~/utils/invite/GroupDmInviteCounts';
|
||||||
import {
|
import {
|
||||||
GuildInvitePrimaryAction,
|
GuildInvitePrimaryAction,
|
||||||
getGuildInviteActionState,
|
getGuildInviteActionState,
|
||||||
@ -58,7 +58,6 @@ import {
|
|||||||
isGuildInviteActionDisabled,
|
isGuildInviteActionDisabled,
|
||||||
} from '~/utils/invite/GuildInviteActionState';
|
} from '~/utils/invite/GuildInviteActionState';
|
||||||
import * as RouterUtils from '~/utils/RouterUtils';
|
import * as RouterUtils from '~/utils/RouterUtils';
|
||||||
|
|
||||||
import {getGroupDMTitle, getGuildEmbedSplashAspectRatio, getImageAspectRatioFromBase64} from './InviteEmbed/utils';
|
import {getGroupDMTitle, getGuildEmbedSplashAspectRatio, getImageAspectRatioFromBase64} from './InviteEmbed/utils';
|
||||||
import styles from './InviteEmbed.module.css';
|
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 groupDMPath = Routes.dmChannel(invite.channel.id);
|
||||||
const handleAcceptInvite = () => InviteActionCreators.acceptAndTransitionToChannel(invite.code, i18n);
|
const handleAcceptInvite = () => InviteActionCreators.acceptAndTransitionToChannel(invite.code, i18n);
|
||||||
const handleNavigateToGroup = () => RouterUtils.transitionTo(groupDMPath);
|
const handleNavigateToGroup = () => RouterUtils.transitionTo(groupDMPath);
|
||||||
const isAlreadyInGroupDM = !!ChannelStore.getChannel(invite.channel.id);
|
const groupDMCounts = getGroupDmInviteCounts({
|
||||||
const memberCount = invite.member_count ?? 0;
|
channelId: invite.channel.id,
|
||||||
|
inviteMemberCount: invite.member_count,
|
||||||
|
});
|
||||||
|
const isAlreadyInGroupDM = groupDMCounts.hasLocalChannel;
|
||||||
|
const memberCount = groupDMCounts.memberCount;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EmbedCard
|
<EmbedCard
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import foodPatternUrl from '~/images/i-like-food.svg';
|
|||||||
import InviteStore from '~/stores/InviteStore';
|
import InviteStore from '~/stores/InviteStore';
|
||||||
import {isGroupDmInvite, isGuildInvite, isPackInvite as isPackInviteGuard} from '~/types/InviteTypes';
|
import {isGroupDmInvite, isGuildInvite, isPackInvite as isPackInviteGuard} from '~/types/InviteTypes';
|
||||||
import * as AvatarUtils from '~/utils/AvatarUtils';
|
import * as AvatarUtils from '~/utils/AvatarUtils';
|
||||||
|
import {getGroupDmInviteCounts} from '~/utils/invite/GroupDmInviteCounts';
|
||||||
import {
|
import {
|
||||||
GuildInvitePrimaryAction,
|
GuildInvitePrimaryAction,
|
||||||
getGuildInviteActionState,
|
getGuildInviteActionState,
|
||||||
@ -57,6 +58,13 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code}: Inv
|
|||||||
}, [code, inviteState]);
|
}, [code, inviteState]);
|
||||||
|
|
||||||
const isGroupDM = invite != null && isGroupDmInvite(invite);
|
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 isPackInvite = invite != null && isPackInviteGuard(invite);
|
||||||
|
|
||||||
const guildActionState = getGuildInviteActionState({invite});
|
const guildActionState = getGuildInviteActionState({invite});
|
||||||
@ -64,12 +72,18 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code}: Inv
|
|||||||
|
|
||||||
const inviteForHeader = React.useMemo(() => {
|
const inviteForHeader = React.useMemo(() => {
|
||||||
if (!invite) return null;
|
if (!invite) return null;
|
||||||
|
if (isGroupDM && groupDMCounts) {
|
||||||
|
return {
|
||||||
|
...invite,
|
||||||
|
member_count: groupDMCounts.memberCount,
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...invite,
|
...invite,
|
||||||
presence_count: presenceCount,
|
presence_count: presenceCount,
|
||||||
member_count: memberCount,
|
member_count: memberCount,
|
||||||
};
|
};
|
||||||
}, [invite, presenceCount, memberCount]);
|
}, [invite, isGroupDM, presenceCount, memberCount, groupDMCounts?.memberCount]);
|
||||||
|
|
||||||
const splashUrl = React.useMemo(() => {
|
const splashUrl = React.useMemo(() => {
|
||||||
if (!invite || !isGuildInvite(invite)) {
|
if (!invite || !isGuildInvite(invite)) {
|
||||||
|
|||||||
50
fluxer_app/src/utils/invite/GroupDmInviteCounts.ts
Normal file
50
fluxer_app/src/utils/invite/GroupDmInviteCounts.ts
Normal 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,
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -22,7 +22,6 @@ import type {Guild, GuildRecord} from '~/records/GuildRecord';
|
|||||||
import type {Invite} from '~/records/MessageRecord';
|
import type {Invite} from '~/records/MessageRecord';
|
||||||
import AuthenticationStore from '~/stores/AuthenticationStore';
|
import AuthenticationStore from '~/stores/AuthenticationStore';
|
||||||
import GuildMemberStore from '~/stores/GuildMemberStore';
|
import GuildMemberStore from '~/stores/GuildMemberStore';
|
||||||
import PresenceStore from '~/stores/PresenceStore';
|
|
||||||
import {isGuildInvite} from '~/types/InviteTypes';
|
import {isGuildInvite} from '~/types/InviteTypes';
|
||||||
|
|
||||||
const normalizeFeatures = (features?: Iterable<string> | null): Array<string> => {
|
const normalizeFeatures = (features?: Iterable<string> | null): Array<string> => {
|
||||||
@ -55,18 +54,8 @@ export const getGuildInviteActionState = (params: {
|
|||||||
const guildId = guildRecord?.id ?? null;
|
const guildId = guildRecord?.id ?? null;
|
||||||
const currentUserId = AuthenticationStore.currentUserId;
|
const currentUserId = AuthenticationStore.currentUserId;
|
||||||
const isMember = Boolean(guildId && currentUserId && GuildMemberStore.getMember(guildId, currentUserId));
|
const isMember = Boolean(guildId && currentUserId && GuildMemberStore.getMember(guildId, currentUserId));
|
||||||
const presenceCount =
|
const presenceCount = params.invite && isGuildInvite(params.invite) ? (params.invite.presence_count ?? 0) : 0;
|
||||||
guildId && isMember
|
const memberCount = params.invite && isGuildInvite(params.invite) ? (params.invite.member_count ?? 0) : 0;
|
||||||
? 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 features = normalizeFeatures(guildRecord?.features ?? inviteGuild?.features);
|
const features = normalizeFeatures(guildRecord?.features ?? inviteGuild?.features);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user