Skip to content

Commit 691b051

Browse files
authored
fix: Resolve file attachment caching conflicts for identical filenames (#968)
* fix: resolve file attachment caching conflicts for identical filenames * chore: update android/ios version
1 parent d4905a9 commit 691b051

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default ({ config }: ConfigContext): ExpoConfig => {
44
return {
55
name: 'Chatwoot',
66
slug: process.env.EXPO_PUBLIC_APP_SLUG || 'chatwoot-mobile',
7-
version: '4.3.0',
7+
version: '4.3.10',
88
orientation: 'portrait',
99
icon: './assets/icon.png',
1010
userInterfaceStyle: 'light',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chatwoot/mobile-app",
3-
"version": "4.3.0",
3+
"version": "4.3.10",
44
"scripts": {
55
"start": "expo start --dev-client",
66
"start:production": "expo start --no-dev --minify",

src/screens/chat-screen/components/message-components/FileBubble.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ import { tailwind } from '@/theme';
99
import { Icon } from '@/components-next/common';
1010
import { Spinner } from '@/components-next/spinner';
1111
import { MESSAGE_VARIANTS } from '@/constants';
12+
13+
const generateUniqueFileName = (url: string, originalFileName: string) => {
14+
const hash = url.split('').reduce((acc, char) => {
15+
const charCode = char.charCodeAt(0);
16+
return ((acc << 5) - acc + charCode) | 0;
17+
}, 0);
18+
const uniqueHash = Math.abs(hash).toString(36);
19+
const fileExtension = originalFileName.includes('.')
20+
? originalFileName.substring(originalFileName.lastIndexOf('.'))
21+
: '';
22+
const baseFileName = originalFileName.includes('.')
23+
? originalFileName.substring(0, originalFileName.lastIndexOf('.'))
24+
: originalFileName;
25+
return `${baseFileName}_${uniqueHash}${fileExtension}`;
26+
};
27+
1228
type FilePreviewProps = Pick<FileBubbleProps, 'fileSrc'> & {
1329
isComposed?: boolean;
1430
variant: string;
@@ -20,7 +36,8 @@ export const FileBubblePreview = (props: FilePreviewProps) => {
2036

2137
const [fileDownload, setFileDownload] = useState(false);
2238
const fileName = fileSrc.split('/')[fileSrc.split('/').length - 1];
23-
const localFilePath = dirs.DocumentDir + `/${fileName}`;
39+
const uniqueFileName = generateUniqueFileName(fileSrc, fileName);
40+
const localFilePath = dirs.DocumentDir + `/${uniqueFileName}`;
2441

2542
const previewFile = () => {
2643
try {

0 commit comments

Comments
 (0)