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)); 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 ( return (
<SessionWrapperModal <SessionWrapperModal
title={window.i18n('setDisplayPicture')} title={window.i18n('setDisplayPicture')}
@ -94,30 +114,14 @@ export const DisplayPictureModal = (props: DisplayPictureModalProps) => {
<SessionButton <SessionButton
text={window.i18n('upload')} text={window.i18n('upload')}
buttonType={SessionButtonType.Simple} buttonType={SessionButtonType.Simple}
onClick={async () => { onClick={handleUpload}
setLoading(true);
if (newAvatarObjectUrl === _newAvatarObjectUrl) {
window.log.debug(`Avatar Object URL has not changed!`);
return;
}
await uploadProfileAvatar(newAvatarObjectUrl);
setLoading(false);
closeDialog();
}}
disabled={_newAvatarObjectUrl === newAvatarObjectUrl} disabled={_newAvatarObjectUrl === newAvatarObjectUrl}
/> />
<SessionButton <SessionButton
text={window.i18n('remove')} text={window.i18n('remove')}
buttonColor={SessionButtonColor.Danger} buttonColor={SessionButtonColor.Danger}
buttonType={SessionButtonType.Simple} buttonType={SessionButtonType.Simple}
onClick={async () => { onClick={handleRemove}
setLoading(true);
await clearOurAvatar();
setNewAvatarObjectUrl(null);
setOldAvatarPath(null);
setLoading(false);
}}
disabled={!oldAvatarPath} disabled={!oldAvatarPath}
/> />
</div> </div>

@ -487,6 +487,9 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
}; };
} }
/**
* This function can be used for clearing our avatar.
*/
export async function clearOurAvatar() { export async function clearOurAvatar() {
const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache()); const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache());
if (!ourConvo) { if (!ourConvo) {
@ -500,6 +503,7 @@ export async function clearOurAvatar() {
ourConvo.set('profileKey', undefined); ourConvo.set('profileKey', undefined);
await ourConvo.commit(); await ourConvo.commit();
await setLastProfileUpdateTimestamp(Date.now());
await SyncUtils.forceSyncConfigurationNowIfNeeded(true); await SyncUtils.forceSyncConfigurationNowIfNeeded(true);
// TODO send messages to opengroups to clear avatar from there // TODO send messages to opengroups to clear avatar from there

Loading…
Cancel
Save