fix deduplication for opengroups v1 & v2

This commit is contained in:
Audric Ackermann 2021-04-28 15:53:30 +10:00
parent 0c0da48150
commit 6aa699ad23
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
6 changed files with 60 additions and 19 deletions

View file

@ -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,
}
);

View file

@ -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;

View file

@ -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;

View file

@ -415,7 +415,6 @@ export const deleteSingleMessage = async (
};
const messageDeletedResult = await sendOpenGroupV2Request(request);
const isOk = parseStatusCodeFromOnionRequest(messageDeletedResult) === 200;
console.warn('messageDeletedResult', messageDeletedResult);
return isOk;
};

View file

@ -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);
}

View file

@ -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;
}