From a62fae913afd5c42775bca620279d7a0b1d1f665 Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Tue, 17 Feb 2026 18:16:23 +0800 Subject: [PATCH] presence status --- src/ws/dto/app-metadata.dto.ts | 25 +++++++++---------- src/ws/dto/user-status.dto.ts | 6 ++--- src/ws/state/state.gateway.spec.ts | 40 +++++++++++++++--------------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/ws/dto/app-metadata.dto.ts b/src/ws/dto/app-metadata.dto.ts index 1b1dbef..e29f023 100644 --- a/src/ws/dto/app-metadata.dto.ts +++ b/src/ws/dto/app-metadata.dto.ts @@ -15,17 +15,16 @@ function IsAtLeastOneNameProvided(validationOptions?: ValidationOptions) { name: 'isAtLeastOneNameProvided', validator: { validate(value, args) { - const object = args?.object as AppMetadataDto; - const hasLocalized = - typeof object.localized === 'string' && - object.localized.trim().length > 0; - const hasUnlocalized = - typeof object.unlocalized === 'string' && - object.unlocalized.trim().length > 0; - return hasLocalized || hasUnlocalized; + const object = args?.object as PresenceStatusDto; + const hasTitle = + typeof object.title === 'string' && object.title.trim().length > 0; + const hasSubtitle = + typeof object.subtitle === 'string' && + object.subtitle.trim().length > 0; + return hasTitle || hasSubtitle; }, defaultMessage() { - return 'At least one of localized or unlocalized must be a non-empty string'; + return 'At least one of title or subtitle must be a non-empty string'; }, }, }, @@ -33,19 +32,19 @@ function IsAtLeastOneNameProvided(validationOptions?: ValidationOptions) { ); } -export class AppMetadataDto { +export class PresenceStatusDto { @IsOptional() @IsString() @MaxLength(200) @IsAtLeastOneNameProvided() - localized: string | null; + title: string | null; @IsOptional() @IsString() @MaxLength(200) - unlocalized: string | null; + subtitle: string | null; @IsOptional() @IsString() - appIconB64: string | null; + graphicsB64: string | null; } diff --git a/src/ws/dto/user-status.dto.ts b/src/ws/dto/user-status.dto.ts index a68c9f3..0e2bf25 100644 --- a/src/ws/dto/user-status.dto.ts +++ b/src/ws/dto/user-status.dto.ts @@ -1,6 +1,6 @@ import { IsEnum, ValidateNested } from 'class-validator'; import { Type } from 'class-transformer'; -import { AppMetadataDto } from './app-metadata.dto'; +import { PresenceStatusDto } from './app-metadata.dto'; export enum UserState { IDLE = 'idle', @@ -9,8 +9,8 @@ export enum UserState { export class UserStatusDto { @ValidateNested() - @Type(() => AppMetadataDto) - appMetadata: AppMetadataDto; + @Type(() => PresenceStatusDto) + presenceStatus: PresenceStatusDto; @IsEnum(UserState) state: UserState; diff --git a/src/ws/state/state.gateway.spec.ts b/src/ws/state/state.gateway.spec.ts index 985280a..daf0735 100644 --- a/src/ws/state/state.gateway.spec.ts +++ b/src/ws/state/state.gateway.spec.ts @@ -486,10 +486,10 @@ describe('StateGateway', () => { ]); const data: UserStatusDto = { - appMetadata: { - localized: null, - unlocalized: 'VS Code', - appIconB64: null, + presenceStatus: { + title: null, + subtitle: 'VS Code', + graphicsB64: null, }, state: UserState.IDLE, }; @@ -522,10 +522,10 @@ describe('StateGateway', () => { }; const data: UserStatusDto = { - appMetadata: { - localized: null, - unlocalized: 'VS Code', - appIconB64: null, + presenceStatus: { + title: null, + subtitle: 'VS Code', + graphicsB64: null, }, state: UserState.IDLE, }; @@ -549,10 +549,10 @@ describe('StateGateway', () => { }; const data: UserStatusDto = { - appMetadata: { - localized: null, - unlocalized: 'VS Code', - appIconB64: null, + presenceStatus: { + title: null, + subtitle: 'VS Code', + graphicsB64: null, }, state: UserState.IDLE, }; @@ -572,10 +572,10 @@ describe('StateGateway', () => { data: {}, }; const data: UserStatusDto = { - appMetadata: { - localized: null, - unlocalized: 'VS Code', - appIconB64: null, + presenceStatus: { + title: null, + subtitle: 'VS Code', + graphicsB64: null, }, state: UserState.IDLE, }; @@ -605,10 +605,10 @@ describe('StateGateway', () => { ]); const data: UserStatusDto = { - appMetadata: { - localized: null, - unlocalized: 'VS Code', - appIconB64: null, + presenceStatus: { + title: null, + subtitle: 'VS Code', + graphicsB64: null, }, state: UserState.IDLE, };