A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(schema): add profile badges and operator pass badge flags
Hampus149f5846af3a
diff --git a/packages/constants/src/UserConstants.ts b/packages/constants/src/UserConstants.tsindex 0fdb4c1e7..a22903a02 100644--- a/packages/constants/src/UserConstants.ts+++ b/packages/constants/src/UserConstants.ts@@ -92,7 +92,7 @@ export const UserFlagsDescriptions: Record<keyof typeof UserFlags, string> = {HAS_DISMISSED_PREMIUM_ONBOARDING: 'User has dismissed premium onboarding',APP_STORE_REVIEWER: 'User is an app store reviewer',STAFF_HIDDEN: 'User staff status is hidden from public flags',- AGE_VERIFIED_ADULT: 'User has verified their age as an adult via credit card verification',+ AGE_VERIFIED_ADULT: 'User has verified their age as an adult',LIMIT_EXEMPT: 'User is permanently exempt from account limitation',};export const PremiumFlags = {@@ -105,6 +105,9 @@ export const PremiumFlags = {PURCHASE_DISABLED: 1 << 6,ENABLED_OVERRIDE: 1 << 7,PERKS_DISABLED: 1 << 8,+ OPERATOR_PASS_BADGE_HIDDEN: 1 << 9,+ OPERATOR_PASS_BADGE_TIMESTAMP_HIDDEN: 1 << 11,+ OPERATOR_PASS_BADGE_COUNT_HIDDEN: 1 << 12,} as const;export const PremiumFlagsDescriptions: Record<keyof typeof PremiumFlags, string> = {DISCRIMINATOR: 'User has a premium discriminator',@@ -116,6 +119,9 @@ export const PremiumFlagsDescriptions: Record<keyof typeof PremiumFlags, string>PURCHASE_DISABLED: 'Premium purchase is disabled for this user',ENABLED_OVERRIDE: 'Premium status is enabled via override',PERKS_DISABLED: 'User has temporarily disabled premium perks',+ OPERATOR_PASS_BADGE_HIDDEN: 'User has chosen to hide their Operator Pass badge',+ OPERATOR_PASS_BADGE_TIMESTAMP_HIDDEN: 'User has hidden when they first got the Operator Pass',+ OPERATOR_PASS_BADGE_COUNT_HIDDEN: 'User has hidden how many Operator Passes they hold',};const LEGACY_PREMIUM_FLAG_BITS_TO_NEW: ReadonlyArray<readonly [bigint, number]> = [[1n << 37n, PremiumFlags.DISCRIMINATOR],diff --git a/packages/date_utils/src/SinceMonthYear.ts b/packages/date_utils/src/SinceMonthYear.tsnew file mode 100644index 000000000..477b6812b--- /dev/null+++ b/packages/date_utils/src/SinceMonthYear.ts@@ -0,0 +1,28 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {getDateFormatter} from '@fluxer/date_utils/src/DateFormatterCache';++const FORMAT_CONTEXT_MONTH_LANGUAGES = new Set(['cs', 'hr', 'lt', 'pl', 'ru', 'sk', 'uk']);++function languageOf(locale: string): string {+ try {+ return new Intl.Locale(locale).language;+ } catch {+ return locale.split(/[-_]/)[0]?.toLowerCase() ?? locale;+ }+}++export function formatSinceMonthYear(date: Date, locale: string, timeZone?: string): string {+ const zone = timeZone ? {timeZone} : {};+ if (!FORMAT_CONTEXT_MONTH_LANGUAGES.has(languageOf(locale))) {+ return getDateFormatter(locale, {month: 'long', year: 'numeric', ...zone}).format(date);+ }+ const parts = getDateFormatter(locale, {day: 'numeric', month: 'long', year: 'numeric', ...zone}).formatToParts(date);+ const day = parts.findIndex((part) => part.type === 'day');+ const joiner = day < parts.length - 1 ? day + 1 : day - 1;+ return parts+ .filter((_, index) => index !== day && index !== joiner)+ .map((part) => part.value)+ .join('')+ .trim();+}diff --git a/packages/schema/src/domains/user/ProfileBadgeSchemas.ts b/packages/schema/src/domains/user/ProfileBadgeSchemas.tsnew file mode 100644index 000000000..25fe28aa4--- /dev/null+++ b/packages/schema/src/domains/user/ProfileBadgeSchemas.ts@@ -0,0 +1,96 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {HexString16Type} from '@fluxer/schema/src/primitives/SchemaPrimitives';+import {z} from 'zod';++export const ProfileBadgeResponse = z.object({+ kind: z+ .string()+ .describe(+ 'Stable badge key. Known values: staff, partner, bug_hunter, operator_pass, visionary, visionary_number, plutonium, and premium on self-hosted instances. Clients must render unknown values from the other fields.',+ ),+ label: z+ .string()+ .describe(+ 'Full badge description, localized for the viewer. Use it as the tooltip, and as alt text when there is no caption',+ ),+ asset: HexString16Type.nullable().describe(+ 'Badge image hash. The image is served at {static_cdn}/badges/{asset}.webp. Null for text badges',+ ),+ small_asset: HexString16Type.optional().describe(+ 'Image hash drawn for 20 pixels and smaller, served like asset. Use it instead of asset at those sizes. Absent when asset reads well small',+ ),+ aspect_ratio: z+ .number()+ .positive()+ .nullable()+ .describe(+ 'Image width divided by its height. Render the image at the badge height and this many times as wide. Null for square badges',+ ),+ caption: z+ .string()+ .nullable()+ .describe(+ 'Short text for the badge, such as #42. A badge with an image uses it as alt text, and a badge without one shows it as text. Null when the label covers it',+ ),+ href: z.string().nullable().describe('Absolute URL to open when the badge is clicked, or null'),+ count: z+ .number()+ .int()+ .nullish()+ .describe(+ 'How many passes the badge stands for, from 2. The badge art already carries the number, so clients never draw it on top. Absent below 2 and when the holder hides the number from other people',+ ),+ accessible_label: z+ .string()+ .nullish()+ .describe('Label for screen readers with the full count, used instead of label when present'),+ details: z+ .object({+ title: z.string().describe('First line of the tooltip under the larger badge art'),+ lines: z.array(z.string()).describe('Further tooltip lines, in order'),+ })+ .nullish()+ .describe('Content for the richer vertical tooltip, null or absent when label is the whole tooltip'),+});++export type ProfileBadgeResponse = z.infer<typeof ProfileBadgeResponse>;++export const ProfileBadgeListResponse = z+ .array(ProfileBadgeResponse)+ .describe('Profile badges in display order. Empty when there is nothing to show');++export const ProfileBadgePreviewRequest = z.object({+ premium_badge_hidden: z.boolean().optional().describe('Preview with the premium badge hidden'),+ premium_badge_masked: z.boolean().optional().describe('Preview with the premium badge masked'),+ premium_badge_timestamp_hidden: z.boolean().optional().describe('Preview with the premium badge date hidden'),+ premium_badge_sequence_hidden: z.boolean().optional().describe('Preview with the Visionary ID hidden'),+ operator_pass_badge_hidden: z+ .boolean()+ .optional()+ .describe('Preview with the Operator Pass badge hidden, or shown when false'),+ operator_pass_badge_timestamp_hidden: z+ .boolean()+ .optional()+ .describe('Preview with the month and year the Operator Pass was first held hidden'),+ operator_pass_badge_count_hidden: z+ .boolean()+ .optional()+ .describe('Preview with the number of Operator Passes held hidden'),+});++export type ProfileBadgePreviewRequest = z.infer<typeof ProfileBadgePreviewRequest>;++export const ProfileBadgePreviewResponse = z.object({+ profile_badges: ProfileBadgeListResponse,+});++export type ProfileBadgePreviewResponse = z.infer<typeof ProfileBadgePreviewResponse>;++export const AdminProfileBadgeResponse = ProfileBadgeResponse.extend({+ suppressed: z+ .boolean()+ .describe('True when the public profile does not show this badge, because of a privacy setting or account state'),+});++export type AdminProfileBadgeResponse = z.infer<typeof AdminProfileBadgeResponse>;