diff --git a/ts/components/dialog/DisplayPictureModal.tsx b/ts/components/dialog/DisplayPictureModal.tsx index 7cf18561b..96feefc74 100644 --- a/ts/components/dialog/DisplayPictureModal.tsx +++ b/ts/components/dialog/DisplayPictureModal.tsx @@ -61,6 +61,26 @@ export const DisplayPictureModal = (props: DisplayPictureModalProps) => { dispatch(updateDisplayPictureModel(null)); }; + const handleUpload = async () => { + setLoading(true); + if (newAvatarObjectUrl === _newAvatarObjectUrl) { + window.log.debug(`Avatar Object URL has not changed!`); + return; + } + + await uploadProfileAvatar(newAvatarObjectUrl); + setLoading(false); + closeDialog(); + }; + + const handleRemove = async () => { + setLoading(true); + await clearOurAvatar(); + setNewAvatarObjectUrl(null); + setOldAvatarPath(null); + setLoading(false); + }; + return ( { { - setLoading(true); - if (newAvatarObjectUrl === _newAvatarObjectUrl) { - window.log.debug(`Avatar Object URL has not changed!`); - return; - } - - await uploadProfileAvatar(newAvatarObjectUrl); - setLoading(false); - closeDialog(); - }} + onClick={handleUpload} disabled={_newAvatarObjectUrl === newAvatarObjectUrl} /> { - setLoading(true); - await clearOurAvatar(); - setNewAvatarObjectUrl(null); - setOldAvatarPath(null); - setLoading(false); - }} + onClick={handleRemove} disabled={!oldAvatarPath} /> diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 86a4df97c..c85185766 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -487,6 +487,9 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) { }; } +/** + * This function can be used for clearing our avatar. + */ export async function clearOurAvatar() { const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache()); if (!ourConvo) { @@ -500,6 +503,7 @@ export async function clearOurAvatar() { ourConvo.set('profileKey', undefined); await ourConvo.commit(); + await setLastProfileUpdateTimestamp(Date.now()); await SyncUtils.forceSyncConfigurationNowIfNeeded(true); // TODO send messages to opengroups to clear avatar from there