From 63a16dce36fecc02cc9db42dcae85ae40dc82290 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 16 Jan 2023 17:24:58 +0100 Subject: MAM: Fix latest range not being stored in db if it contained a duplicate --- libdino/src/service/history_sync.vala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libdino/src') diff --git a/libdino/src/service/history_sync.vala b/libdino/src/service/history_sync.vala index 92a9e9e4..697d8edd 100644 --- a/libdino/src/service/history_sync.vala +++ b/libdino/src/service/history_sync.vala @@ -212,16 +212,18 @@ public class Dino.HistorySync { var query_params = new Xmpp.MessageArchiveManagement.V2.MamQueryParams.query_latest(mam_server, latest_message_time, latest_message_id); PageRequestResult page_result = yield get_mam_page(account, query_params, null); + debug("[%s | %s] Latest page result: %s", account.bare_jid.to_string(), mam_server.to_string(), page_result.page_result.to_string()); - if (page_result.page_result == PageResult.Error || page_result.page_result == PageResult.Duplicate) { - debug("MAM [%s | %s] Failed fetching latest page %s", mam_server.to_string(), mam_server.to_string(), page_result.page_result.to_string()); + if (page_result.page_result == PageResult.Error) { return null; } - print(@"MAM result: $(page_result.page_result))\n"); + // If we get PageResult.Duplicate, we still want to update the db row to the latest message. // Catchup finished within first page. Update latest db entry. - if (page_result.page_result in new PageResult[] { PageResult.TargetReached, PageResult.NoMoreMessages } && latest_row_id != -1) { + if (latest_row_id != -1 && + page_result.page_result in new PageResult[] { PageResult.TargetReached, PageResult.NoMoreMessages, PageResult.Duplicate }) { + if (page_result.stanzas == null || page_result.stanzas.is_empty) return null; string first_mam_id = page_result.query_result.first; @@ -265,7 +267,7 @@ public class Dino.HistorySync { .value(db.mam_catchup.server_jid, mam_server.to_string()) .value(db.mam_catchup.from_id, from_id) .value(db.mam_catchup.from_time, from_time) - .value(db.mam_catchup.from_end, false) + .value(db.mam_catchup.from_end, page_result.page_result == PageResult.NoMoreMessages) .value(db.mam_catchup.to_id, to_id) .value(db.mam_catchup.to_time, to_time) .perform(); -- cgit v1.2.3