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),
};

View file

@ -7226,13 +7226,6 @@
"reasonCategory": "falseMatch",
"updated": "2021-05-05T23:11:22.692Z"
},
{
"rule": "React-useRef",
"path": "ts/components/AvatarPreview.tsx",
"line": " const startingAvatarPathRef = useRef<undefined | string>(",
"reasonCategory": "usageTrusted",
"updated": "2021-08-03T21:17:38.615Z"
},
{
"rule": "React-useRef",
"path": "ts/components/AvatarTextEditor.tsx",
@ -8079,4 +8072,4 @@
"reasonCategory": "usageTrusted",
"updated": "2021-09-17T21:02:59.414Z"
}
]
]