mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(api): show premium badge for premium override (#3395)
This commit is contained in:
1 parent
54ec74e4f9
commit
3694300d86
3 files changed
+45
-1
No files matched your search
@@ -3,6 +3,7 @@
|
|||||||
import {
|
import {
|
||||||
canOwnerRunBots,
|
canOwnerRunBots,
|
||||||
checkIsPremium,
|
checkIsPremium,
|
||||||
|
getBadgePremiumType,
|
||||||
getEffectivePremiumUntil,
|
getEffectivePremiumUntil,
|
||||||
getPremiumPaymentRecoveryGraceMs,
|
getPremiumPaymentRecoveryGraceMs,
|
||||||
isSignInRefused,
|
isSignInRefused,
|
||||||
@@ -61,6 +62,31 @@ describe('checkIsPremium', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getBadgePremiumType', () => {
|
||||||
|
it('shows a subscription badge for a backend premium override', () => {
|
||||||
|
expect(getBadgePremiumType({premiumType: null, premiumFlags: PremiumFlags.ENABLED_OVERRIDE})).toBe(
|
||||||
|
UserPremiumTypes.SUBSCRIPTION,
|
||||||
|
);
|
||||||
|
expect(getBadgePremiumType({premiumType: UserPremiumTypes.NONE, premiumFlags: PremiumFlags.ENABLED_OVERRIDE})).toBe(
|
||||||
|
UserPremiumTypes.SUBSCRIPTION,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('keeps the stored premium type', () => {
|
||||||
|
expect(
|
||||||
|
getBadgePremiumType({premiumType: UserPremiumTypes.LIFETIME, premiumFlags: PremiumFlags.ENABLED_OVERRIDE}),
|
||||||
|
).toBe(UserPremiumTypes.LIFETIME);
|
||||||
|
});
|
||||||
|
it('shows no badge without premium or while perks are disabled', () => {
|
||||||
|
expect(getBadgePremiumType({premiumType: null, premiumFlags: 0})).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
getBadgePremiumType({
|
||||||
|
premiumType: null,
|
||||||
|
premiumFlags: PremiumFlags.ENABLED_OVERRIDE | PremiumFlags.PERKS_DISABLED,
|
||||||
|
}),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('account standing', () => {
|
describe('account standing', () => {
|
||||||
const hour = 3_600_000;
|
const hour = 3_600_000;
|
||||||
function standing(flags: bigint, tempBannedUntil: Date | null = null, deletionStartedAt: Date | null = null) {
|
function standing(flags: bigint, tempBannedUntil: Date | null = null, deletionStartedAt: Date | null = null) {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
PREMIUM_PAYMENT_RECOVERY_GRACE_DAYS,
|
PREMIUM_PAYMENT_RECOVERY_GRACE_DAYS,
|
||||||
PremiumFlags,
|
PremiumFlags,
|
||||||
UserFlags,
|
UserFlags,
|
||||||
|
type UserPremiumType,
|
||||||
|
UserPremiumTypes,
|
||||||
} from '@fluxer/constants/src/UserConstants';
|
} from '@fluxer/constants/src/UserConstants';
|
||||||
import {MS_PER_DAY} from '@fluxer/date_utils/src/DateConstants';
|
import {MS_PER_DAY} from '@fluxer/date_utils/src/DateConstants';
|
||||||
import {snowflakeToDate} from '@fluxer/snowflake/src/Snowflake';
|
import {snowflakeToDate} from '@fluxer/snowflake/src/Snowflake';
|
||||||
@@ -121,6 +123,21 @@ export function checkIsPremium(user: PremiumCheckable): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBadgePremiumType(
|
||||||
|
user: Pick<PremiumCheckable, 'premiumType' | 'premiumFlags'>,
|
||||||
|
): UserPremiumType | undefined {
|
||||||
|
if (user.premiumType != null && user.premiumType !== UserPremiumTypes.NONE) {
|
||||||
|
return user.premiumType as UserPremiumType;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(user.premiumFlags & (PremiumFlags.ENABLED_OVERRIDE | PremiumFlags.PERKS_DISABLED)) ===
|
||||||
|
PremiumFlags.ENABLED_OVERRIDE
|
||||||
|
) {
|
||||||
|
return UserPremiumTypes.SUBSCRIPTION;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const PREMIUM_CLEAR_FIELDS = [
|
const PREMIUM_CLEAR_FIELDS = [
|
||||||
'premium_type',
|
'premium_type',
|
||||||
'premium_since',
|
'premium_since',
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type {GuildMember} from '@app/api/models/GuildMember';
|
|||||||
import type {User} from '@app/api/models/User';
|
import type {User} from '@app/api/models/User';
|
||||||
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
|
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
|
||||||
import {isUsernameTaken} from '@app/api/user/UniqueUsernames';
|
import {isUsernameTaken} from '@app/api/user/UniqueUsernames';
|
||||||
|
import {getBadgePremiumType} from '@app/api/user/UserHelpers';
|
||||||
import {hasFixedDiscriminator} from '@app/api/user/UserTag';
|
import {hasFixedDiscriminator} from '@app/api/user/UserTag';
|
||||||
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
|
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
|
||||||
import {
|
import {
|
||||||
@@ -100,7 +101,7 @@ export class UserAccountLookupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let premiumType = user.premiumType ?? undefined;
|
let premiumType = getBadgePremiumType(user);
|
||||||
let premiumSince = user.premiumSince ?? undefined;
|
let premiumSince = user.premiumSince ?? undefined;
|
||||||
let premiumLifetimeSequence = user.premiumLifetimeSequence ?? undefined;
|
let premiumLifetimeSequence = user.premiumLifetimeSequence ?? undefined;
|
||||||
if (restrictProfile || user.premiumFlags & PremiumFlags.BADGE_HIDDEN) {
|
if (restrictProfile || user.premiumFlags & PremiumFlags.BADGE_HIDDEN) {
|
||||||
|
|||||||
Reference in new issue
Block a user