Skip to content

Commit 8a66f6a

Browse files
authored
fix: send messages with successfully uploaded attachments only (#2704)
When link previews generation client-side was enabled, the failed upload attachments were also included in the sent message payload.
1 parent 98af293 commit 8a66f6a

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/components/MessageInput/hooks/useSubmitHandler.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ export const useSubmitHandler = <
8888
return addNotification(t('Wait until all attachments have uploaded'), 'error');
8989
}
9090

91-
const attachmentsFromUploads = attachments
92-
.filter(
93-
(att) =>
94-
att.localMetadata?.uploadState !== 'failed' ||
95-
(findAndEnqueueURLsToEnrich && !att.og_scrape_url), // filter out all the attachments scraped before the message was edited
96-
)
91+
const attachmentsWithoutLinkPreviews = attachments
92+
.filter((att) => {
93+
const isSuccessfulUpload = att.localMetadata?.uploadState === 'finished';
94+
const isNotUpload = !att.localMetadata?.uploadState;
95+
const isNotLinkPreview = !att.og_scrape_url;
96+
return isNotLinkPreview && (isSuccessfulUpload || isNotUpload);
97+
})
9798
.map((localAttachment) => {
9899
// eslint-disable-next-line @typescript-eslint/no-unused-vars
99100
const { localMetadata: _, ...attachment } = localAttachment;
@@ -116,14 +117,7 @@ export const useSubmitHandler = <
116117
attachmentsFromLinkPreviews = someLinkPreviewsLoading
117118
? []
118119
: Array.from(linkPreviews.values())
119-
.filter(
120-
(linkPreview) =>
121-
linkPreview.state === LinkPreviewState.LOADED &&
122-
!attachmentsFromUploads.find(
123-
(attFromUpload) =>
124-
attFromUpload.og_scrape_url === linkPreview.og_scrape_url,
125-
),
126-
)
120+
.filter((linkPreview) => linkPreview.state === LinkPreviewState.LOADED)
127121

128122
.map(
129123
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -137,7 +131,10 @@ export const useSubmitHandler = <
137131
someLinkPreviewsDismissed;
138132
}
139133

140-
const newAttachments = [...attachmentsFromUploads, ...attachmentsFromLinkPreviews];
134+
const newAttachments = [
135+
...attachmentsWithoutLinkPreviews,
136+
...attachmentsFromLinkPreviews,
137+
];
141138

142139
// Instead of checking if a user is still mentioned every time the text changes,
143140
// just filter out non-mentioned users before submit, which is cheaper

src/components/Poll/PollActions/PollResults/PollResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const pollStateSelector = <
2121
nextValue: PollState<StreamChatGenerics>,
2222
): PollStateSelectorReturnValue<StreamChatGenerics> => ({
2323
name: nextValue.name,
24-
options: nextValue.options,
24+
options: [...nextValue.options],
2525
vote_counts_by_option: nextValue.vote_counts_by_option,
2626
});
2727

yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,11 @@
10611061
dependencies:
10621062
regenerator-runtime "^0.14.0"
10631063

1064+
"@babel/runtime@^7.27.0":
1065+
version "7.27.1"
1066+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.1.tgz#9fce313d12c9a77507f264de74626e87fd0dc541"
1067+
integrity sha512-1x3D2xEk2fRo3PAhwQwu5UubzgiVWSXTBfWpVd2Mx2AzRqJuDJCsgaDVZ7HB5iGzDW1Hl1sWN2mFyKjmR9uAog==
1068+
10641069
"@babel/template@^7.16.7", "@babel/template@^7.24.7", "@babel/template@^7.3.3":
10651070
version "7.24.7"
10661071
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.24.7.tgz#02efcee317d0609d2c07117cb70ef8fb17ab7315"
@@ -12119,11 +12124,11 @@ [email protected]:
1211912124
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==
1212012125

1212112126
stream-chat@^8.55.0:
12122-
version "8.55.0"
12123-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.55.0.tgz#a4a651c4216185821a9d6b1ea55b6689a1a979a8"
12124-
integrity sha512-mdgB6LrDwCojf2xuHME2pnZIoIzAgd++CSsGlk9a+AUhmZMLnFFuMfg18uav3h9dKdRcRfFIgXe+raJgV6uIgA==
12127+
version "8.60.0"
12128+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.60.0.tgz#b67d4fbb185da53fb8ac5fc5759986d6ad7e19a3"
12129+
integrity sha512-7FpO7Wno++r+n+x9aFuXtGYtNO06CIMd2Bxe3doYZLhMfS0nuaXloeFlGcMT0r4U/6bnguz1qQdDJUPNQAS8bQ==
1212512130
dependencies:
12126-
"@babel/runtime" "^7.16.3"
12131+
"@babel/runtime" "^7.27.0"
1212712132
"@types/jsonwebtoken" "~9.0.0"
1212812133
"@types/ws" "^7.4.0"
1212912134
axios "^1.6.0"

0 commit comments

Comments
 (0)