mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
database: Only insert if there is no entry with same archive_id
archive_is is <stanza-id> or <result id=""> and should identify one message stable and uniquely. See XEP-0359: Unique and Stable Stanza IDs. We need this for example for this situation: * we go online with Profanity * we fetch all messages since yesterday * we add them to the db * we go offline * we go online with Profanity * we fetch all messages since yesterday * we only want to add the new ones So far we don't ask MAM "give me all since last 'id'" but since a certain date. In case no archive_id will be set, it will be `(null)` and thus should be inserted anyways because it won't find a value with (null) in that row. Because when adding we use `message->stanzaid ? message->stanzaid : "",` so it will be empty in such a case. Regards MAM: https://github.com/profanity-im/profanity/issues/660 Regards Stable IDs: https://github.com/profanity-im/profanity/issues/1207
This commit is contained in:
parent
8852db03d6
commit
c9b154b1a2
@ -110,8 +110,8 @@ log_database_init(ProfAccount* account)
|
||||
// message is the message text
|
||||
// timestamp the timestamp like "2020/03/24 11:12:14"
|
||||
// type is there to distinguish: message (chat), MUC message (muc), muc pm (mucpm)
|
||||
// stanza_id is the ID from XEP-0359: Unique and Stable Stanza IDs
|
||||
// archive_id is the ID from XEP-0313: Message Archive Management
|
||||
// stanza_id is the ID in <message>
|
||||
// archive_id is the stanza-id from from XEP-0359: Unique and Stable Stanza IDs used for XEP-0313: Message Archive Management
|
||||
// replace_id is the ID from XEP-0308: Last Message Correction
|
||||
// encryption is to distinguish: none, omemo, otr, pgp
|
||||
// marked_read is 0/1 whether a message has been marked as read via XEP-0333: Chat Markers
|
||||
@ -335,7 +335,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
|
||||
char* escaped_message = str_replace(message->plain, "'", "''");
|
||||
|
||||
if (asprintf(&query, "INSERT INTO `ChatLogs` (`from_jid`, `from_resource`, `to_jid`, `to_resource`, `message`, `timestamp`, `stanza_id`, `replace_id`, `type`, `encryption`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
|
||||
if (asprintf(&query, "INSERT INTO `ChatLogs` (`from_jid`, `from_resource`, `to_jid`, `to_resource`, `message`, `timestamp`, `stanza_id`, `archive_id`, `replace_id`, `type`, `encryption`) SELECT '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' WHERE NOT EXISTS (SELECT 1 FROM `ChatLogs` WHERE `archive_id` = '%s')",
|
||||
from_jid->barejid,
|
||||
from_jid->resourcepart ? from_jid->resourcepart : "",
|
||||
to_jid->barejid,
|
||||
@ -343,9 +343,11 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
escaped_message,
|
||||
date_fmt,
|
||||
message->id ? message->id : "",
|
||||
message->stanzaid ? message->stanzaid : "",
|
||||
message->replace_id ? message->replace_id : "",
|
||||
type,
|
||||
enc)
|
||||
enc,
|
||||
message->stanzaid)
|
||||
== -1) {
|
||||
log_error("log_database_add(): SQL query. could not allocate memory");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user