disable deduplication based serverId+sender

only use the serverTimestamp+sender for searching because
serverId+sender might have false positive
pull/2039/head
Audric Ackermann 3 years ago
parent 8fea533124
commit af75b6f0e2
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -60,7 +60,6 @@ module.exports = {
getUnreadByConversation,
getUnreadCountByConversation,
getMessageBySender,
getMessageBySenderAndServerId,
getMessageBySenderAndServerTimestamp,
getMessageBySenderAndTimestamp,
getMessageIdsFromServerIds,
@ -2058,21 +2057,6 @@ function getMessageBySender({ source, sourceDevice, sentAt }) {
return map(rows, row => jsonToObject(row.json));
}
function getMessageBySenderAndServerId({ source, serverId }) {
const rows = globalInstance
.prepare(
`SELECT json FROM ${MESSAGES_TABLE} WHERE
source = $source AND
serverId = $serverId;`
)
.all({
source,
serverId,
});
return map(rows, row => jsonToObject(row.json));
}
function getMessageBySenderAndTimestamp({ source, timestamp }) {
const rows = globalInstance
.prepare(

@ -110,7 +110,6 @@ const channelsToMake = {
removeAllMessagesInConversation,
getMessageBySender,
getMessageBySenderAndServerId,
getMessageBySenderAndServerTimestamp,
getMessageBySenderAndTimestamp,
getMessageIdsFromServerIds,
@ -690,24 +689,6 @@ export async function getMessageBySender({
return new MessageModel(messages[0]);
}
export async function getMessageBySenderAndServerId({
source,
serverId,
}: {
source: string;
serverId: number;
}): Promise<MessageModel | null> {
const messages = await channels.getMessageBySenderAndServerId({
source,
serverId,
});
if (!messages || !messages.length) {
return null;
}
return new MessageModel(messages[0]);
}
export async function getMessageBySenderAndServerTimestamp({
source,
serverTimestamp,

@ -12,11 +12,7 @@ import { getConversationController } from '../session/conversations';
import { handleClosedGroupControlMessage } from './closedGroups';
import { MessageModel } from '../models/message';
import { MessageModelType } from '../models/messageType';
import {
getMessageBySender,
getMessageBySenderAndServerId,
getMessageBySenderAndServerTimestamp,
} from '../../ts/data/data';
import { getMessageBySender, getMessageBySenderAndServerTimestamp } from '../../ts/data/data';
import { ConversationModel, ConversationTypeEnum } from '../models/conversation';
import { allowOnlyOneAtATime } from '../session/utils/Promise';
import { toHex } from '../session/utils/String';
@ -368,22 +364,14 @@ export async function isMessageDuplicate({
try {
let result;
if (serverId || serverTimestamp) {
// first try to find a duplicate serverId from this sender
if (serverId) {
result = await getMessageBySenderAndServerId({
source,
serverId,
});
}
// if no result, try to find a duplicate with the same serverTimestamp from this sender
// first try to find a duplicate with the same serverTimestamp from this sender
if (!result && serverTimestamp) {
result = await getMessageBySenderAndServerTimestamp({
source,
serverTimestamp,
});
}
// if we have a result, it means a specific user sent two messages either with the same
// serverId or the same serverTimestamp.
// if we have a result, it means a specific user sent two messages either with the same serverTimestamp.
// no need to do anything else, those messages must be the same
// Note: this test is not based on which conversation the user sent the message
// but we consider that a user sending two messages with the same serverTimestamp is unlikely

Loading…
Cancel
Save