Only assume UUID to be unique for one counterpart+account when deduplicating

This commit is contained in:
fiaxh 2018-03-07 21:17:15 +01:00
parent c8f68678be
commit c6ff25cc7a
2 changed files with 17 additions and 7 deletions

View file

@ -273,7 +273,6 @@ public class Database : Qlite.Database {
QueryBuilder builder = message.select()
.with(message.account_id, "=", account.id)
.with(message.counterpart_id, "=", get_jid_id(query_message.counterpart))
.with(message.counterpart_resource, "=", query_message.counterpart.resourcepart)
.with(message.body, "=", query_message.body)
.with(message.time, "<", (long) query_message.time.add_minutes(1).to_unix())
.with(message.time, ">", (long) query_message.time.add_minutes(-1).to_unix());
@ -282,14 +281,25 @@ public class Database : Qlite.Database {
} else {
builder.with_null(message.stanza_id);
}
if (query_message.counterpart.resourcepart != null) {
builder.with(message.counterpart_resource, "=", query_message.counterpart.resourcepart);
} else {
builder.with_null(message.counterpart_resource);
}
return builder.count() > 0;
}
public bool contains_message_by_stanza_id(string stanza_id, Account account) {
return message.select()
.with(message.stanza_id, "=", stanza_id)
.with(message.account_id, "=", account.id)
.count() > 0;
public bool contains_message_by_stanza_id(Message query_message, Account account) {
QueryBuilder builder = message.select()
.with(message.stanza_id, "=", query_message.stanza_id)
.with(message.counterpart_id, "=", get_jid_id(query_message.counterpart))
.with(message.account_id, "=", account.id);
if (query_message.counterpart.resourcepart != null) {
builder.with(message.counterpart_resource, "=", query_message.counterpart.resourcepart);
} else {
builder.with_null(message.counterpart_resource);
}
return builder.count() > 0;
}
public Message? get_message_by_id(int id) {

View file

@ -171,7 +171,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
bool is_uuid = message.stanza_id != null && Regex.match_simple("""[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}""", message.stanza_id);
bool new_uuid_msg = is_uuid && !db.contains_message_by_stanza_id(message.stanza_id, conversation.account);
bool new_uuid_msg = is_uuid && !db.contains_message_by_stanza_id(message, conversation.account);
bool new_misc_msg = !is_uuid && !db.contains_message(message, conversation.account);
bool new_msg = new_uuid_msg || new_misc_msg;
return !new_msg;