presence status
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user