mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
fix deduplication for opengroups v1 & v2
This commit is contained in:
parent
0c0da48150
commit
6aa699ad23
6 changed files with 60 additions and 19 deletions
19
app/sql.js
19
app/sql.js
|
@ -72,6 +72,7 @@ module.exports = {
|
|||
getUnreadByConversation,
|
||||
getUnreadCountByConversation,
|
||||
getMessageBySender,
|
||||
getMessageBySenderAndServerId,
|
||||
getMessageIdsFromServerIds,
|
||||
getMessageById,
|
||||
getAllMessages,
|
||||
|
@ -1982,7 +1983,7 @@ async function getAllMessageIds() {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
async function getMessageBySender({ source, sourceDevice, sent_at }) {
|
||||
async function getMessageBySender({ source, sourceDevice, sentAt }) {
|
||||
const rows = await db.all(
|
||||
`SELECT json FROM ${MESSAGES_TABLE} WHERE
|
||||
source = $source AND
|
||||
|
@ -1991,7 +1992,21 @@ async function getMessageBySender({ source, sourceDevice, sent_at }) {
|
|||
{
|
||||
$source: source,
|
||||
$sourceDevice: sourceDevice,
|
||||
$sent_at: sent_at,
|
||||
$sent_at: sentAt,
|
||||
}
|
||||
);
|
||||
|
||||
return map(rows, row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getMessageBySenderAndServerId({ source, serverId }) {
|
||||
const rows = await db.all(
|
||||
`SELECT json FROM ${MESSAGES_TABLE} WHERE
|
||||
source = $source AND
|
||||
serverId = $serverId;`,
|
||||
{
|
||||
$source: source,
|
||||
$serverId: serverId,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@ const channelsToMake = {
|
|||
removeAllMessagesInConversation,
|
||||
|
||||
getMessageBySender,
|
||||
getMessageBySenderAndServerId,
|
||||
getMessageIdsFromServerIds,
|
||||
getMessageById,
|
||||
getAllMessages,
|
||||
|
@ -720,14 +721,37 @@ export async function getAllMessageIds(): Promise<Array<string>> {
|
|||
return ids;
|
||||
}
|
||||
|
||||
export async function getMessageBySender(
|
||||
// eslint-disable-next-line camelcase
|
||||
{ source, sourceDevice, sent_at }: { source: string; sourceDevice: number; sent_at: number }
|
||||
): Promise<MessageModel | null> {
|
||||
export async function getMessageBySender({
|
||||
source,
|
||||
sourceDevice,
|
||||
sentAt,
|
||||
}: {
|
||||
source: string;
|
||||
sourceDevice: number;
|
||||
sentAt: number;
|
||||
}): Promise<MessageModel | null> {
|
||||
const messages = await channels.getMessageBySender({
|
||||
source,
|
||||
sourceDevice,
|
||||
sent_at,
|
||||
sentAt,
|
||||
});
|
||||
if (!messages || !messages.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -768,7 +768,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
return null;
|
||||
}
|
||||
this.queueJob(async () => {
|
||||
console.warn('sending groupinvi', messageModel);
|
||||
await this.sendMessageJob(messageModel, expireTimer);
|
||||
});
|
||||
return null;
|
||||
|
|
|
@ -415,7 +415,6 @@ export const deleteSingleMessage = async (
|
|||
};
|
||||
const messageDeletedResult = await sendOpenGroupV2Request(request);
|
||||
const isOk = parseStatusCodeFromOnionRequest(messageDeletedResult) === 200;
|
||||
console.warn('messageDeletedResult', messageDeletedResult);
|
||||
return isOk;
|
||||
};
|
||||
|
||||
|
|
|
@ -177,8 +177,6 @@ const handleDeletions = async (
|
|||
const allRowIds = (deleted || []).map(d => d.id);
|
||||
const maxDeletedId = Math.max(...allRowIds);
|
||||
try {
|
||||
console.warn('We got deletion to do:', deleted, maxDeletedId);
|
||||
|
||||
const messageIds = await getMessageIdsFromServerIds(allIdsRemoved, conversationId);
|
||||
|
||||
await Promise.all(
|
||||
|
@ -253,7 +251,6 @@ const handleCompactPollResults = async (
|
|||
|
||||
// we want to do deletions even if we somehow lost the convo.
|
||||
if (res.deletions.length) {
|
||||
console.warn('res.deletions', res.deletions);
|
||||
// new deletions
|
||||
await handleDeletions(res.deletions, convoId, convo);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import { ConversationController } from '../session/conversations';
|
|||
import { handleClosedGroupControlMessage } from './closedGroups';
|
||||
import { MessageModel } from '../models/message';
|
||||
import { MessageModelType } from '../models/messageType';
|
||||
import { getMessageBySender } from '../../ts/data/data';
|
||||
import { getMessageBySender, getMessageBySenderAndServerId } from '../../ts/data/data';
|
||||
import { ConversationModel, ConversationTypeEnum } from '../models/conversation';
|
||||
import { DeliveryReceiptMessage } from '../session/messages/outgoing/controlMessage/receipt/DeliveryReceiptMessage';
|
||||
|
||||
|
@ -347,12 +347,19 @@ export async function isMessageDuplicate({
|
|||
const { Errors } = window.Signal.Types;
|
||||
// serverId is only used for opengroupv2
|
||||
try {
|
||||
const result = await getMessageBySender({
|
||||
source,
|
||||
sourceDevice,
|
||||
sent_at: timestamp,
|
||||
});
|
||||
|
||||
let result;
|
||||
if (serverId) {
|
||||
result = await getMessageBySenderAndServerId({
|
||||
source,
|
||||
serverId,
|
||||
});
|
||||
} else {
|
||||
result = await getMessageBySender({
|
||||
source,
|
||||
sourceDevice,
|
||||
sentAt: timestamp,
|
||||
});
|
||||
}
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue