Support for retry when sending media
This commit is contained in:
parent
881270f149
commit
ce6398685f
7 changed files with 69 additions and 34 deletions
|
|
@ -39,7 +39,6 @@ export type AttachmentSendInfo = {
|
|||
randomRotation: number; // For UI effects
|
||||
randomTranslationX: number; // For UI effects
|
||||
randomTranslationY: number; // For UI effects
|
||||
proofHintFlags?: ProofHintFlags;
|
||||
};
|
||||
|
||||
export type AttachmentThumbnail = {
|
||||
|
|
@ -59,6 +58,7 @@ export type Attachment = {
|
|||
useScaled: boolean;
|
||||
src?: string;
|
||||
proof?: Proof;
|
||||
proofHintFlags?: ProofHintFlags;
|
||||
thumbnail?: AttachmentThumbnail;
|
||||
sendInfo: AttachmentSendInfo;
|
||||
};
|
||||
|
|
@ -66,6 +66,7 @@ export type Attachment = {
|
|||
export type AttachmentBatch = {
|
||||
sendingStatus: Ref<AttachmentSendStatus>;
|
||||
sendingRootEventId: Ref<string | undefined>;
|
||||
sendingRootMessage: Ref<string | undefined>;
|
||||
progressPercent: Ref<number>;
|
||||
attachments: Attachment[];
|
||||
attachmentsSentCount: ComputedRef<number>;
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ export class AttachmentManager {
|
|||
}
|
||||
try {
|
||||
attachment.proof = await proofmode.proofCheckFile(file);
|
||||
attachment.proofHintFlags = extractProofHintFlags(attachment.proof);
|
||||
|
||||
// Default to scaled version if the image does not contain Content Credentials
|
||||
//
|
||||
|
|
@ -420,6 +421,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
|
||||
const sendingStatus: Ref<AttachmentSendStatus> = ref("initial");
|
||||
const sendingRootEventId: Ref<string | undefined> = ref(undefined);
|
||||
const sendingRootMessage: Ref<string | undefined> = ref(undefined);
|
||||
const sendingPromise: Ref<Promise<any> | undefined> = ref(undefined);
|
||||
const attachments: Ref<Attachment[]> = ref([]);
|
||||
|
||||
|
|
@ -528,6 +530,8 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
const send = async (message: string): Promise<any> => {
|
||||
if (!matrixClient || !room) return Promise.reject("Not configured");
|
||||
sendingStatus.value = "sending";
|
||||
progressPercent.value = 0;
|
||||
sendingRootMessage.value = message;
|
||||
|
||||
attachments.value.forEach((attachment) => {
|
||||
let sendInfo: AttachmentSendInfo = {
|
||||
|
|
@ -539,7 +543,6 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
randomTranslationX: 0,
|
||||
randomTranslationY: 0,
|
||||
promise: undefined,
|
||||
proofHintFlags: extractProofHintFlags(attachment.proof),
|
||||
};
|
||||
attachment.sendInfo = shallowReactive(sendInfo);
|
||||
attachment.proof = undefined;
|
||||
|
|
@ -555,6 +558,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
event.uploadBatch = {
|
||||
sendingStatus,
|
||||
sendingRootEventId,
|
||||
sendingRootMessage,
|
||||
progressPercent,
|
||||
attachments: unref(attachments),
|
||||
attachmentsSentCount,
|
||||
|
|
@ -572,8 +576,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
};
|
||||
room.on(RoomEvent.LocalEchoUpdated, onLocalEchoUpdated);
|
||||
|
||||
const promise = utils
|
||||
.sendTextMessage(matrixClient, room.roomId, message, undefined, undefined, txnId)
|
||||
const promise = (sendingRootEventId.value ? Promise.resolve(sendingRootEventId.value) : utils.sendTextMessage(matrixClient, room.roomId, message, undefined, undefined, txnId))
|
||||
.then((eventId: string) => {
|
||||
sendingRootEventId.value = eventId;
|
||||
|
||||
|
|
@ -582,7 +585,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
if (index < attachments.value.length) {
|
||||
const attachment = attachments.value[index];
|
||||
const item = attachment;
|
||||
if (item.sendInfo.status !== "initial") {
|
||||
if (item.sendInfo.status !== "initial" && item.sendInfo.status !== "failed") {
|
||||
return getItemPromise(++index);
|
||||
}
|
||||
item.sendInfo.status = "sending";
|
||||
|
|
@ -637,12 +640,13 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
item.sendInfo.status = "sent";
|
||||
item.sendInfo.statusDate = Date.now();
|
||||
})
|
||||
.catch((ignorederr: any) => {
|
||||
.catch((error: any) => {
|
||||
if (item.sendInfo.promise?.aborted) {
|
||||
item.sendInfo.status = "canceled";
|
||||
} else {
|
||||
console.error("ERROR", ignorederr);
|
||||
console.error("ERROR", error);
|
||||
item.sendInfo.status = "failed";
|
||||
return Promise.reject(error)
|
||||
}
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
|
@ -659,6 +663,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
})
|
||||
.catch((err: any) => {
|
||||
console.error("Upload error", err);
|
||||
sendingStatus.value = "failed";
|
||||
})
|
||||
.finally(() => {
|
||||
room.off(RoomEvent.LocalEchoUpdated, onLocalEchoUpdated);
|
||||
|
|
@ -670,6 +675,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
|
|||
return {
|
||||
sendingStatus,
|
||||
sendingRootEventId,
|
||||
sendingRootMessage,
|
||||
progressPercent,
|
||||
attachments: unref(attachments),
|
||||
attachmentsSentCount,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue