1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

Create New Method for Setting Avatar Color from Sync (#8403)

This commit is contained in:
Justin Baur 2024-03-20 14:28:22 -05:00 committed by GitHub
parent 1400ec9c16
commit ec5c6b6797
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 1 deletions

View File

@ -15,6 +15,17 @@ export abstract class AvatarService {
* @returns a promise that resolves when the avatar color is set
*/
abstract setAvatarColor(color: string): Promise<void>;
/**
* 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<void>;
/**
* Gets the avatar color of the specified user.
*

View File

@ -27,6 +27,10 @@ export class AvatarService implements AvatarServiceAbstraction {
await this.stateProvider.setUserState(AVATAR_COLOR, avatarColor);
}
async setSyncAvatarColor(userId: UserId, color: string): Promise<void> {
await this.stateProvider.getUser(userId, AVATAR_COLOR).update(() => color);
}
getUserAvatarColor$(userId: UserId): Observable<string | null> {
return this.stateProvider.getUser(userId, AVATAR_COLOR).state$;
}

View File

@ -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);