feat: small refactoring

pull/2765/head
William Grant 2 years ago
parent cb7c36e2e6
commit 84d3d5b1b4

@ -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 (
<SessionWrapperModal
title={window.i18n('setDisplayPicture')}
@ -94,30 +114,14 @@ export const DisplayPictureModal = (props: DisplayPictureModalProps) => {
<SessionButton
text={window.i18n('upload')}
buttonType={SessionButtonType.Simple}
onClick={async () => {
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}
/>
<SessionButton
text={window.i18n('remove')}
buttonColor={SessionButtonColor.Danger}
buttonType={SessionButtonType.Simple}
onClick={async () => {
setLoading(true);
await clearOurAvatar();
setNewAvatarObjectUrl(null);
setOldAvatarPath(null);
setLoading(false);
}}
onClick={handleRemove}
disabled={!oldAvatarPath}
/>
</div>

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

Loading…
Cancel
Save