aboutsummaryrefslogtreecommitdiff
path: root/libdino/src
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2026-10-23 16:52:20 +0200
committerMarvin W <git@larma.de>2026-10-23 17:01:44 +0200
commitd314154abf1bf9a7f7ce20115c3c8c4512f73b15 (patch)
treece8c98fa6dbec50f696fedb644217057ddf151a0 /libdino/src
parentef925d1897d581cba0c61370f3aa9d80dac94b7c (diff)
libdino: Stop prefetching read_up_to message for each conversation
Diffstat (limited to 'libdino/src')
-rw-r--r--libdino/src/entity/conversation.vala31
-rw-r--r--libdino/src/service/chat_interaction.vala4
-rw-r--r--libdino/src/service/counterpart_interaction_manager.vala9
3 files changed, 21 insertions, 23 deletions
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index 40943132..8c1063c7 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -34,7 +34,7 @@ public class Conversation : Object {
}
}
public Encryption encryption { get; set; default = Encryption.UNKNOWN; }
- public Message? read_up_to { get; set; }
+ public int read_up_to_message_id { get; set; default=-1; }
public int read_up_to_item { get; set; default=-1; }
public enum NotifySetting { DEFAULT, ON, OFF, HIGHLIGHT }
@@ -69,9 +69,12 @@ public class Conversation : Object {
int64? last_active = row[db.conversation.last_active];
if (last_active != null) this.last_active = new DateTime.from_unix_utc(last_active);
encryption = (Encryption) row[db.conversation.encryption];
- int? read_up_to = row[db.conversation.read_up_to];
- if (read_up_to != null) this.read_up_to = db.get_message_by_id(read_up_to);
- read_up_to_item = row[db.conversation.read_up_to_item];
+ if (!db.conversation.read_up_to.is_null(row)) {
+ read_up_to_message_id = row[db.conversation.read_up_to];
+ }
+ if (!db.conversation.read_up_to_item.is_null(row)) {
+ read_up_to_item = row[db.conversation.read_up_to_item];
+ }
notify_setting = (NotifySetting) row[db.conversation.notification];
send_typing = (Setting) row[db.conversation.send_typing];
send_marker = (Setting) row[db.conversation.send_marker];
@@ -95,8 +98,8 @@ public class Conversation : Object {
.value(db.conversation.send_typing, send_typing)
.value(db.conversation.send_marker, send_marker)
.value(db.conversation.pinned, pinned);
- if (read_up_to != null) {
- insert.value(db.conversation.read_up_to, read_up_to.id);
+ if (read_up_to_message_id != -1) {
+ insert.value(db.conversation.read_up_to, read_up_to_message_id);
}
if (read_up_to_item != -1) {
insert.value(db.conversation.read_up_to_item, read_up_to_item);
@@ -167,20 +170,10 @@ public class Conversation : Object {
update.set(db.conversation.type_, type_); break;
case "encryption":
update.set(db.conversation.encryption, encryption); break;
- case "read-up-to":
- if (read_up_to != null) {
- update.set(db.conversation.read_up_to, read_up_to.id);
- } else {
- update.set_null(db.conversation.read_up_to);
- }
- break;
+ case "read-up-to-message-id":
+ update.set(db.conversation.read_up_to, read_up_to_message_id); break;
case "read-up-to-item":
- if (read_up_to_item != -1) {
- update.set(db.conversation.read_up_to_item, read_up_to_item);
- } else {
- update.set_null(db.conversation.read_up_to_item);
- }
- break;
+ update.set(db.conversation.read_up_to_item, read_up_to_item); break;
case "nickname":
update.set(db.conversation.resource, nickname); break;
case "active":
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala
index 9c8106a0..1e988382 100644
--- a/libdino/src/service/chat_interaction.vala
+++ b/libdino/src/service/chat_interaction.vala
@@ -152,7 +152,7 @@ public class ChatInteraction : StreamInteractionModule, Object {
if (conversation == null) return false;
Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_last_message(conversation);
if (message == null || message.direction == Entities.Message.DIRECTION_SENT) return false;
- if (message.equals(conversation.read_up_to)) return false;
+ if (message.id == conversation.read_up_to_message_id) return false;
bool sent_marker = yield send_and_mark_message_displayed(conversation, message);
return sent_marker;
@@ -224,7 +224,7 @@ public class ChatInteraction : StreamInteractionModule, Object {
if (message.type_ == Message.Type.GROUPCHAT) return false;
if (message.stanza_id == null) return false;
if (message.direction == Entities.Message.DIRECTION_SENT) return false;
- if (message.equals(conversation.read_up_to)) return false;
+ if (message.id == conversation.read_up_to_message_id) return false;
if (conversation.get_send_marker_setting(stream_interactor) != Conversation.Setting.ON) return false;
XmppStream? stream = stream_interactor.get_stream(conversation.account);
diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala
index f60cfb20..d6ca73a9 100644
--- a/libdino/src/service/counterpart_interaction_manager.vala
+++ b/libdino/src/service/counterpart_interaction_manager.vala
@@ -159,8 +159,13 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
public bool mark_displayed_up_to_message(Conversation conversation, Message message) {
// Don't move read marker backwards because we get old info from another client
- if (conversation.read_up_to != null && conversation.read_up_to.local_time.compare(message.local_time) > 0) return false;
- conversation.read_up_to = message;
+ if (conversation.read_up_to_message_id != -1) {
+ Message read_up_to_message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(conversation.read_up_to_message_id, conversation);
+ if (read_up_to_message.local_time.compare(message.local_time) > 0) {
+ return false;
+ }
+ }
+ conversation.read_up_to_message_id = message.id;
ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_content_item_for_message(conversation, message);
if (content_item == null) return true;