From ec5c6b6797b791cff8460346596362d2b9557bb7 Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Wed, 20 Mar 2024 14:28:22 -0500 Subject: [PATCH] Create New Method for Setting Avatar Color from Sync (#8403) --- libs/common/src/auth/abstractions/avatar.service.ts | 11 +++++++++++ libs/common/src/auth/services/avatar.service.ts | 4 ++++ libs/common/src/vault/services/sync/sync.service.ts | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libs/common/src/auth/abstractions/avatar.service.ts b/libs/common/src/auth/abstractions/avatar.service.ts index 1192ef745d..7da92ac7fd 100644 --- a/libs/common/src/auth/abstractions/avatar.service.ts +++ b/libs/common/src/auth/abstractions/avatar.service.ts @@ -15,6 +15,17 @@ export abstract class AvatarService { * @returns a promise that resolves when the avatar color is set */ abstract setAvatarColor(color: string): Promise; + /** + * Sets the avatar color for the given user, meant to be used via sync. + * + * @remarks This is meant to be used for getting an updated avatar color from + * the sync endpoint. If the user is changing their avatar color + * on device, you should instead call {@link setAvatarColor}. + * + * @param userId The user id for the user to set the avatar color for + * @param color The color to set the avatar color to + */ + abstract setSyncAvatarColor(userId: UserId, color: string): Promise; /** * Gets the avatar color of the specified user. * diff --git a/libs/common/src/auth/services/avatar.service.ts b/libs/common/src/auth/services/avatar.service.ts index b770dc39b9..9b8c83968d 100644 --- a/libs/common/src/auth/services/avatar.service.ts +++ b/libs/common/src/auth/services/avatar.service.ts @@ -27,6 +27,10 @@ export class AvatarService implements AvatarServiceAbstraction { await this.stateProvider.setUserState(AVATAR_COLOR, avatarColor); } + async setSyncAvatarColor(userId: UserId, color: string): Promise { + await this.stateProvider.getUser(userId, AVATAR_COLOR).update(() => color); + } + getUserAvatarColor$(userId: UserId): Observable { return this.stateProvider.getUser(userId, AVATAR_COLOR).state$; } diff --git a/libs/common/src/vault/services/sync/sync.service.ts b/libs/common/src/vault/services/sync/sync.service.ts index 1b3e63d001..654b1137f5 100644 --- a/libs/common/src/vault/services/sync/sync.service.ts +++ b/libs/common/src/vault/services/sync/sync.service.ts @@ -29,6 +29,7 @@ import { SendData } from "../../../tools/send/models/data/send.data"; import { SendResponse } from "../../../tools/send/models/response/send.response"; import { SendApiService } from "../../../tools/send/services/send-api.service.abstraction"; import { InternalSendService } from "../../../tools/send/services/send.service.abstraction"; +import { UserId } from "../../../types/guid"; import { CipherService } from "../../../vault/abstractions/cipher.service"; import { FolderApiServiceAbstraction } from "../../../vault/abstractions/folder/folder-api.service.abstraction"; import { InternalFolderService } from "../../../vault/abstractions/folder/folder.service.abstraction"; @@ -313,7 +314,7 @@ export class SyncService implements SyncServiceAbstraction { await this.cryptoService.setPrivateKey(response.privateKey); await this.cryptoService.setProviderKeys(response.providers); await this.cryptoService.setOrgKeys(response.organizations, response.providerOrganizations); - await this.avatarService.setAvatarColor(response.avatarColor); + await this.avatarService.setSyncAvatarColor(response.id as UserId, response.avatarColor); await this.stateService.setSecurityStamp(response.securityStamp); await this.stateService.setEmailVerified(response.emailVerified);