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

@ -233,7 +233,6 @@ export const EditProfileDialog = (): ReactElement => {
profileName, profileName,
ourId, ourId,
avatarAction: fireInputEvent, 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) { export async function replyToMessage(messageId: string) {
const quotedMessageModel = await Data.getMessageById(messageId); const quotedMessageModel = await Data.getMessageById(messageId);
if (!quotedMessageModel) { if (!quotedMessageModel) {

Loading…
Cancel
Save