feat: initial remove profile work done

pull/2765/head
William Grant 2 years ago
parent 88587a203d
commit cb7c36e2e6

@ -6,7 +6,7 @@ import { useDispatch } from 'react-redux';
import { updateDisplayPictureModel } from '../../state/ducks/modalDialog';
import { ProfileAvatar, ProfileAvatarProps } from './EditProfileDialog';
import styled from 'styled-components';
import { uploadOurAvatar } from '../../interactions/conversationInteractions';
import { clearOurAvatar, uploadOurAvatar } from '../../interactions/conversationInteractions';
import { ToastUtils } from '../../session/utils';
import { SessionSpinner } from '../basic/SessionSpinner';
@ -36,7 +36,6 @@ const uploadProfileAvatar = async (scaledAvatarUrl: string | null) => {
export type DisplayPictureModalProps = ProfileAvatarProps & {
avatarAction: () => Promise<string | null>;
removeAction: () => void;
};
export const DisplayPictureModal = (props: DisplayPictureModalProps) => {
@ -48,14 +47,14 @@ export const DisplayPictureModal = (props: DisplayPictureModalProps) => {
const {
newAvatarObjectUrl: _newAvatarObjectUrl,
oldAvatarPath,
oldAvatarPath: _oldAvatarPath,
profileName,
ourId,
avatarAction,
removeAction,
} = props;
const [newAvatarObjectUrl, setNewAvatarObjectUrl] = useState<string | null>(_newAvatarObjectUrl);
const [oldAvatarPath, setOldAvatarPath] = useState<string | null>(_oldAvatarPath);
const [loading, setLoading] = useState(false);
const closeDialog = () => {
@ -112,8 +111,12 @@ export const DisplayPictureModal = (props: DisplayPictureModalProps) => {
text={window.i18n('remove')}
buttonColor={SessionButtonColor.Danger}
buttonType={SessionButtonType.Simple}
onClick={() => {
removeAction();
onClick={async () => {
setLoading(true);
await clearOurAvatar();
setNewAvatarObjectUrl(null);
setOldAvatarPath(null);
setLoading(false);
}}
disabled={!oldAvatarPath}
/>

@ -233,7 +233,6 @@ export const EditProfileDialog = (): ReactElement => {
profileName,
ourId,
avatarAction: fireInputEvent,
removeAction: () => {},
})
);
};

@ -487,6 +487,24 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
};
}
export async function clearOurAvatar() {
const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache());
if (!ourConvo) {
window.log.warn('ourConvo not found... This is not a valid case');
return;
}
// TODO check if defined first
ourConvo.set('avatarPointer', undefined);
ourConvo.set('avatarInProfile', undefined);
ourConvo.set('profileKey', undefined);
await ourConvo.commit();
await SyncUtils.forceSyncConfigurationNowIfNeeded(true);
// TODO send messages to opengroups to clear avatar from there
}
export async function replyToMessage(messageId: string) {
const quotedMessageModel = await Data.getMessageById(messageId);
if (!quotedMessageModel) {

Loading…
Cancel
Save