Fix save profile avatar disappearing on save name/bio
Co-authored-by: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com>
This commit is contained in:
parent
74dd88f917
commit
df00d4b9f4
5 changed files with 34 additions and 38 deletions
|
@ -7,7 +7,7 @@ import type { AvatarColorType } from '../types/Colors';
|
||||||
import { AvatarColors } from '../types/Colors';
|
import { AvatarColors } from '../types/Colors';
|
||||||
import type {
|
import type {
|
||||||
AvatarDataType,
|
AvatarDataType,
|
||||||
AvatarUpdateType,
|
AvatarUpdateOptionsType,
|
||||||
DeleteAvatarFromDiskActionType,
|
DeleteAvatarFromDiskActionType,
|
||||||
ReplaceAvatarActionType,
|
ReplaceAvatarActionType,
|
||||||
SaveAvatarToDiskActionType,
|
SaveAvatarToDiskActionType,
|
||||||
|
@ -59,7 +59,7 @@ type PropsExternalType = {
|
||||||
onEditStateChanged: (editState: EditState) => unknown;
|
onEditStateChanged: (editState: EditState) => unknown;
|
||||||
onProfileChanged: (
|
onProfileChanged: (
|
||||||
profileData: ProfileDataType,
|
profileData: ProfileDataType,
|
||||||
avatar: AvatarUpdateType
|
avatarUpdateOptions: AvatarUpdateOptionsType
|
||||||
) => unknown;
|
) => unknown;
|
||||||
renderEditUsernameModalBody: (props: {
|
renderEditUsernameModalBody: (props: {
|
||||||
isRootModal: boolean;
|
isRootModal: boolean;
|
||||||
|
@ -199,9 +199,6 @@ export function ProfileEditor({
|
||||||
const [avatarBuffer, setAvatarBuffer] = useState<Uint8Array | undefined>(
|
const [avatarBuffer, setAvatarBuffer] = useState<Uint8Array | undefined>(
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
const [isLoadingAvatar, setIsLoadingAvatar] = useState(
|
|
||||||
Boolean(profileAvatarPath)
|
|
||||||
);
|
|
||||||
const [stagedProfile, setStagedProfile] = useState<ProfileDataType>({
|
const [stagedProfile, setStagedProfile] = useState<ProfileDataType>({
|
||||||
aboutEmoji,
|
aboutEmoji,
|
||||||
aboutText,
|
aboutText,
|
||||||
|
@ -252,7 +249,10 @@ export function ProfileEditor({
|
||||||
? trim(stagedProfile.familyName)
|
? trim(stagedProfile.familyName)
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
{ oldAvatar: oldAvatarBuffer, newAvatar: avatar }
|
{
|
||||||
|
keepAvatar: false,
|
||||||
|
avatarUpdate: { oldAvatar: oldAvatarBuffer, newAvatar: avatar },
|
||||||
|
}
|
||||||
);
|
);
|
||||||
setOldAvatarBuffer(avatar);
|
setOldAvatarBuffer(avatar);
|
||||||
},
|
},
|
||||||
|
@ -289,9 +289,8 @@ export function ProfileEditor({
|
||||||
avatar => {
|
avatar => {
|
||||||
setAvatarBuffer(avatar);
|
setAvatarBuffer(avatar);
|
||||||
setOldAvatarBuffer(avatar);
|
setOldAvatarBuffer(avatar);
|
||||||
setIsLoadingAvatar(false);
|
|
||||||
},
|
},
|
||||||
[setAvatarBuffer, setOldAvatarBuffer, setIsLoadingAvatar]
|
[setAvatarBuffer, setOldAvatarBuffer]
|
||||||
);
|
);
|
||||||
|
|
||||||
let content: JSX.Element;
|
let content: JSX.Element;
|
||||||
|
@ -387,10 +386,7 @@ export function ProfileEditor({
|
||||||
familyName: stagedProfile.familyName,
|
familyName: stagedProfile.familyName,
|
||||||
});
|
});
|
||||||
|
|
||||||
onProfileChanged(stagedProfile, {
|
onProfileChanged(stagedProfile, { keepAvatar: true });
|
||||||
oldAvatar: oldAvatarBuffer,
|
|
||||||
newAvatar: avatarBuffer,
|
|
||||||
});
|
|
||||||
handleBack();
|
handleBack();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -401,9 +397,8 @@ export function ProfileEditor({
|
||||||
);
|
);
|
||||||
} else if (editState === EditState.Bio) {
|
} else if (editState === EditState.Bio) {
|
||||||
const shouldDisableSave =
|
const shouldDisableSave =
|
||||||
isLoadingAvatar ||
|
stagedProfile.aboutText === fullBio.aboutText &&
|
||||||
(stagedProfile.aboutText === fullBio.aboutText &&
|
stagedProfile.aboutEmoji === fullBio.aboutEmoji;
|
||||||
stagedProfile.aboutEmoji === fullBio.aboutEmoji);
|
|
||||||
|
|
||||||
const defaultBios = getDefaultBios(i18n);
|
const defaultBios = getDefaultBios(i18n);
|
||||||
|
|
||||||
|
@ -505,10 +500,7 @@ export function ProfileEditor({
|
||||||
aboutText: stagedProfile.aboutText,
|
aboutText: stagedProfile.aboutText,
|
||||||
});
|
});
|
||||||
|
|
||||||
onProfileChanged(stagedProfile, {
|
onProfileChanged(stagedProfile, { keepAvatar: true });
|
||||||
oldAvatar: oldAvatarBuffer,
|
|
||||||
newAvatar: avatarBuffer,
|
|
||||||
});
|
|
||||||
handleBack();
|
handleBack();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { ConfirmationDialog } from './ConfirmationDialog';
|
||||||
import type { PropsType as ProfileEditorPropsType } from './ProfileEditor';
|
import type { PropsType as ProfileEditorPropsType } from './ProfileEditor';
|
||||||
import { ProfileEditor, EditState } from './ProfileEditor';
|
import { ProfileEditor, EditState } from './ProfileEditor';
|
||||||
import type { ProfileDataType } from '../state/ducks/conversations';
|
import type { ProfileDataType } from '../state/ducks/conversations';
|
||||||
import type { AvatarUpdateType } from '../types/Avatar';
|
import type { AvatarUpdateOptionsType } from '../types/Avatar';
|
||||||
|
|
||||||
export type PropsDataType = {
|
export type PropsDataType = {
|
||||||
hasError: boolean;
|
hasError: boolean;
|
||||||
|
@ -16,7 +16,7 @@ export type PropsDataType = {
|
||||||
type PropsType = {
|
type PropsType = {
|
||||||
myProfileChanged: (
|
myProfileChanged: (
|
||||||
profileData: ProfileDataType,
|
profileData: ProfileDataType,
|
||||||
avatar: AvatarUpdateType
|
avatarUpdateOptions: AvatarUpdateOptionsType
|
||||||
) => unknown;
|
) => unknown;
|
||||||
toggleProfileEditor: () => unknown;
|
toggleProfileEditor: () => unknown;
|
||||||
toggleProfileEditorHasError: () => unknown;
|
toggleProfileEditorHasError: () => unknown;
|
||||||
|
|
|
@ -13,22 +13,15 @@ import { strictAssert } from '../util/assert';
|
||||||
import { isWhitespace } from '../util/whitespaceStringUtil';
|
import { isWhitespace } from '../util/whitespaceStringUtil';
|
||||||
import { imagePathToBytes } from '../util/imagePathToBytes';
|
import { imagePathToBytes } from '../util/imagePathToBytes';
|
||||||
import { getAbsoluteProfileAvatarPath } from '../util/avatarUtils';
|
import { getAbsoluteProfileAvatarPath } from '../util/avatarUtils';
|
||||||
import type { AvatarUpdateType } from '../types/Avatar';
|
import type {
|
||||||
|
AvatarUpdateOptionsType,
|
||||||
|
AvatarUpdateType,
|
||||||
|
} from '../types/Avatar';
|
||||||
import MessageSender from '../textsecure/SendMessage';
|
import MessageSender from '../textsecure/SendMessage';
|
||||||
|
|
||||||
export type WriteProfileOptionsType = Readonly<
|
|
||||||
| {
|
|
||||||
keepAvatar: true;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
keepAvatar?: false;
|
|
||||||
avatarUpdate: AvatarUpdateType;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
export async function writeProfile(
|
export async function writeProfile(
|
||||||
conversation: ConversationType,
|
conversation: ConversationType,
|
||||||
options: WriteProfileOptionsType
|
options: AvatarUpdateOptionsType
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { server } = window.textsecure;
|
const { server } = window.textsecure;
|
||||||
if (!server) {
|
if (!server) {
|
||||||
|
|
|
@ -92,7 +92,10 @@ import {
|
||||||
getMessagesByConversation,
|
getMessagesByConversation,
|
||||||
} from '../selectors/conversations';
|
} from '../selectors/conversations';
|
||||||
import { getIntl } from '../selectors/user';
|
import { getIntl } from '../selectors/user';
|
||||||
import type { AvatarDataType, AvatarUpdateType } from '../../types/Avatar';
|
import type {
|
||||||
|
AvatarDataType,
|
||||||
|
AvatarUpdateOptionsType,
|
||||||
|
} from '../../types/Avatar';
|
||||||
import { getDefaultAvatars } from '../../types/Avatar';
|
import { getDefaultAvatars } from '../../types/Avatar';
|
||||||
import { getAvatarData } from '../../util/getAvatarData';
|
import { getAvatarData } from '../../util/getAvatarData';
|
||||||
import { isSameAvatarData } from '../../util/isSameAvatarData';
|
import { isSameAvatarData } from '../../util/isSameAvatarData';
|
||||||
|
@ -2051,7 +2054,7 @@ function saveAvatarToDisk(
|
||||||
|
|
||||||
function myProfileChanged(
|
function myProfileChanged(
|
||||||
profileData: ProfileDataType,
|
profileData: ProfileDataType,
|
||||||
avatarUpdate: AvatarUpdateType
|
avatarUpdateOptions: AvatarUpdateOptionsType
|
||||||
): ThunkAction<
|
): ThunkAction<
|
||||||
void,
|
void,
|
||||||
RootStateType,
|
RootStateType,
|
||||||
|
@ -2067,9 +2070,7 @@ function myProfileChanged(
|
||||||
...conversation,
|
...conversation,
|
||||||
...profileData,
|
...profileData,
|
||||||
},
|
},
|
||||||
{
|
avatarUpdateOptions
|
||||||
avatarUpdate,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// writeProfile above updates the backbone model which in turn updates
|
// writeProfile above updates the backbone model which in turn updates
|
||||||
|
|
|
@ -76,6 +76,16 @@ export type AvatarUpdateType = Readonly<{
|
||||||
newAvatar: Uint8Array | undefined;
|
newAvatar: Uint8Array | undefined;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
export type AvatarUpdateOptionsType = Readonly<
|
||||||
|
| {
|
||||||
|
keepAvatar: false;
|
||||||
|
avatarUpdate: AvatarUpdateType;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
keepAvatar: true;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
const groupIconColors = [
|
const groupIconColors = [
|
||||||
'A180',
|
'A180',
|
||||||
'A120',
|
'A120',
|
||||||
|
|
Loading…
Add table
Reference in a new issue