Skip to content

Commit 8b4268c

Browse files
committed
fix: attachment send while offline support is enabled
1 parent 896591e commit 8b4268c

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,15 +1203,18 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
12031203
if (updatedMessage.attachments?.length) {
12041204
for (let i = 0; i < updatedMessage.attachments?.length; i++) {
12051205
const attachment = updatedMessage.attachments[i];
1206-
const image = attachment.originalFile;
1207-
const file = attachment.originalFile;
1208-
// check if image_url is not a remote url
1206+
1207+
// If the attachment is already uploaded, skip it.
12091208
if (
1210-
attachment.type === FileTypes.Image &&
1211-
image?.uri &&
1212-
attachment.image_url &&
1213-
isLocalUrl(attachment.image_url)
1209+
(attachment.image_url && !isLocalUrl(attachment.image_url)) ||
1210+
(attachment.asset_url && !isLocalUrl(attachment.asset_url))
12141211
) {
1212+
continue;
1213+
}
1214+
1215+
const image = attachment.originalFile;
1216+
const file = attachment.originalFile;
1217+
if (attachment.type === FileTypes.Image && image?.uri) {
12151218
const filename = image.name ?? getFileNameFromPath(image.uri);
12161219
// if any upload is in progress, cancel it
12171220
const controller = uploadAbortControllerRef.current.get(filename);
@@ -1234,12 +1237,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
12341237
});
12351238
}
12361239

1237-
if (
1238-
attachment.type !== FileTypes.Image &&
1239-
attachment.asset_url &&
1240-
isLocalUrl(attachment.asset_url) &&
1241-
file?.uri
1242-
) {
1240+
if (attachment.type !== FileTypes.Image && file?.uri) {
12431241
// if any upload is in progress, cancel it
12441242
const controller = uploadAbortControllerRef.current.get(file.name);
12451243
if (controller) {

package/src/middlewares/attachments.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ import {
1313

1414
const localAttachmentToAttachment = (localAttachment: LocalAttachment) => {
1515
const { localMetadata, ...attachment } = localAttachment;
16+
1617
if (isLocalImageAttachment(localAttachment)) {
18+
const isRemoteUri = !!attachment.image_url;
19+
20+
if (isRemoteUri) return attachment as Attachment;
21+
1722
return {
1823
...attachment,
1924
image_url: localMetadata?.previewUri,
2025
originalFile: localMetadata.file,
2126
} as Attachment;
2227
} else {
28+
const isRemoteUri = !!attachment.asset_url;
29+
if (isRemoteUri) return attachment as Attachment;
30+
2331
return {
2432
...attachment,
2533
asset_url: (localMetadata.file as FileReference).uri,

package/src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const getUrlWithoutParams = (url?: string) => {
112112
return url.substring(0, url.indexOf('?'));
113113
};
114114

115-
export const isLocalUrl = (url: string) => url.includes('http');
115+
export const isLocalUrl = (url: string) => !url.includes('http');
116116

117117
export const generateRandomId = (a = ''): string =>
118118
a

0 commit comments

Comments
 (0)