Skip to content

Commit 2b591ba

Browse files
committed
fix(chat): combine file messages by referenceId, not timestamp
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 810446a commit 2b591ba

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/utils/combineFileMessages.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ function isCombinableFileMessage(message: ChatMessage): boolean {
4949
return file.mimetype !== 'text/vcard' && !file.mimetype.startsWith('audio/')
5050
}
5151

52+
/**
53+
* Checks whether file share message referenceId follows the group pattern
54+
* (see prepareTemporaryMessage.ts for the format)
55+
*
56+
* @param id referenceId
57+
* @return uploadHash (repeating part for single context upload) or original referenceId
58+
*/
59+
function getUploadHashFromReferenceId(id: string): string {
60+
const [uploadHash, order] = id.split('-')
61+
if (uploadHash.length === 60 && Number.isInteger(+order)) {
62+
return uploadHash
63+
} else {
64+
return id
65+
}
66+
}
67+
5268
/**
5369
* Check whether two file shares belong to each other: they are replies to the same message
5470
* (or no replies at all) and they were shared together in a single context
@@ -58,10 +74,8 @@ function isCombinableFileMessage(message: ChatMessage): boolean {
5874
*/
5975
function canBeCombinedWith(message1: ChatMessage, message2: ChatMessage): boolean {
6076
return message1.parent?.id === message2.parent?.id
61-
// FIXME the timestamp is not a reliable indicator here, should instead
62-
// create referenceId differently (e.g. as `${SHA(uploadId) + SHA(Math.random())}`)
63-
// and base splitting on this (should be aligned with mobile clients as well)
64-
&& message1.timestamp - message2.timestamp <= 30
77+
&& !!message1.referenceId && !!message2.referenceId
78+
&& getUploadHashFromReferenceId(message1.referenceId) === getUploadHashFromReferenceId(message2.referenceId)
6579
}
6680

6781
/**

0 commit comments

Comments
 (0)