Fix missing group avatar on group link join
This commit is contained in:
parent
03d68c3137
commit
8b840ab442
1 changed files with 65 additions and 46 deletions
|
@ -13,6 +13,7 @@ import * as Errors from '../types/errors';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
import { HTTPError } from '../textsecure/Errors';
|
import { HTTPError } from '../textsecure/Errors';
|
||||||
import { SignalService as Proto } from '../protobuf';
|
import { SignalService as Proto } from '../protobuf';
|
||||||
|
import type { ContactAvatarType } from '../types/Avatar';
|
||||||
import { ToastType } from '../types/Toast';
|
import { ToastType } from '../types/Toast';
|
||||||
import {
|
import {
|
||||||
applyNewAvatar,
|
applyNewAvatar,
|
||||||
|
@ -32,6 +33,8 @@ import { longRunningTaskWrapper } from '../util/longRunningTaskWrapper';
|
||||||
import { sleep } from '../util/sleep';
|
import { sleep } from '../util/sleep';
|
||||||
import { dropNull } from '../util/dropNull';
|
import { dropNull } from '../util/dropNull';
|
||||||
import { getLocalAttachmentUrl } from '../util/getLocalAttachmentUrl';
|
import { getLocalAttachmentUrl } from '../util/getLocalAttachmentUrl';
|
||||||
|
import { type Loadable, LoadingState } from '../util/loadable';
|
||||||
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
|
|
||||||
export async function joinViaLink(value: string): Promise<void> {
|
export async function joinViaLink(value: string): Promise<void> {
|
||||||
let inviteLinkPassword: string;
|
let inviteLinkPassword: string;
|
||||||
|
@ -130,12 +133,14 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let localAvatar:
|
let localAvatar: Loadable<ContactAvatarType | undefined> = result.avatar
|
||||||
| {
|
? {
|
||||||
loading?: boolean;
|
loadingState: LoadingState.Loading,
|
||||||
path?: string;
|
|
||||||
}
|
}
|
||||||
| undefined = result.avatar ? { loading: true } : undefined;
|
: {
|
||||||
|
loadingState: LoadingState.Loaded,
|
||||||
|
value: undefined,
|
||||||
|
};
|
||||||
const memberCount = result.memberCount || 1;
|
const memberCount = result.memberCount || 1;
|
||||||
const approvalRequired =
|
const approvalRequired =
|
||||||
result.addFromInviteLink ===
|
result.addFromInviteLink ===
|
||||||
|
@ -178,16 +183,21 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
|
|
||||||
const getPreJoinConversation = (): PreJoinConversationType => {
|
const getPreJoinConversation = (): PreJoinConversationType => {
|
||||||
let avatar;
|
let avatar;
|
||||||
if (!localAvatar) {
|
if (localAvatar.loadingState === LoadingState.Loading) {
|
||||||
avatar = undefined;
|
|
||||||
} else if (localAvatar && localAvatar.loading) {
|
|
||||||
avatar = {
|
avatar = {
|
||||||
loading: true,
|
loading: true,
|
||||||
};
|
};
|
||||||
} else if (localAvatar && localAvatar.path) {
|
} else if (localAvatar.loadingState === LoadingState.Loaded) {
|
||||||
avatar = {
|
avatar =
|
||||||
url: getLocalAttachmentUrl(localAvatar),
|
localAvatar.value == null
|
||||||
};
|
? undefined
|
||||||
|
: {
|
||||||
|
url: getLocalAttachmentUrl(localAvatar.value),
|
||||||
|
};
|
||||||
|
} else if (localAvatar.loadingState === LoadingState.LoadFailed) {
|
||||||
|
avatar = undefined;
|
||||||
|
} else {
|
||||||
|
throw missingCaseError(localAvatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -211,8 +221,13 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
|
|
||||||
window.reduxActions.conversations.setPreJoinConversation(undefined);
|
window.reduxActions.conversations.setPreJoinConversation(undefined);
|
||||||
|
|
||||||
if (localAvatar && localAvatar.path) {
|
if (
|
||||||
await window.Signal.Migrations.deleteAttachmentData(localAvatar.path);
|
localAvatar?.loadingState === LoadingState.Loaded &&
|
||||||
|
localAvatar.value?.path
|
||||||
|
) {
|
||||||
|
await window.Signal.Migrations.deleteAttachmentData(
|
||||||
|
localAvatar.value.path
|
||||||
|
);
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -260,6 +275,15 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const avatar =
|
||||||
|
localAvatar?.loadingState === LoadingState.Loaded &&
|
||||||
|
localAvatar.value?.path &&
|
||||||
|
result.avatar
|
||||||
|
? {
|
||||||
|
url: result.avatar,
|
||||||
|
...localAvatar.value,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
if (!targetConversation) {
|
if (!targetConversation) {
|
||||||
// Note: we save this temp conversation in the database, so we'll need to
|
// Note: we save this temp conversation in the database, so we'll need to
|
||||||
// clean it up if something goes wrong
|
// clean it up if something goes wrong
|
||||||
|
@ -281,13 +305,8 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
left: true,
|
left: true,
|
||||||
revision: result.version,
|
revision: result.version,
|
||||||
|
|
||||||
avatar:
|
avatar,
|
||||||
localAvatar && localAvatar.path && result.avatar
|
|
||||||
? {
|
|
||||||
url: result.avatar,
|
|
||||||
path: localAvatar.path,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
description: groupDescription,
|
description: groupDescription,
|
||||||
groupInviteLinkPassword: inviteLinkPassword,
|
groupInviteLinkPassword: inviteLinkPassword,
|
||||||
name: title,
|
name: title,
|
||||||
|
@ -306,13 +325,7 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
targetConversation.set({
|
targetConversation.set({
|
||||||
// eslint-disable-next-line camelcase
|
// eslint-disable-next-line camelcase
|
||||||
active_at,
|
active_at,
|
||||||
avatar:
|
avatar,
|
||||||
localAvatar && localAvatar.path && result.avatar
|
|
||||||
? {
|
|
||||||
url: result.avatar,
|
|
||||||
path: localAvatar.path,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
description: groupDescription,
|
description: groupDescription,
|
||||||
groupInviteLinkPassword: inviteLinkPassword,
|
groupInviteLinkPassword: inviteLinkPassword,
|
||||||
left: true,
|
left: true,
|
||||||
|
@ -386,24 +399,28 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
|
|
||||||
// We declare a new function here so we can await but not block
|
// We declare a new function here so we can await but not block
|
||||||
const fetchAvatar = async () => {
|
const fetchAvatar = async () => {
|
||||||
if (result.avatar) {
|
if (!result.avatar) {
|
||||||
localAvatar = {
|
return;
|
||||||
loading: true,
|
}
|
||||||
};
|
localAvatar = {
|
||||||
|
loadingState: LoadingState.Loading,
|
||||||
|
};
|
||||||
|
|
||||||
let attributes: Pick<
|
let attributes: Pick<
|
||||||
ConversationAttributesType,
|
ConversationAttributesType,
|
||||||
'avatar' | 'secretParams'
|
'avatar' | 'secretParams'
|
||||||
> = {
|
> = {
|
||||||
avatar: null,
|
avatar: null,
|
||||||
secretParams,
|
secretParams,
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
const patch = await applyNewAvatar(result.avatar, attributes, logId);
|
const patch = await applyNewAvatar(result.avatar, attributes, logId);
|
||||||
attributes = { ...attributes, ...patch };
|
attributes = { ...attributes, ...patch };
|
||||||
|
|
||||||
if (attributes.avatar && attributes.avatar.path) {
|
if (attributes.avatar && attributes.avatar.path) {
|
||||||
localAvatar = {
|
localAvatar = {
|
||||||
...attributes.avatar,
|
loadingState: LoadingState.Loaded,
|
||||||
|
value: { ...attributes.avatar },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dialog has been dismissed; we'll delete the unneeeded avatar
|
// Dialog has been dismissed; we'll delete the unneeeded avatar
|
||||||
|
@ -414,14 +431,16 @@ export async function joinViaLink(value: string): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localAvatar = undefined;
|
localAvatar = { loadingState: LoadingState.Loaded, value: undefined };
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
// Update join dialog with newly-downloaded avatar
|
localAvatar = { loadingState: LoadingState.LoadFailed, error };
|
||||||
window.reduxActions.conversations.setPreJoinConversation(
|
|
||||||
getPreJoinConversation()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update join dialog with newly-downloaded avatar
|
||||||
|
window.reduxActions.conversations.setPreJoinConversation(
|
||||||
|
getPreJoinConversation()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
void fetchAvatar();
|
void fetchAvatar();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue