Skip to content

Commit f2cc0ea

Browse files
authored
Merge pull request #1661 from session-foundation/fix-fs-changes-qa-2
fix: qa issues for fileserver changes 2
2 parents 75e79e6 + 673c115 commit f2cc0ea

File tree

7 files changed

+359
-114
lines changed

7 files changed

+359
-114
lines changed

ts/models/message.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,13 @@ export class MessageModel extends Model<MessageAttributes> {
826826
}ms. Attachments: ${attachments.map(m => m.url)}`
827827
);
828828

829+
this.setAttachments(
830+
this.getAttachments()?.map((a: any, index: number) => ({ ...a, url: attachments[index].url }))
831+
);
832+
// Note: we don't care about the fileUrl/fileId of previews, only of attachments as they are displayed in the message info
833+
834+
await this.commit();
835+
829836
return {
830837
body,
831838
attachments,

ts/session/utils/job_runners/jobs/AvatarReuploadJob.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ class AvatarReuploadJob extends PersistedJob<AvatarReuploadPersistedData> {
233233
ourConvo: conversation,
234234
context: 'reuploadAvatar',
235235
});
236+
if (!details?.avatarPointer) {
237+
window.log.warn(
238+
`[avatarReupload] failed to reupload avatar for ${ed25519Str(conversation.id)}`
239+
);
240+
throw new Error('details.avatarPointer is not valid after uploadAndSetOurAvatarShared');
241+
}
236242
window.log.info(
237243
`[avatarReupload] reupload done for ${ed25519Str(conversation.id)}: ${details?.avatarPointer}`
238244
);

ts/types/attachments/VisualAttachment.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ export async function pickFileForAvatar(): Promise<ProcessedAvatarDataType | nul
238238
} catch (e) {
239239
ToastUtils.pushToastError(
240240
'pickFileForAvatar',
241-
`An error happened while picking/resizing the image: "${e.message?.slice(200) || ''}"`
241+
`An error happened while picking/resizing the image: "${
242+
e.message.slice(0, e.message.indexOf('\n')).slice(0, 200) || ''
243+
}"`
242244
);
243245
window.log.error(e);
244246
return null;

ts/util/avatar/processAvatarData.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function processAvatarData(arrayBuffer: ArrayBuffer, planForReuploa
3838
// sanity check the returned data
3939
if (mainAvatarDetails.format !== 'webp' && mainAvatarDetails.format !== 'gif') {
4040
throw new Error(
41-
'processLocalAvatarChange: we only support animated mainAvatarDetails in webp after conversion'
41+
'processLocalAvatarChange: we only support animated mainAvatarDetails in webp or gif after conversion'
4242
);
4343
}
4444

@@ -56,9 +56,7 @@ export async function processAvatarData(arrayBuffer: ArrayBuffer, planForReuploa
5656
}
5757

5858
if (mainAvatarDetails.size >= MAX_ATTACHMENT_FILESIZE_BYTES) {
59-
throw new Error(
60-
'processLocalAvatarChange: mainAvatarDetails size is too big after conversion (bigger than fs limit'
61-
);
59+
throw new Error('Provided image is too big after conversion. Please use another image.');
6260
}
6361

6462
return { mainAvatarDetails, avatarFallback };

ts/webworker/worker_interface.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ export class WorkerInterface {
4343
const { resolve, reject, fnName } = job;
4444

4545
if (errorForDisplay) {
46-
// eslint:disable: no-console
47-
4846
window?.log?.error(`Error received from worker job ${jobId} (${fnName}):`, errorForDisplay);
49-
return reject(
50-
new Error(`Error received from worker job ${jobId} (${fnName}): ${errorForDisplay}`)
51-
);
47+
// Note: don't wrap this with a prefix as we want to be able to show what was the error as is to the user in a toast.
48+
// If you want to add something, add it at the end.
49+
return reject(new Error(errorForDisplay));
5250
}
5351

5452
return resolve(result);

ts/webworker/workers/node/image_processor/image_processor.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export type ProcessedLinkPreviewThumbnailType = NonNullable<
4444
export type ImageProcessorWorkerActions = {
4545
/**
4646
* Process an avatar. Depending on if we want this to be reuploaded or not, we allow gif as a return format or not.
47-
* The reason is that when we plan for reupload, we don't convert gif to webp, as we want to keep the original gif.
47+
* The reason is that when we plan for reupload, we don't **always** convert gif to webp, as we might want to keep it as gif.
48+
* We will try to convert an input gif to webp, but if it takes too long or the resulting file size is too big, we will just use the original gif.
4849
* When the change is not planned for reupload, we convert everything to a webp.
4950
* This function will generate a mainAvatar, and a fallbackAvatar if needed.
5051
*

0 commit comments

Comments
 (0)