Optimize profile avatar uploads and sync urls

This commit is contained in:
Fedor Indutny 2022-03-15 17:14:20 -07:00 committed by GitHub
parent 703bb8a3a3
commit 36ce4f27a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 147 additions and 77 deletions

View file

@ -10,11 +10,12 @@ import {
encryptProfile,
encryptProfileItemWithPadding,
} from '../Crypto';
import type { AvatarUpdateType } from '../types/Avatar';
import { deriveProfileKeyCommitment, deriveProfileKeyVersion } from './zkgroup';
export async function encryptProfileData(
conversation: ConversationType,
avatarBuffer?: Uint8Array
{ oldAvatar, newAvatar }: AvatarUpdateType
): Promise<[ProfileRequestDataType, Uint8Array | undefined]> {
const {
aboutEmoji,
@ -55,10 +56,12 @@ export async function encryptProfileData(
)
: null;
const encryptedAvatarData = avatarBuffer
? encryptProfile(avatarBuffer, keyBuffer)
const encryptedAvatarData = newAvatar
? encryptProfile(newAvatar, keyBuffer)
: undefined;
const sameAvatar = Bytes.areEqual(oldAvatar, newAvatar);
const profileData = {
version: deriveProfileKeyVersion(profileKey, uuid),
name: Bytes.toBase64(bytesName),
@ -66,7 +69,8 @@ export async function encryptProfileData(
aboutEmoji: bytesAboutEmoji ? Bytes.toBase64(bytesAboutEmoji) : null,
badgeIds: (badges || []).map(({ id }) => id),
paymentAddress: window.storage.get('paymentAddress') || null,
avatar: Boolean(avatarBuffer),
avatar: Boolean(newAvatar),
sameAvatar,
commitment: deriveProfileKeyCommitment(profileKey, uuid),
};