Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): load profile badges from the API

Hampus420a0ad7cd1a
diff --git a/fluxer_app/src/features/user/commands/UserProfileCommands.tsx b/fluxer_app/src/features/user/commands/UserProfileCommands.tsx
index 62435f8ba..befdf1034 100644
--- a/fluxer_app/src/features/user/commands/UserProfileCommands.tsx
+++ b/fluxer_app/src/features/user/commands/UserProfileCommands.tsx
@@ -17,6 +17,11 @@ import UserProfile from '@app/features/user/state/UserProfile';
import UserProfileMobile from '@app/features/user/state/UserProfileMobile';
import Users from '@app/features/user/state/Users';
import {ME} from '@fluxer/constants/src/AppConstants';
+import type {
+ ProfileBadgePreviewRequest,
+ ProfileBadgePreviewResponse,
+ ProfileBadgeResponse,
+} from '@fluxer/schema/src/domains/user/ProfileBadgeSchemas';
const logger = new Logger('UserProfiles');
const pendingRequests: Map<string, Promise<Profile>> = new Map();
@@ -91,6 +96,15 @@ export async function fetch(userId: string, guildId?: string): Promise<Profile>
}
}
+export async function previewBadges(
+ settings: ProfileBadgePreviewRequest,
+): Promise<ReadonlyArray<ProfileBadgeResponse>> {
+ const response = await http.post<ProfileBadgePreviewResponse>(Endpoints.USER_PROFILE_BADGES_PREVIEW, {
+ body: settings,
+ });
+ return response.body.profile_badges;
+}
+
export function invalidate(userId: string, guildId?: string): void {
const scope = guildId ? ` in guild ${guildId}` : '';
logger.debug(`Invalidating cached profile for user ${userId}${scope}`);
diff --git a/fluxer_app/src/features/user/components/modals/user_profile_modal/UserProfileModalUserInfo.tsx b/fluxer_app/src/features/user/components/modals/user_profile_modal/UserProfileModalUserInfo.tsx
index a9f38b2e0..4719068ac 100644
--- a/fluxer_app/src/features/user/components/modals/user_profile_modal/UserProfileModalUserInfo.tsx
+++ b/fluxer_app/src/features/user/components/modals/user_profile_modal/UserProfileModalUserInfo.tsx
@@ -65,8 +65,7 @@ export const UserInfo: React.FC<UserInfoProps> = observer(({user, profile, guild
</div>
<div className={userProfileModalStyles.badgesWrapper} data-flx="user.user-profile-modal.user-info.div--8">
<UserProfileBadges
- user={user}
- profile={profile}
+ badges={profile.profileBadges}
isModal={true}
isMobile={false}
data-flx="user.user-profile-modal.user-info.user-profile-badges"
diff --git a/fluxer_app/src/features/user/components/popouts/UserProfilePopout.tsx b/fluxer_app/src/features/user/components/popouts/UserProfilePopout.tsx
index dbcc6254a..10a1a0fff 100644
--- a/fluxer_app/src/features/user/components/popouts/UserProfilePopout.tsx
+++ b/fluxer_app/src/features/user/components/popouts/UserProfilePopout.tsx
@@ -52,6 +52,7 @@ import {useUserProfileSurfaceState} from '@app/features/user/hooks/useUserProfil
import type {User} from '@app/features/user/models/User';
import {blockedDmConfirmModal, openDMChannelOrShowError} from '@app/features/user/utils/DMActionUtils';
import * as NicknameUtils from '@app/features/user/utils/NicknameUtils';
+import {canOpenProfileEditor} from '@app/features/user/utils/ProfileEditAccess';
import {resolveProfileGuildMembership} from '@app/features/user/utils/ProfileGuildMembership';
import {createMockProfile} from '@app/features/user/utils/ProfileUtils';
import {Permissions} from '@fluxer/constants/src/ChannelConstants';
@@ -254,159 +255,160 @@ export const UserProfilePopout: React.FC<UserProfilePopoutProps> = observer(
}
const borderColor = accentColor;
const bannerColor = accentColor;
+ const cardClassName = styles.profilePopoutCard;
+ const profileBanner = (
+ <ProfileCardBanner
+ bannerUrl={bannerUrl}
+ hoverBannerUrl={hoverBannerUrl}
+ bannerColor={bannerColor}
+ user={user}
+ avatarUrl={avatarUrl}
+ hoverAvatarUrl={hoverAvatarUrl}
+ disablePresence={isWebhook}
+ isClickable={!isWebhook}
+ onAvatarClick={!isWebhook ? handleOpenFullProfile : undefined}
+ onAvatarContextMenu={handleAvatarContextMenu}
+ onBannerContextMenu={handleBannerContextMenu}
+ data-flx="user.user-profile-popout.profile-card-banner"
+ />
+ );
+ const profileBadges = !isWebhook && (
+ <UserProfileBadges
+ badges={profile?.profileBadges ?? []}
+ data-flx="user.user-profile-popout.user-profile-badges"
+ />
+ );
+ const profileContent = (
+ <ProfileCardContent isWebhook={isWebhook} data-flx="user.user-profile-popout.profile-card-content">
+ {showProfileDataWarning && (
+ <div className={styles.profileDataWarning} data-flx="user.user-profile-popout.profile-data-warning">
+ <UserProfileDataWarning data-flx="user.user-profile-popout.user-profile-data-warning" />
+ </div>
+ )}
+ {!isWebhook && profile?.profileLimited && (
+ <div className={styles.profileDataWarning} data-flx="user.user-profile-popout.profile-limited-notice">
+ <LimitedProfileNotice data-flx="user.user-profile-popout.limited-profile-notice" />
+ </div>
+ )}
+ <ProfileCardUserInfo
+ displayName={displayName}
+ displayNameClassName={styles.profileDisplayName}
+ user={user}
+ pronouns={profileData?.pronouns}
+ showUsername={!isWebhook}
+ isClickable={!isWebhook}
+ isWebhook={isWebhook}
+ onDisplayNameClick={!isWebhook ? handleOpenFullProfile : undefined}
+ onUsernameClick={!isWebhook ? handleOpenFullProfile : undefined}
+ actions={
+ !isWebhook && (
+ <ProfileCardActions
+ userId={user.id}
+ isHovering={isHovering}
+ onNoteClick={handleOpenFullProfileNote}
+ data-flx="user.user-profile-popout.profile-card-actions"
+ />
+ )
+ }
+ data-flx="user.user-profile-popout.profile-card-user-info"
+ />
+ {!isWebhook && presenceCustomStatus && (
+ <div className={styles.profileCustomStatus} data-flx="user.user-profile-popout.profile-custom-status">
+ <CustomStatusDisplay
+ customStatus={presenceCustomStatus}
+ className={styles.profileCustomStatusText}
+ allowJumboEmoji
+ maxLines={0}
+ alwaysAnimate={shouldAutoplayProfileAnimations}
+ data-flx="user.user-profile-popout.profile-custom-status-text"
+ />
+ </div>
+ )}
+ {!isWebhook && (
+ <VoiceActivitySection
+ userId={user.id}
+ onNavigate={handleClosePopout}
+ data-flx="user.user-profile-popout.voice-activity-section"
+ />
+ )}
+ {profile && (
+ <UserProfilePreviewBio
+ profile={profile}
+ profileData={profileData ?? null}
+ onShowMore={handleOpenFullProfile}
+ data-flx="user.user-profile-popout.user-profile-preview-bio"
+ />
+ )}
+ {profile && (
+ <UserProfileTimezoneInfo profile={profile} data-flx="user.user-profile-popout.user-profile-timezone-info" />
+ )}
+ {profile && (
+ <UserProfileMembershipInfo
+ profile={profile}
+ user={user}
+ data-flx="user.user-profile-popout.user-profile-membership-info"
+ />
+ )}
+ {!isWebhook && profile && (
+ <UserProfileRoles
+ profile={profile}
+ user={user}
+ memberRoles={[...memberRoles]}
+ canManageRoles={canManageRoles}
+ data-flx="user.user-profile-popout.user-profile-roles"
+ />
+ )}
+ {profile && (
+ <UserProfileConnections
+ profile={profile}
+ variant="compact"
+ data-flx="user.user-profile-popout.user-profile-connections"
+ />
+ )}
+ </ProfileCardContent>
+ );
+ let footerAction: React.ReactNode = null;
+ if (showProfileFooter && isCurrentUser && canOpenProfileEditor(user)) {
+ footerAction = (
+ <Button
+ small={true}
+ fitContainer={true}
+ leftIcon={<PencilIcon className={styles.iconSmall} data-flx="user.user-profile-popout.icon-small--2" />}
+ onClick={handleEditProfile}
+ data-flx="user.user-profile-popout.button.edit-profile"
+ >
+ <Trans>Edit profile</Trans>
+ </Button>
+ );
+ } else if (showProfileFooter && !isCurrentUser) {
+ footerAction = (
+ <Button
+ small={true}
+ fitContainer={true}
+ leftIcon={<ChatTeardropIcon className={styles.iconSmall} data-flx="user.user-profile-popout.icon-small--3" />}
+ onClick={isBlocked ? handleOpenBlockedDm : handleMessage}
+ data-flx="user.user-profile-popout.button.open-blocked-dm"
+ >
+ {isBlocked ? i18n._(OPEN_DM_DESCRIPTOR) : <Trans context="message-action">Message</Trans>}
+ </Button>
+ );
+ }
return (
<FocusRingScope containerRef={popoutContainerRef} data-flx="user.user-profile-popout.focus-ring-scope">
<div ref={popoutContainerRef} data-flx="user.user-profile-popout.div">
<ProfileCardLayout
borderColor={borderColor}
hoverRef={hoverRef}
- className={styles.profilePopoutCard}
+ className={cardClassName}
style={PROFILE_POPOUT_GEOMETRY_STYLE}
data-flx="user.user-profile-popout.profile-card-layout"
>
- <ProfileCardBanner
- bannerUrl={bannerUrl as string | null}
- hoverBannerUrl={hoverBannerUrl}
- bannerColor={bannerColor}
- user={user}
- avatarUrl={avatarUrl}
- hoverAvatarUrl={hoverAvatarUrl}
- disablePresence={isWebhook}
- isClickable={!isWebhook}
- onAvatarClick={!isWebhook ? handleOpenFullProfile : undefined}
- onAvatarContextMenu={handleAvatarContextMenu}
- onBannerContextMenu={handleBannerContextMenu}
- data-flx="user.user-profile-popout.profile-card-banner"
- />
- {!isWebhook && (
- <UserProfileBadges
- user={user}
- profile={profile}
- data-flx="user.user-profile-popout.user-profile-badges"
- />
- )}
- <ProfileCardContent isWebhook={isWebhook} data-flx="user.user-profile-popout.profile-card-content">
- {showProfileDataWarning && (
- <div className={styles.profileDataWarning} data-flx="user.user-profile-popout.profile-data-warning">
- <UserProfileDataWarning data-flx="user.user-profile-popout.user-profile-data-warning" />
- </div>
- )}
- {!isWebhook && profile?.profileLimited && (
- <div className={styles.profileDataWarning} data-flx="user.user-profile-popout.profile-limited-notice">
- <LimitedProfileNotice data-flx="user.user-profile-popout.limited-profile-notice" />
- </div>
- )}
- <ProfileCardUserInfo
- displayName={displayName}
- displayNameClassName={styles.profileDisplayName}
- user={user}
- pronouns={profileData?.pronouns}
- showUsername={!isWebhook}
- isClickable={!isWebhook}
- isWebhook={isWebhook}
- onDisplayNameClick={!isWebhook ? handleOpenFullProfile : undefined}
- onUsernameClick={!isWebhook ? handleOpenFullProfile : undefined}
- actions={
- !isWebhook && (
- <ProfileCardActions
- userId={user.id}
- isHovering={isHovering}
- onNoteClick={handleOpenFullProfileNote}
- data-flx="user.user-profile-popout.profile-card-actions"
- />
- )
- }
- data-flx="user.user-profile-popout.profile-card-user-info"
- />
- {!isWebhook && presenceCustomStatus && (
- <div className={styles.profileCustomStatus} data-flx="user.user-profile-popout.profile-custom-status">
- <CustomStatusDisplay
- customStatus={presenceCustomStatus}
- className={styles.profileCustomStatusText}
- allowJumboEmoji
- maxLines={0}
- alwaysAnimate={shouldAutoplayProfileAnimations}
- data-flx="user.user-profile-popout.profile-custom-status-text"
- />
- </div>
- )}
- {!isWebhook && (
- <VoiceActivitySection
- userId={user.id}
- onNavigate={handleClosePopout}
- data-flx="user.user-profile-popout.voice-activity-section"
- />
- )}
- {profile && (
- <UserProfilePreviewBio
- profile={profile}
- profileData={profileData ?? null}
- onShowMore={handleOpenFullProfile}
- data-flx="user.user-profile-popout.user-profile-preview-bio"
- />
- )}
- {profile && (
- <UserProfileTimezoneInfo
- profile={profile}
- data-flx="user.user-profile-popout.user-profile-timezone-info"
- />
- )}
- {profile && (
- <UserProfileMembershipInfo
- profile={profile}
- user={user}
- data-flx="user.user-profile-popout.user-profile-membership-info"
- />
- )}
- {!isWebhook && profile && (
- <UserProfileRoles
- profile={profile}
- user={user}
- memberRoles={[...memberRoles]}
- canManageRoles={canManageRoles}
- data-flx="user.user-profile-popout.user-profile-roles"
- />
- )}
- {profile && (
- <UserProfileConnections
- profile={profile}
- variant="compact"
- data-flx="user.user-profile-popout.user-profile-connections"
- />
- )}
- </ProfileCardContent>
+ {profileBanner}
+ {profileBadges}
+ {profileContent}
{showProfileFooter && (
<ProfileCardFooter data-flx="user.user-profile-popout.profile-card-footer">
- {isCurrentUser ? (
- user.isClaimed() ? (
- <Button
- small={true}
- fitContainer={true}
- leftIcon={
- <PencilIcon className={styles.iconSmall} data-flx="user.user-profile-popout.icon-small--2" />
- }
- onClick={handleEditProfile}
- data-flx="user.user-profile-popout.button.edit-profile"
- >
- <Trans>Edit profile</Trans>
- </Button>
- ) : null
- ) : (
- <Button
- small={true}
- fitContainer={true}
- leftIcon={
- <ChatTeardropIcon
- className={styles.iconSmall}
- data-flx="user.user-profile-popout.icon-small--3"
- />
- }
- onClick={isBlocked ? handleOpenBlockedDm : handleMessage}
- data-flx="user.user-profile-popout.button.open-blocked-dm"
- >
- {isBlocked ? i18n._(OPEN_DM_DESCRIPTOR) : <Trans context="message-action">Message</Trans>}
- </Button>
- )}
+ {footerAction}
</ProfileCardFooter>
)}
</ProfileCardLayout>
diff --git a/fluxer_app/src/features/user/components/profile/ProfilePreview.tsx b/fluxer_app/src/features/user/components/profile/ProfilePreview.tsx
index 86e36d475..a85153229 100644
--- a/fluxer_app/src/features/user/components/profile/ProfilePreview.tsx
+++ b/fluxer_app/src/features/user/components/profile/ProfilePreview.tsx
@@ -23,13 +23,15 @@ import {ProfileCardLayout} from '@app/features/user/components/profile/profile_c
import {ProfileCardUserInfo} from '@app/features/user/components/profile/profile_card/ProfileCardUserInfo';
import {useProfileCardDisplayState} from '@app/features/user/components/profile/useProfileCardDisplayState';
import {useAutoplayExpandedProfileAnimations} from '@app/features/user/hooks/useAutoplayExpandedProfileAnimations';
+import {useOwnProfileBadges} from '@app/features/user/hooks/useOwnProfileBadges';
import type {Profile} from '@app/features/user/models/Profile';
import type {User} from '@app/features/user/models/User';
import type {CustomStatus} from '@app/features/user/state/CustomStatus';
import * as NicknameUtils from '@app/features/user/utils/NicknameUtils';
import type {ProfilePreviewOverrides} from '@app/features/user/utils/ProfileDisplayUtils';
-import {type BadgeSettings, createMockProfile} from '@app/features/user/utils/ProfileUtils';
+import {createMockProfile} from '@app/features/user/utils/ProfileUtils';
import {YOU_CAN_T_MESSAGE_YOURSELF_DESCRIPTOR} from '@app/features/user/utils/UserMessageDescriptors';
+import type {ProfileBadgePreviewRequest} from '@fluxer/schema/src/domains/user/ProfileBadgeSchemas';
import type {UserProfile} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
import {msg} from '@lingui/core/macro';
import {Trans, useLingui} from '@lingui/react/macro';
@@ -58,7 +60,7 @@ interface ProfilePreviewProps {
guildId?: string | null;
guildMember?: GuildMember | null;
guildMemberProfile?: UserProfile | null;
- previewBadgeSettings?: BadgeSettings;
+ previewBadgeSettings?: ProfileBadgePreviewRequest;
ignoreGuildAvatarInPreview?: boolean;
ignoreGuildBannerInPreview?: boolean;
showMembershipInfo?: boolean;
@@ -113,6 +115,7 @@ export const ProfilePreview: React.FC<ProfilePreviewProps> = observer(
],
);
const isCommunityProfile = Boolean(guildId && guildMemberProfile);
+ const profileBadges = useOwnProfileBadges(user.id, previewBadgeSettings);
const previewUser = useMemo(() => {
const globalName = previewGlobalName !== undefined ? previewGlobalName : user.globalName;
if (isCommunityProfile) {
@@ -126,7 +129,7 @@ export const ProfilePreview: React.FC<ProfilePreviewProps> = observer(
if (isCommunityProfile && guildId && guildMemberProfile) {
const globalProfile = createMockProfile(previewUser, {
previewTimezoneOffset,
- previewBadgeSettings,
+ profileBadges,
});
return globalProfile.withGuildId(guildId).withUpdates({
guild_member: guildMember?.toJSON(),
@@ -145,7 +148,7 @@ export const ProfilePreview: React.FC<ProfilePreviewProps> = observer(
previewPronouns,
previewAccentColor,
previewTimezoneOffset,
- previewBadgeSettings,
+ profileBadges,
});
}, [
previewUser,
@@ -155,7 +158,7 @@ export const ProfilePreview: React.FC<ProfilePreviewProps> = observer(
previewPronouns,
previewAccentColor,
previewTimezoneOffset,
- previewBadgeSettings,
+ profileBadges,
guildId,
guildMember,
guildMemberProfile,
@@ -251,8 +254,7 @@ export const ProfilePreview: React.FC<ProfilePreviewProps> = observer(
data-flx="user.profile.profile-preview.profile-card-banner"
/>
<UserProfileBadges
- user={previewUser}
- profile={mockProfile}
+ badges={mockProfile.profileBadges}
data-flx="user.profile.profile-preview.user-profile-badges"
/>
<ProfileCardContent data-flx="user.profile.profile-preview.profile-card-content">
diff --git a/fluxer_app/src/features/user/events/UserUpdate.ts b/fluxer_app/src/features/user/events/UserUpdate.ts
index be7cf3cd0..2a9efe8e6 100644
--- a/fluxer_app/src/features/user/events/UserUpdate.ts
+++ b/fluxer_app/src/features/user/events/UserUpdate.ts
@@ -6,6 +6,7 @@ import GuildVerification from '@app/features/guild/state/GuildVerification';
import Messages from '@app/features/messaging/state/MessagingMessages';
import Permission from '@app/features/permissions/state/Permission';
import QuickSwitcher from '@app/features/search/state/QuickSwitcher';
+import * as UserProfileCommands from '@app/features/user/commands/UserProfileCommands';
import Users from '@app/features/user/state/Users';
import type {User} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
@@ -18,13 +19,23 @@ export interface UserUpdatePayload {
avatar: string | null;
flags: number;
is_staff?: boolean;
+ operator_pass_since?: string | null;
+}
+
+function operatorPassSinceChanged(data: UserUpdatePayload): boolean {
+ const current = Users.currentUser;
+ if (!current || current.id !== data.id || data.operator_pass_since === undefined) return false;
+ const next = data.operator_pass_since ? new Date(data.operator_pass_since).getTime() : null;
+ return (current.operatorPassSince?.getTime() ?? null) !== next;
}
export function handleUserUpdate(data: UserUpdatePayload, context: GatewayHandlerContext): void {
+ const passChanged = operatorPassSinceChanged(data);
Users.handleUserUpdate(data as User);
if (context.accountKey !== null && data.id === context.expectedUserId) {
syncAccountUserData(context.accountKey, data);
}
+ if (passChanged) UserProfileCommands.clearCurrentUserProfiles();
Messages.handleUserUpdate({user: {id: data.id}});
Permission.handleUserUpdate(data.id);
QuickSwitcher.recomputeIfOpen();
diff --git a/fluxer_app/src/features/user/hooks/useOwnProfileBadges.ts b/fluxer_app/src/features/user/hooks/useOwnProfileBadges.ts
new file mode 100644
index 000000000..b878d4ed3
--- /dev/null
+++ b/fluxer_app/src/features/user/hooks/useOwnProfileBadges.ts
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {useDebouncedAsyncResource} from '@app/features/platform/hooks/useDebouncedAsyncResource';
+import {Logger} from '@app/features/platform/utils/AppLogger';
+import * as UserProfileCommands from '@app/features/user/commands/UserProfileCommands';
+import UserProfile from '@app/features/user/state/UserProfile';
+import type {
+ ProfileBadgePreviewRequest,
+ ProfileBadgeResponse,
+} from '@fluxer/schema/src/domains/user/ProfileBadgeSchemas';
+import {useEffect, useMemo} from 'react';
+
+const logger = new Logger('useOwnProfileBadges');
+const PREVIEW_DEBOUNCE_MS = 250;
+const NO_BADGES: ReadonlyArray<ProfileBadgeResponse> = [];
+
+export function useOwnProfileBadges(
+ userId: string | null,
+ settings?: ProfileBadgePreviewRequest,
+): ReadonlyArray<ProfileBadgeResponse> {
+ const cachedBadges = userId ? UserProfile.getProfile(userId)?.profileBadges : undefined;
+ const hasSettings = Boolean(settings);
+ const premiumBadgeHidden = settings?.premium_badge_hidden;
+ const premiumBadgeTimestampHidden = settings?.premium_badge_timestamp_hidden;
+ const premiumBadgeMasked = settings?.premium_badge_masked;
+ const premiumBadgeSequenceHidden = settings?.premium_badge_sequence_hidden;
+ const operatorPassBadgeHidden = settings?.operator_pass_badge_hidden;
+ const operatorPassBadgeTimestampHidden = settings?.operator_pass_badge_timestamp_hidden;
+ const operatorPassBadgeCountHidden = settings?.operator_pass_badge_count_hidden;
+ const hasCachedProfile = cachedBadges !== undefined;
+ useEffect(() => {
+ if (!userId || hasSettings || hasCachedProfile) {
+ return;
+ }
+ UserProfileCommands.fetch(userId).catch((error: unknown) => {
+ logger.warn('Failed to load profile badges', error);
+ });
+ }, [userId, hasSettings, hasCachedProfile]);
+ const request = useMemo(() => {
+ if (!userId || !hasSettings) {
+ return null;
+ }
+ return {
+ input: {
+ premium_badge_hidden: premiumBadgeHidden,
+ premium_badge_timestamp_hidden: premiumBadgeTimestampHidden,
+ premium_badge_masked: premiumBadgeMasked,
+ premium_badge_sequence_hidden: premiumBadgeSequenceHidden,
+ operator_pass_badge_hidden: operatorPassBadgeHidden,
+ operator_pass_badge_timestamp_hidden: operatorPassBadgeTimestampHidden,
+ operator_pass_badge_count_hidden: operatorPassBadgeCountHidden,
+ },
+ load: UserProfileCommands.previewBadges,
+ };
+ }, [
+ userId,
+ hasSettings,
+ premiumBadgeHidden,
+ premiumBadgeTimestampHidden,
+ premiumBadgeMasked,
+ premiumBadgeSequenceHidden,
+ operatorPassBadgeHidden,
+ operatorPassBadgeTimestampHidden,
+ operatorPassBadgeCountHidden,
+ ]);
+ const preview = useDebouncedAsyncResource(request, PREVIEW_DEBOUNCE_MS, (error) => {
+ logger.warn('Failed to load profile badges', error);
+ });
+ if (!userId) {
+ return NO_BADGES;
+ }
+ if (hasSettings && preview?.value) {
+ return preview.value;
+ }
+ return cachedBadges ?? NO_BADGES;
+}
diff --git a/fluxer_app/src/features/user/models/Profile.ts b/fluxer_app/src/features/user/models/Profile.ts
index afb597f51..374204cea 100644
--- a/fluxer_app/src/features/user/models/Profile.ts
+++ b/fluxer_app/src/features/user/models/Profile.ts
@@ -7,6 +7,7 @@ import GuildMembers from '@app/features/member/state/GuildMembers';
import Users from '@app/features/user/state/Users';
import type {ConnectionResponse} from '@fluxer/schema/src/domains/connection/ConnectionSchemas';
import type {GuildMemberData} from '@fluxer/schema/src/domains/guild/GuildMemberSchemas';
+import type {ProfileBadgeResponse} from '@fluxer/schema/src/domains/user/ProfileBadgeSchemas';
import type {UserPartial, UserProfile} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
export interface ProfileMutualGuild {
@@ -20,9 +21,7 @@ export type ProfileWire = Readonly<{
guild_member_profile?: UserProfile | null;
timezone_offset: number | null;
guild_member?: GuildMemberData;
- premium_type?: number;
- premium_since?: string;
- premium_lifetime_sequence?: number;
+ profile_badges?: ReadonlyArray<ProfileBadgeResponse>;
mutual_friends?: Array<UserPartial>;
mutual_guilds?: Array<ProfileMutualGuild>;
connected_accounts?: Array<ConnectionResponse>;
@@ -35,9 +34,7 @@ export class Profile {
readonly userProfile: Readonly<UserProfile>;
readonly guildMemberProfile: Readonly<UserProfile> | null;
readonly timezoneOffset: number | null;
- readonly premiumType: number | null;
- readonly premiumSince: Date | null;
- readonly premiumLifetimeSequence: number | null;
+ readonly profileBadges: ReadonlyArray<ProfileBadgeResponse>;
readonly mutualFriends: ReadonlyArray<UserPartial> | null;
readonly mutualGuilds: ReadonlyArray<ProfileMutualGuild> | null;
readonly connectedAccounts: ReadonlyArray<ConnectionResponse> | null;
@@ -50,9 +47,7 @@ export class Profile {
this.userProfile = Object.freeze({...profile.user_profile});
this.guildMemberProfile = profile.guild_member_profile ? Object.freeze({...profile.guild_member_profile}) : null;
this.timezoneOffset = profile.timezone_offset;
- this.premiumType = profile.premium_type ?? null;
- this.premiumSince = profile.premium_since ? new Date(profile.premium_since) : null;
- this.premiumLifetimeSequence = profile.premium_lifetime_sequence ?? null;
+ this.profileBadges = Object.freeze([...(profile.profile_badges ?? [])]);
this.mutualFriends = profile.mutual_friends ? Object.freeze([...profile.mutual_friends]) : null;
this.mutualGuilds = profile.mutual_guilds ? Object.freeze([...profile.mutual_guilds]) : null;
this.connectedAccounts = profile.connected_accounts ? Object.freeze([...profile.connected_accounts]) : null;
@@ -73,13 +68,7 @@ export class Profile {
timezone_offset: updates.timezone_offset !== undefined ? updates.timezone_offset : this.timezoneOffset,
guild_member:
updates.guild_member !== undefined ? updates.guild_member : (this.embeddedGuildMember?.toJSON() ?? undefined),
- premium_type: updates.premium_type !== undefined ? updates.premium_type : (this.premiumType ?? undefined),
- premium_since:
- updates.premium_since !== undefined ? updates.premium_since : (this.premiumSince?.toISOString() ?? undefined),
- premium_lifetime_sequence:
- updates.premium_lifetime_sequence !== undefined
- ? updates.premium_lifetime_sequence
- : (this.premiumLifetimeSequence ?? undefined),
+ profile_badges: updates.profile_badges ?? this.profileBadges,
mutual_friends: updates.mutual_friends ?? (this.mutualFriends ? [...this.mutualFriends] : undefined),
mutual_guilds: updates.mutual_guilds ?? (this.mutualGuilds ? [...this.mutualGuilds] : undefined),
connected_accounts:
@@ -133,9 +122,7 @@ export class Profile {
guild_member_profile: this.guildMemberProfile ? {...this.guildMemberProfile} : undefined,
guild_member: this.embeddedGuildMember?.toJSON(),
timezone_offset: this.timezoneOffset,
- premium_type: this.premiumType ?? undefined,
- premium_since: this.premiumSince?.toISOString() ?? undefined,
- premium_lifetime_sequence: this.premiumLifetimeSequence ?? undefined,
+ profile_badges: [...this.profileBadges],
mutual_friends: this.mutualFriends ? [...this.mutualFriends] : undefined,
mutual_guilds: this.mutualGuilds ? [...this.mutualGuilds] : undefined,
connected_accounts: this.connectedAccounts ? [...this.connectedAccounts] : undefined,
diff --git a/fluxer_app/src/features/user/state/UserProfile.ts b/fluxer_app/src/features/user/state/UserProfile.ts
index 3d5922d05..b96cc5932 100644
--- a/fluxer_app/src/features/user/state/UserProfile.ts
+++ b/fluxer_app/src/features/user/state/UserProfile.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import Authentication from '@app/features/auth/state/Authentication';
+import {onLocaleChange} from '@app/features/i18n/utils/LocaleChangeListener';
import {AccountScopedWork} from '@app/features/platform/state/AccountScopedWork';
import {Logger} from '@app/features/platform/utils/AppLogger';
import type {Profile} from '@app/features/user/models/Profile';
@@ -18,6 +19,7 @@ class UserProfile {
constructor() {
makeAutoObservable(this, {}, {autoBind: true});
+ onLocaleChange(() => this.clearAllProfiles());
}
getProfile(userId: string, guildId?: string): Profile | null {
diff --git a/fluxer_app/src/features/user/utils/ProfileUtils.ts b/fluxer_app/src/features/user/utils/ProfileUtils.ts
index 445241879..c2fe7298a 100644
--- a/fluxer_app/src/features/user/utils/ProfileUtils.ts
+++ b/fluxer_app/src/features/user/utils/ProfileUtils.ts
@@ -2,68 +2,9 @@
import {Profile} from '@app/features/user/models/Profile';
import type {User} from '@app/features/user/models/User';
-import {ProfileFieldPrivacyFlags, UserPremiumTypes} from '@fluxer/constants/src/UserConstants';
+import {ProfileFieldPrivacyFlags} from '@fluxer/constants/src/UserConstants';
import {getCurrentTimeZoneOffsetMinutes} from '@fluxer/date_utils/src/TimeZoneUtils';
-
-export interface BadgeSettings {
- premium_badge_hidden?: boolean;
- premium_badge_timestamp_hidden?: boolean;
- premium_badge_masked?: boolean;
- premium_badge_sequence_hidden?: boolean;
-}
-
-function computeVisiblePremiumData(user: User, previewBadgeSettings?: BadgeSettings) {
- const premiumType = user.premiumType;
- const premiumSince = user.premiumSince;
- const premiumLifetimeSequence = user.premiumLifetimeSequence;
- if (!premiumType || premiumType === UserPremiumTypes.NONE) {
- return {
- premiumType: null,
- premiumSince: null,
- premiumLifetimeSequence: null,
- };
- }
- const premiumBadgeHidden = previewBadgeSettings?.premium_badge_hidden ?? user.premiumBadgeHidden;
- const premiumBadgeTimestampHidden =
- previewBadgeSettings?.premium_badge_timestamp_hidden ?? user.premiumBadgeTimestampHidden;
- const premiumBadgeMasked = previewBadgeSettings?.premium_badge_masked ?? user.premiumBadgeMasked;
- const premiumBadgeSequenceHidden =
- previewBadgeSettings?.premium_badge_sequence_hidden ?? user.premiumBadgeSequenceHidden;
- if (premiumBadgeHidden) {
- return {
- premiumType: null,
- premiumSince: null,
- premiumLifetimeSequence: null,
- };
- }
- let visiblePremiumType = premiumType;
- let visiblePremiumSince = premiumSince;
- let visiblePremiumLifetimeSequence = premiumLifetimeSequence;
- if (premiumType === UserPremiumTypes.LIFETIME) {
- if (premiumBadgeMasked) {
- visiblePremiumType = UserPremiumTypes.SUBSCRIPTION;
- }
- if (premiumBadgeSequenceHidden) {
- visiblePremiumLifetimeSequence = null;
- }
- }
- if (premiumBadgeTimestampHidden) {
- visiblePremiumSince = null;
- }
- let premiumSinceString: string | null = null;
- if (visiblePremiumSince) {
- if (typeof visiblePremiumSince === 'string') {
- premiumSinceString = visiblePremiumSince;
- } else if (visiblePremiumSince instanceof Date) {
- premiumSinceString = visiblePremiumSince.toISOString();
- }
- }
- return {
- premiumType: visiblePremiumType,
- premiumSince: premiumSinceString,
- premiumLifetimeSequence: visiblePremiumLifetimeSequence,
- };
-}
+import type {ProfileBadgeResponse} from '@fluxer/schema/src/domains/user/ProfileBadgeSchemas';
export function createMockProfile(
user: User,
@@ -73,34 +14,39 @@ export function createMockProfile(
previewBio?: string | null;
previewPronouns?: string | null;
previewAccentColor?: number | null;
- previewBadgeSettings?: BadgeSettings;
previewTimezoneOffset?: number | null;
+ profileBadges?: ReadonlyArray<ProfileBadgeResponse>;
},
): Profile {
- const finalBanner = options?.hasClearedBanner
- ? null
- : options?.previewBannerUrl
- ? options.previewBannerUrl
- : user.banner || null;
+ let finalBanner: string | null;
+ if (options?.hasClearedBanner) {
+ finalBanner = null;
+ } else if (options?.previewBannerUrl) {
+ finalBanner = options.previewBannerUrl;
+ } else {
+ finalBanner = user.banner || null;
+ }
const finalBio = options?.previewBio !== undefined ? options.previewBio : user.bio || null;
const finalPronouns = options?.previewPronouns !== undefined ? options.previewPronouns : user.pronouns || null;
- const visiblePremiumData = computeVisiblePremiumData(user, options?.previewBadgeSettings);
+ const profileUser = user.toJSON();
+ const userProfile = {
+ bio: finalBio,
+ banner: finalBanner,
+ pronouns: finalPronouns,
+ accent_color: options?.previewAccentColor !== undefined ? options.previewAccentColor : (user.accentColor ?? null),
+ };
+ let timezoneOffset: number | null;
+ if (options?.previewTimezoneOffset !== undefined) {
+ timezoneOffset = options.previewTimezoneOffset;
+ } else if ((user.timezonePrivacyFlags ?? ProfileFieldPrivacyFlags.EVERYONE) !== 0) {
+ timezoneOffset = getCurrentTimeZoneOffsetMinutes(user.timezone);
+ } else {
+ timezoneOffset = null;
+ }
return new Profile({
- user: user.toJSON(),
- user_profile: {
- bio: finalBio,
- banner: finalBanner,
- pronouns: finalPronouns,
- accent_color: options?.previewAccentColor !== undefined ? options.previewAccentColor : (user.accentColor ?? null),
- },
- timezone_offset:
- options?.previewTimezoneOffset !== undefined
- ? options.previewTimezoneOffset
- : (user.timezonePrivacyFlags ?? ProfileFieldPrivacyFlags.EVERYONE) !== 0
- ? getCurrentTimeZoneOffsetMinutes(user.timezone)
- : null,
- premium_type: visiblePremiumData.premiumType ?? undefined,
- premium_since: visiblePremiumData.premiumSince ?? undefined,
- premium_lifetime_sequence: visiblePremiumData.premiumLifetimeSequence ?? undefined,
+ user: profileUser,
+ user_profile: userProfile,
+ timezone_offset: timezoneOffset,
+ profile_badges: options?.profileBadges ?? [],
});
}