A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(api): publish operator pass wall entries and business logos
Hampus09ccccbf73f3
diff --git a/fluxer_api/src/api/operator_pass/OperatorPassBusinessListing.ts b/fluxer_api/src/api/operator_pass/OperatorPassBusinessListing.tsnew file mode 100644index 000000000..f77f3eeaa--- /dev/null+++ b/fluxer_api/src/api/operator_pass/OperatorPassBusinessListing.ts@@ -0,0 +1,159 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {UserID} from '@app/api/BrandedTypes';+import type {OperatorPassPurchaseRow} from '@app/api/database/types/OperatorPassTypes';+import {+ loadOperatorPassEntitlementState,+ resolveOperatorPassHolder,+} from '@app/api/operator_pass/OperatorPassEntitlementService';+import type {OperatorPassRepository} from '@app/api/operator_pass/OperatorPassRepository';+import {MS_PER_DAY} from '@fluxer/date_utils/src/DateConstants';+import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';+import sharp, {type Metadata} from 'sharp';+import type Stripe from 'stripe';++const LOGO_MAX_BYTES = 2 * 1024 * 1024;+const LOGO_MIN_PX = 256;+const LOGO_MAX_PIXELS = 4096 * 4096;+const PAYMENT_HOLD_MS = 7 * MS_PER_DAY;+const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];++type LogoFormat = 'png' | 'jpeg' | 'webp';++function ascii(bytes: Uint8Array, start: number, end: number): string {+ return String.fromCharCode(...bytes.subarray(start, end));+}++function sniffLogoFormat(bytes: Uint8Array): LogoFormat | null {+ if (bytes.length >= 8 && PNG_SIGNATURE.every((byte, index) => bytes[index] === byte)) {+ return 'png';+ }+ if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {+ return 'jpeg';+ }+ if (bytes.length >= 12 && ascii(bytes, 0, 4) === 'RIFF' && ascii(bytes, 8, 12) === 'WEBP') {+ return 'webp';+ }+ return null;+}++function isAnimatedPng(bytes: Uint8Array): boolean {+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);+ let offset = PNG_SIGNATURE.length;+ while (offset + 8 <= bytes.length) {+ const type = ascii(bytes, offset + 4, offset + 8);+ if (type === 'acTL') {+ return true;+ }+ if (type === 'IDAT') {+ return false;+ }+ offset += 12 + view.getUint32(offset);+ }+ return false;+}++function invalidLogo(message: string): InputValidationError {+ return InputValidationError.create('logo', message);+}++export async function validateOperatorPassBusinessLogo(bytes: Uint8Array): Promise<void> {+ if (bytes.length > LOGO_MAX_BYTES) {+ throw invalidLogo('The logo must be under 2 MB');+ }+ const format = sniffLogoFormat(bytes);+ if (!format) {+ throw invalidLogo('The logo must be a PNG, JPEG or WebP image');+ }+ if (format === 'png' && isAnimatedPng(bytes)) {+ throw invalidLogo('The logo must not be animated');+ }+ let metadata: Metadata;+ try {+ metadata = await sharp(Buffer.from(bytes)).metadata();+ } catch {+ throw invalidLogo('The logo could not be read as an image');+ }+ const width = metadata.width ?? 0;+ const height = metadata.height ?? 0;+ if (metadata.format !== format) {+ throw invalidLogo('The logo must be a PNG, JPEG or WebP image');+ }+ if ((metadata.pages ?? 1) > 1) {+ throw invalidLogo('The logo must not be animated');+ }+ if (width * height > LOGO_MAX_PIXELS) {+ throw invalidLogo('The logo must be at most 4096 by 4096 pixels');+ }+ if (width !== height) {+ throw invalidLogo('The logo must be square');+ }+ if (width < LOGO_MIN_PX) {+ throw invalidLogo(`The logo must be at least ${LOGO_MIN_PX} by ${LOGO_MIN_PX} pixels`);+ }+}++function isPaymentSettled(purchase: OperatorPassPurchaseRow, now: Date): boolean {+ const paidAt = purchase.completed_at ?? purchase.purchased_at;+ return (+ purchase.status === 'completed' &&+ purchase.refunded_at == null &&+ purchase.fraud_warning_at == null &&+ (purchase.disputed_at == null || purchase.dispute_closed_at != null) &&+ paidAt != null &&+ now.getTime() - paidAt.getTime() >= PAYMENT_HOLD_MS+ );+}++function isQualifyingTaxId(taxId: Stripe.TaxId): boolean {+ if (taxId.type !== 'eu_vat' || taxId.country === 'SE') {+ return true;+ }+ return taxId.verification?.status === 'verified';+}++async function hasQualifyingTaxId(stripe: Stripe, purchase: OperatorPassPurchaseRow): Promise<boolean> {+ const session = await stripe.checkout.sessions.retrieve(purchase.checkout_session_id, {+ expand: ['customer.tax_ids'],+ });+ const customer = session.customer;+ if (!customer || typeof customer === 'string' || customer.deleted) {+ return false;+ }+ return (customer.tax_ids?.data ?? []).some(isQualifyingTaxId);+}++export async function findOperatorPassBusinessPurchase(params: {+ stripe: Stripe;+ repository: OperatorPassRepository;+ userId: UserID;+ now: Date;+}): Promise<OperatorPassPurchaseRow | null> {+ const {stripe, repository, userId, now} = params;+ for (const purchase of await repository.listPurchasesByPurchaser(userId)) {+ if (isPaymentSettled(purchase, now) && (await hasQualifyingTaxId(stripe, purchase))) {+ return purchase;+ }+ }+ return null;+}++export async function requireOperatorPassBusinessPurchase(params: {+ stripe: Stripe;+ repository: OperatorPassRepository;+ userId: UserID;+ now: Date;+}): Promise<OperatorPassPurchaseRow> {+ const state = await loadOperatorPassEntitlementState(params.repository, params.userId);+ if (!resolveOperatorPassHolder(state, params.now)) {+ throw InputValidationError.create('user_id', 'The account holds no Operator Pass that shows on the wall');+ }+ const purchase = await findOperatorPassBusinessPurchase(params);+ if (!purchase) {+ throw InputValidationError.create(+ 'user_id',+ 'No purchase of this account qualifies. A business listing needs a purchase with a tax ID, verified when it is an EU VAT number from outside Sweden, paid at least 7 days ago with no refund, open dispute or fraud warning.',+ );+ }+ return purchase;+}diff --git a/fluxer_api/src/api/operator_pass/OperatorPassWallPresentation.ts b/fluxer_api/src/api/operator_pass/OperatorPassWallPresentation.tsnew file mode 100644index 000000000..fd28bba91--- /dev/null+++ b/fluxer_api/src/api/operator_pass/OperatorPassWallPresentation.ts@@ -0,0 +1,131 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {OperatorPassWallEntryRow} from '@app/api/database/types/OperatorPassTypes';+import type {User} from '@app/api/models/User';+import {+ OPERATOR_PASS_WALL_AVATAR_SIZES,+ operatorPassWallSnapshotUrl,+} from '@app/api/operator_pass/OperatorPassWallAvatarStore';+import {+ OPERATOR_PASS_WALL_FALLBACK_NAME,+ OPERATOR_PASS_WALL_REVIEW_TARGET_MS,+} from '@app/api/operator_pass/OperatorPassWallConstants';+import {UserFlags} from '@fluxer/constants/src/UserConstants';+import {OperatorPassWallNameRequiredError} from '@fluxer/errors/src/domains/operator_pass/OperatorPassWallNameRequiredError';+import type {OperatorPassListingResponse} from '@fluxer/schema/src/domains/operator_pass/OperatorPassSchemas';++const OFF_WALL_FLAGS = UserFlags.DELETED | UserFlags.SELF_DELETED | UserFlags.SPAMMER;++export function isOperatorPassWallStanding(+ user: Pick<User, 'flags' | 'tempBannedUntil' | 'pendingDeletionAt' | 'deletionStartedAt'>,+ now = Date.now(),+): boolean {+ if ((user.flags & OFF_WALL_FLAGS) !== 0n || user.pendingDeletionAt !== null || user.deletionStartedAt !== null) {+ return false;+ }+ if ((user.flags & UserFlags.DISABLED) === 0n) {+ return true;+ }+ return user.tempBannedUntil !== null && user.tempBannedUntil.getTime() <= now;+}++export interface OperatorPassWallChoice {+ name: string | null;+ optedOut: boolean;+}++export function normalizeOperatorPassWallChoice({+ name,+ optOut,+}: {+ name: string | null | undefined;+ optOut: boolean | null | undefined;+}): OperatorPassWallChoice {+ if (optOut === true) {+ return {name: null, optedOut: true};+ }+ const trimmed = name?.trim() ?? '';+ if (trimmed.length === 0) {+ throw new OperatorPassWallNameRequiredError();+ }+ return {name: trimmed, optedOut: false};+}++export function hasOperatorPassWallChoice(entry: OperatorPassWallEntryRow | null): boolean {+ return entry != null && (entry.listed_at != null || entry.left_wall_at != null || entry.delivered_at != null);+}++export function isOperatorPassWallListed(entry: OperatorPassWallEntryRow): boolean {+ return !entry.opted_out && entry.listed_at != null;+}++export function operatorPassWallShownName(entry: OperatorPassWallEntryRow, user: Pick<User, 'username'>): string {+ if (entry.live_name) {+ return entry.live_name;+ }+ return entry.username_declined ? OPERATOR_PASS_WALL_FALLBACK_NAME : user.username;+}++export function operatorPassWallReviewState(+ entry: OperatorPassWallEntryRow,+): 'pending' | 'approved' | 'declined' | null {+ if (entry.pending_revision_id != null) {+ return 'pending';+ }+ if (entry.declined_revision_id != null) {+ return 'declined';+ }+ if (entry.live_revision_id != null) {+ return 'approved';+ }+ return null;+}++export function operatorPassWallDisplayState(+ entry: OperatorPassWallEntryRow,+ {removed}: {removed: boolean},+): 'live' | 'fallback' | 'hidden' | 'removed' {+ if (removed) {+ return 'removed';+ }+ if (entry.hidden) {+ return 'hidden';+ }+ return entry.live_revision_id != null ? 'live' : 'fallback';+}++export function mapOperatorPassListing(+ entry: OperatorPassWallEntryRow | null,+ passCount: number,+ user: Pick<User, 'username'>,+ {removed = false}: {removed?: boolean} = {},+): OperatorPassListingResponse {+ const listed = entry != null && isOperatorPassWallListed(entry);+ return {+ wall_name: entry?.opted_out ? null : (entry?.pending_name ?? entry?.live_name ?? entry?.name ?? null),+ wall_opt_out: entry?.opted_out ?? true,+ keep_as_is: entry?.keep_as_is ?? false,+ release_list_opt_in: entry?.release_list_opt_in ?? false,+ status: listed ? 'listed' : 'not_listed',+ display_state: listed && entry ? operatorPassWallDisplayState(entry, {removed}) : null,+ review_state: listed && entry ? operatorPassWallReviewState(entry) : null,+ shown_name: listed && entry ? operatorPassWallShownName(entry, user) : null,+ shown_avatar_url:+ listed && entry?.live_avatar+ ? operatorPassWallSnapshotUrl(entry.live_avatar, Math.max(...OPERATOR_PASS_WALL_AVATAR_SIZES))+ : null,+ pending_name: listed ? (entry?.pending_name ?? null) : null,+ pending_since: listed ? (entry?.pending_since?.toISOString() ?? null) : null,+ review_due_at:+ listed && entry?.pending_since+ ? new Date(entry.pending_since.getTime() + OPERATOR_PASS_WALL_REVIEW_TARGET_MS).toISOString()+ : null,+ decline_reason: listed ? (entry?.decline_reason ?? null) : null,+ decline_note: listed ? (entry?.decline_note ?? null) : null,+ declined_name: listed ? (entry?.declined_name ?? null) : null,+ listed_at: listed ? (entry?.listed_at?.toISOString() ?? null) : null,+ release_year: entry?.release_erased_at ? null : (entry?.release_published_year ?? null),+ has_wall: passCount > 0,+ pass_count: passCount,+ };+}diff --git a/fluxer_api/src/api/operator_pass/OperatorPassWallPublicationService.ts b/fluxer_api/src/api/operator_pass/OperatorPassWallPublicationService.tsnew file mode 100644index 000000000..4b6c84447--- /dev/null+++ b/fluxer_api/src/api/operator_pass/OperatorPassWallPublicationService.ts@@ -0,0 +1,353 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {UserID} from '@app/api/BrandedTypes';+import {Config} from '@app/api/Config';+import {Db} from '@app/api/database/CassandraTypes';+import type {OperatorPassWallEntryRow, OperatorPassWallStateRow} from '@app/api/database/types/OperatorPassTypes';+import {getOperatorPassWallInfrastructure} from '@app/api/middleware/ServiceSingletons';+import {+ loadOperatorPassEntitlementState,+ resolveOperatorPassHolder,+} from '@app/api/operator_pass/OperatorPassEntitlementService';+import {getOperatorPassWallTier} from '@app/api/operator_pass/OperatorPassPrices';+import type {OperatorPassRepository} from '@app/api/operator_pass/OperatorPassRepository';+import {operatorPassNow} from '@app/api/operator_pass/OperatorPassSchedule';+import {+ OPERATOR_PASS_WALL_AVATAR_SIZES,+ OPERATOR_PASS_WALL_TIER_SCALES,+ operatorPassWallSnapshotUrl,+} from '@app/api/operator_pass/OperatorPassWallAvatarStore';+import {OPERATOR_PASS_WALL_UPDATE_ATTEMPTS} from '@app/api/operator_pass/OperatorPassWallConstants';+import type {OperatorPassWallEntryStore} from '@app/api/operator_pass/OperatorPassWallEntryStore';+import {+ isOperatorPassWallListed,+ isOperatorPassWallStanding,+ operatorPassWallShownName,+} from '@app/api/operator_pass/OperatorPassWallPresentation';+import {+ type OperatorPassWallBlobEntry,+ operatorPassWallPublicId,+} from '@app/api/operator_pass/OperatorPassWallPublisher';+import {isOperatorPassCountHidden} from '@app/api/user/profile_badges/PremiumBadgeMasking';+import type {UserRepository} from '@app/api/user/repositories/UserRepository';+import type {OperatorPassWallResponse} from '@fluxer/schema/src/domains/operator_pass/OperatorPassSchemas';++const PUBLIC_WALL_CACHE_MS = 60_000;++const WALL_STATE_ID = 'wall';++let publicWallCache: {expiresAt: number; value: OperatorPassWallSnapshot} | null = null;++export function invalidateOperatorPassPublicWall(): void {+ publicWallCache = null;+}++interface OperatorPassWallSnapshot {+ version: number;+ frozen: boolean;+ generated_at: string;+ avatar_sizes: Array<number>;+ tier_scales: Array<number>;+ entries: Array<OperatorPassWallBlobEntry>;+}++interface RankedWallEntry {+ entry: OperatorPassWallBlobEntry;+ since: number;+}++export class OperatorPassWallPublicationService {+ constructor(+ private readonly repository: OperatorPassRepository,+ private readonly userRepository: UserRepository,+ private readonly entries: OperatorPassWallEntryStore,+ ) {}++ private async buildPublicEntry(+ entry: OperatorPassWallEntryRow,+ now: Date = operatorPassNow(),+ ): Promise<OperatorPassWallBlobEntry | null> {+ return (await this.buildRankedEntry(entry, now))?.entry ?? null;+ }++ private async buildRankedEntry(entry: OperatorPassWallEntryRow, now: Date): Promise<RankedWallEntry | null> {+ if (!isOperatorPassWallListed(entry) || entry.hidden) {+ return null;+ }+ const [user, state] = await Promise.all([+ this.userRepository.findUnique(entry.user_id),+ loadOperatorPassEntitlementState(this.repository, entry.user_id),+ ]);+ if (!user || !isOperatorPassWallStanding(user, now.getTime())) {+ return null;+ }+ const holder = resolveOperatorPassHolder(state, now);+ if (!holder) {+ return null;+ }+ return {+ entry: {+ id: operatorPassWallPublicId(entry.user_id),+ name: operatorPassWallShownName(entry, user),+ avatar: entry.live_avatar ?? null,+ tier: getOperatorPassWallTier(entry.live_business ? 1 : holder.count, Config.operatorPass.wallTierMinimums),+ ...(isOperatorPassCountHidden(user.premiumFlags) ? {} : {count: holder.count}),+ ...(entry.live_business ? {business: true as const} : {}),+ },+ since: holder.since.getTime(),+ };+ }++ async snapshot(): Promise<OperatorPassWallSnapshot> {+ for (let attempt = 0; attempt < OPERATOR_PASS_WALL_UPDATE_ATTEMPTS; attempt++) {+ const state = await this.loadState();+ if (state.frozen && state.frozen_snapshot) {+ return JSON.parse(state.frozen_snapshot) as OperatorPassWallSnapshot;+ }+ if (+ publicWallCache &&+ publicWallCache.expiresAt > Date.now() &&+ publicWallCache.value.version === Number(state.wall_version)+ ) {+ return publicWallCache.value;+ }+ const value = await this.computeSnapshot(Number(state.wall_version));+ const after = await this.loadState();+ if (after.wall_version === state.wall_version && after.frozen === state.frozen) {+ publicWallCache = {expiresAt: Date.now() + PUBLIC_WALL_CACHE_MS, value};+ return value;+ }+ }+ throw new Error("Operators' wall version changed too often to snapshot");+ }++ async listPublicWall(): Promise<OperatorPassWallResponse> {+ const snapshot = await this.snapshot();+ const size = Math.max(...OPERATOR_PASS_WALL_AVATAR_SIZES);+ return {+ version: snapshot.version,+ operators: snapshot.entries.map((entry) => ({+ id: entry.id,+ name: entry.name,+ avatar: entry.avatar,+ avatar_url: entry.avatar ? operatorPassWallSnapshotUrl(entry.avatar, size) : null,+ ...(entry.count !== undefined ? {count: entry.count} : {}),+ tier: entry.tier,+ ...(entry.business ? {business: true as const} : {}),+ })),+ };+ }++ async loadState(): Promise<OperatorPassWallStateRow> {+ const existing = await this.repository.findWallState(WALL_STATE_ID);+ if (existing) {+ return existing;+ }+ const created: OperatorPassWallStateRow = {+ id: WALL_STATE_ID,+ wall_version: 0n,+ frozen: false,+ frozen_at: null,+ frozen_by: null,+ frozen_snapshot: null,+ published_at: null,+ version: 1,+ };+ await this.repository.createWallState(created);+ return (await this.repository.findWallState(WALL_STATE_ID)) ?? created;+ }++ async setFrozen(frozen: boolean, adminId: UserID): Promise<OperatorPassWallStateRow> {+ for (let attempt = 0; attempt < OPERATOR_PASS_WALL_UPDATE_ATTEMPTS; attempt++) {+ const state = await this.loadState();+ if (state.frozen === frozen) {+ return state;+ }+ const now = operatorPassNow();+ const frozenSnapshot = frozen+ ? JSON.stringify(await this.computeSnapshot(Number(state.wall_version), 'frozen'))+ : null;+ const next = await this.repository.updateWallState(state, {+ frozen: Db.set(frozen),+ frozen_at: Db.set(frozen ? now : null),+ frozen_by: Db.set(frozen ? adminId : null),+ frozen_snapshot: Db.set(frozenSnapshot),+ });+ if (next) {+ publicWallCache = null;+ if (!frozen) {+ await this.republish();+ await this.releaseFrozenAvatars(state.frozen_snapshot ?? null);+ }+ return next;+ }+ }+ throw new Error("Operators' wall state changed too often to update");+ }++ async republish(): Promise<number> {+ const state = await this.loadState();+ if (state.frozen) {+ return Number(state.wall_version);+ }+ const bumped = await this.bumpVersion();+ if (bumped === null) {+ return Number(state.wall_version);+ }+ await getOperatorPassWallInfrastructure().publisher.publish({+ type: 'operator_pass_wall_delta',+ version: bumped.version,+ previous_version: bumped.previous,+ published_at: new Date().toISOString(),+ resync: true,+ upserts: [],+ removals: [],+ });+ return bumped.version;+ }++ async publishChanges(userIds: ReadonlyArray<UserID>, ordering: 'reorder' | 'preserve' = 'reorder'): Promise<void> {+ publicWallCache = null;+ const state = await this.loadState();+ if (state.frozen) {+ await this.dropFromFrozenSnapshot(userIds);+ return;+ }+ const bumped = await this.bumpVersion();+ if (bumped === null) {+ await this.dropFromFrozenSnapshot(userIds);+ return;+ }+ const upserts: Array<OperatorPassWallBlobEntry> = [];+ const removals: Array<string> = [];+ for (const userId of new Set(userIds)) {+ const entry = await this.repository.findWallEntry(userId);+ const item = entry ? await this.buildPublicEntry(entry) : null;+ if (item) upserts.push(item);+ else removals.push(operatorPassWallPublicId(userId));+ }+ await getOperatorPassWallInfrastructure().publisher.publish({+ type: 'operator_pass_wall_delta',+ version: bumped.version,+ previous_version: bumped.previous,+ published_at: new Date().toISOString(),+ resync: ordering === 'reorder' && upserts.length > 0,+ upserts,+ removals,+ });+ }++ private async computeSnapshot(version: number, mode: 'live' | 'frozen' = 'live'): Promise<OperatorPassWallSnapshot> {+ const now = operatorPassNow();+ const ranked: Array<RankedWallEntry> = [];+ for (const entry of await this.entries.scanAll()) {+ const item = await this.buildRankedEntry(entry, now);+ if (item) ranked.push(item);+ }+ const entries = ranked+ .sort(+ (left, right) =>+ Number(left.entry.business === true) - Number(right.entry.business === true) ||+ (left.entry.business ? 0 : right.entry.tier - left.entry.tier) ||+ left.since - right.since ||+ left.entry.id.localeCompare(right.entry.id),+ )+ .map((item) => item.entry);+ return {+ version,+ frozen: mode === 'frozen',+ generated_at: new Date().toISOString(),+ avatar_sizes: [...OPERATOR_PASS_WALL_AVATAR_SIZES],+ tier_scales: [...OPERATOR_PASS_WALL_TIER_SCALES],+ entries,+ };+ }++ private async bumpVersion(): Promise<{version: number; previous: number} | null> {+ for (let attempt = 0; attempt < OPERATOR_PASS_WALL_UPDATE_ATTEMPTS * 4; attempt++) {+ const state = await this.loadState();+ if (state.frozen) {+ return null;+ }+ const next = state.wall_version + 1n;+ const updated = await this.repository.updateWallState(state, {+ wall_version: Db.set(next),+ published_at: Db.set(new Date()),+ });+ if (updated) {+ return {version: Number(next), previous: Number(state.wall_version)};+ }+ }+ throw new Error("Operators' wall version changed too often to update");+ }++ async isAvatarServed(sha256: string): Promise<boolean> {+ for (const userId of await this.repository.listWallAvatarRefs(sha256)) {+ const entry = await this.repository.findWallEntry(userId);+ if (entry?.live_avatar === sha256 && (await this.buildPublicEntry(entry)) !== null) {+ return true;+ }+ }+ const state = await this.loadState();+ if (state.frozen && state.frozen_snapshot) {+ const frozen = JSON.parse(state.frozen_snapshot) as OperatorPassWallSnapshot;+ return frozen.entries.some((item) => item.avatar === sha256);+ }+ return false;+ }++ private async releaseFrozenAvatars(frozenSnapshot: string | null): Promise<void> {+ if (!frozenSnapshot) {+ return;+ }+ const frozen = JSON.parse(frozenSnapshot) as OperatorPassWallSnapshot;+ const avatars = new Set(frozen.entries.flatMap((item) => (item.avatar ? [item.avatar] : [])));+ for (const avatar of avatars) {+ await this.releaseAvatar(avatar);+ }+ }++ async releaseAvatar(sha256: string): Promise<void> {+ if (!(await this.isAvatarServed(sha256))) {+ await getOperatorPassWallInfrastructure().avatarStore.unpublish(sha256);+ }+ }++ async publishAvatarIfServed(entry: OperatorPassWallEntryRow): Promise<void> {+ if (entry.live_avatar && (await this.buildPublicEntry(entry)) !== null) {+ await getOperatorPassWallInfrastructure().avatarStore.publish(entry.live_avatar);+ }+ }++ private async dropFromFrozenSnapshot(userIds: ReadonlyArray<UserID>): Promise<void> {+ const gone: Array<string> = [];+ for (const userId of new Set(userIds)) {+ const entry = await this.repository.findWallEntry(userId);+ if (!entry || (await this.buildPublicEntry(entry)) === null) {+ gone.push(operatorPassWallPublicId(userId));+ }+ }+ if (gone.length === 0) {+ return;+ }+ for (let attempt = 0; attempt < OPERATOR_PASS_WALL_UPDATE_ATTEMPTS; attempt++) {+ const state = await this.loadState();+ if (!state.frozen || !state.frozen_snapshot) {+ return;+ }+ const frozen = JSON.parse(state.frozen_snapshot) as OperatorPassWallSnapshot;+ const entries = frozen.entries.filter((item) => !gone.includes(item.id));+ if (entries.length === frozen.entries.length) {+ return;+ }+ const updated = await this.repository.updateWallState(state, {+ frozen_snapshot: Db.set(JSON.stringify({...frozen, entries})),+ });+ if (updated) {+ publicWallCache = null;+ return;+ }+ }+ throw new Error("Operators' wall state changed too often to update");+ }+}