diff --git a/app/sql.js b/app/sql.js index 217f7ba56..a1d421450 100644 --- a/app/sql.js +++ b/app/sql.js @@ -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( diff --git a/ts/data/data.ts b/ts/data/data.ts index c8c912086..8665a9da0 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -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 { - const messages = await channels.getMessageBySenderAndServerId({ - source, - serverId, - }); - if (!messages || !messages.length) { - return null; - } - - return new MessageModel(messages[0]); -} - export async function getMessageBySenderAndServerTimestamp({ source, serverTimestamp, diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index b41265c09..f0619d434 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -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