aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-07-26 19:10:35 +0200
committerfiaxh <git@lightrise.org>2024-07-29 13:15:14 +0200
commitceb921a0148f7fdc2a9df3e6b85143bf8c26c341 (patch)
treebdbfe4523453b29fa962d36121be40f5ee147e18
parentca980ea409b75025aa8218782d415ba9cf69e1c6 (diff)
downloaddino-ceb921a0148f7fdc2a9df3e6b85143bf8c26c341.tar.gz
dino-ceb921a0148f7fdc2a9df3e6b85143bf8c26c341.zip
Store reply message as sent, with fallback
-rw-r--r--libdino/src/entity/message.vala36
-rw-r--r--libdino/src/service/fallback_body.vala15
-rw-r--r--libdino/src/service/message_correction.vala2
-rw-r--r--libdino/src/service/message_processor.vala36
-rw-r--r--libdino/src/service/replies.vala15
-rw-r--r--main/src/ui/chat_input/chat_input_controller.vala13
6 files changed, 66 insertions, 51 deletions
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala
index 9d1cd43e..4e6c7f45 100644
--- a/libdino/src/entity/message.vala
+++ b/libdino/src/entity/message.vala
@@ -67,7 +67,7 @@ public class Message : Object {
}
}
public string? edit_to = null;
- public int quoted_item_id = 0;
+ public int quoted_item_id { get; private set; default=0; }
private Gee.List<Xep.FallbackIndication.Fallback> fallbacks = null;
@@ -142,6 +142,22 @@ public class Message : Object {
notify.connect(on_update);
}
+ public void set_quoted_item(int quoted_content_item_id) {
+ if (id == -1) {
+ warning("Message needs to be persisted before setting quoted item");
+ return;
+ }
+
+ this.quoted_item_id = quoted_content_item_id;
+
+ db.reply.upsert()
+ .value(db.reply.message_id, id, true)
+ .value(db.reply.quoted_content_item_id, quoted_content_item_id)
+ .value_null(db.reply.quoted_message_stanza_id)
+ .value_null(db.reply.quoted_message_from)
+ .perform();
+ }
+
public Gee.List<Xep.FallbackIndication.Fallback> get_fallbacks() {
if (fallbacks != null) return fallbacks;
@@ -165,7 +181,25 @@ public class Message : Object {
}
public void set_fallbacks(Gee.List<Xep.FallbackIndication.Fallback> fallbacks) {
+ if (id == -1) {
+ warning("Message needs to be persisted before setting fallbacks");
+ return;
+ }
+
this.fallbacks = fallbacks;
+
+ foreach (var fallback in fallbacks) {
+ foreach (var location in fallback.locations) {
+ db.body_meta.insert()
+ .value(db.body_meta.message_id, id)
+ .value(db.body_meta.info_type, Xep.FallbackIndication.NS_URI)
+ .value(db.body_meta.info, fallback.ns_uri)
+ .value(db.body_meta.from_char, location.from_char)
+ .value(db.body_meta.to_char, location.to_char)
+ .perform();
+ }
+ }
+
}
public void set_type_string(string type) {
diff --git a/libdino/src/service/fallback_body.vala b/libdino/src/service/fallback_body.vala
index 13323427..0ce89ade 100644
--- a/libdino/src/service/fallback_body.vala
+++ b/libdino/src/service/fallback_body.vala
@@ -46,20 +46,9 @@ public class Dino.FallbackBody : StreamInteractionModule, Object {
if (fallbacks.is_empty) return false;
foreach (var fallback in fallbacks) {
- if (fallback.ns_uri != Xep.Replies.NS_URI) continue;
-
- foreach (var location in fallback.locations) {
- db.body_meta.insert()
- .value(db.body_meta.message_id, message.id)
- .value(db.body_meta.info_type, Xep.FallbackIndication.NS_URI)
- .value(db.body_meta.info, fallback.ns_uri)
- .value(db.body_meta.from_char, location.from_char)
- .value(db.body_meta.to_char, location.to_char)
- .perform();
- }
-
- message.set_fallbacks(fallbacks);
+ if (fallback.ns_uri != Xep.Replies.NS_URI) continue; // TODO what if it's not
}
+ message.set_fallbacks(fallbacks);
return false;
}
diff --git a/libdino/src/service/message_correction.vala b/libdino/src/service/message_correction.vala
index 8f9770d8..6d4137d4 100644
--- a/libdino/src/service/message_correction.vala
+++ b/libdino/src/service/message_correction.vala
@@ -44,7 +44,7 @@ public class MessageCorrection : StreamInteractionModule, MessageListener {
Message out_message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(correction_text, conversation);
out_message.edit_to = stanza_id;
- out_message.quoted_item_id = old_message.quoted_item_id;
+ out_message.set_quoted_item(old_message.quoted_item_id);
outstanding_correction_nodes[out_message.stanza_id] = stanza_id;
stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(out_message, conversation);
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala
index baab37ce..620c93eb 100644
--- a/libdino/src/service/message_processor.vala
+++ b/libdino/src/service/message_processor.vala
@@ -406,8 +406,20 @@ public class MessageProcessor : StreamInteractionModule, Object {
new_message.type_ = MessageStanza.TYPE_CHAT;
}
- string? fallback = get_fallback_body_set_infos(message, new_message, conversation);
- new_message.body = fallback == null ? message.body : fallback + message.body;
+ if (message.quoted_item_id != 0) {
+ ContentItem? quoted_content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, message.quoted_item_id);
+ if (quoted_content_item != null) {
+ Jid? quoted_sender = message.from;
+ string? quoted_stanza_id = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(conversation, quoted_content_item);
+ if (quoted_sender != null && quoted_stanza_id != null) {
+ Xep.Replies.set_reply_to(new_message, new Xep.Replies.ReplyTo(quoted_sender, quoted_stanza_id));
+ }
+
+ foreach (var fallback in message.get_fallbacks()) {
+ Xep.FallbackIndication.set_fallback(new_message, fallback);
+ }
+ }
+ }
build_message_stanza(message, new_message, conversation);
pre_message_send(message, new_message, conversation);
@@ -456,26 +468,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
});
}
-
- public string? get_fallback_body_set_infos(Entities.Message message, MessageStanza new_stanza, Conversation conversation) {
- if (message.quoted_item_id == 0) return null;
-
- ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, message.quoted_item_id);
- if (content_item == null) return null;
-
- Jid? quoted_sender = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_sender_for_content_item(conversation, content_item);
- string? quoted_stanza_id = stream_interactor.get_module(ContentItemStore.IDENTITY).get_message_id_for_content_item(conversation, content_item);
- if (quoted_sender != null && quoted_stanza_id != null) {
- Xep.Replies.set_reply_to(new_stanza, new Xep.Replies.ReplyTo(quoted_sender, quoted_stanza_id));
- }
-
- string fallback = FallbackBody.get_quoted_fallback_body(content_item);
-
- var fallback_location = new Xep.FallbackIndication.FallbackLocation(0, (int)fallback.char_count());
- Xep.FallbackIndication.set_fallback(new_stanza, new Xep.FallbackIndication.Fallback(Xep.Replies.NS_URI, new Xep.FallbackIndication.FallbackLocation[] { fallback_location }));
-
- return fallback;
- }
}
public abstract class MessageListener : Xmpp.OrderedListener {
diff --git a/libdino/src/service/replies.vala b/libdino/src/service/replies.vala
index 58d44b37..cc9f43cc 100644
--- a/libdino/src/service/replies.vala
+++ b/libdino/src/service/replies.vala
@@ -38,17 +38,6 @@ public class Dino.Replies : StreamInteractionModule, Object {
return null;
}
- public void set_message_is_reply_to(Message message, ContentItem reply_to) {
- message.quoted_item_id = reply_to.id;
-
- db.reply.upsert()
- .value(db.reply.message_id, message.id, true)
- .value(db.reply.quoted_content_item_id, reply_to.id)
- .value_null(db.reply.quoted_message_stanza_id)
- .value_null(db.reply.quoted_message_from)
- .perform();
- }
-
private void on_incoming_message(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
// Check if a previous message was in reply to this one
var reply_qry = db.reply.select();
@@ -67,7 +56,7 @@ public class Dino.Replies : StreamInteractionModule, Object {
ContentItem? message_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_foreign(conversation, 1, message.id);
Message? reply_message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(reply_row[db.message.id], conversation);
if (message_item != null && reply_message != null) {
- set_message_is_reply_to(reply_message, message_item);
+ reply_message.set_quoted_item(message_item.id);
}
}
@@ -78,7 +67,7 @@ public class Dino.Replies : StreamInteractionModule, Object {
ContentItem? quoted_content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_content_item_for_message_id(conversation, reply_to.to_message_id);
if (quoted_content_item == null) return;
- set_message_is_reply_to(message, quoted_content_item);
+ message.set_quoted_item(quoted_content_item.id);
}
private class ReceivedMessageListener : MessageListener {
diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala
index d1c42d35..cf8e5a02 100644
--- a/main/src/ui/chat_input/chat_input_controller.vala
+++ b/main/src/ui/chat_input/chat_input_controller.vala
@@ -1,6 +1,7 @@
using Gee;
using Gdk;
using Gtk;
+using Xmpp;
using Dino.Entities;
@@ -195,7 +196,17 @@ public class ChatInputController : Object {
}
Message out_message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(text, conversation);
if (quoted_content_item_bak != null) {
- stream_interactor.get_module(Replies.IDENTITY).set_message_is_reply_to(out_message, quoted_content_item_bak);
+ out_message.set_quoted_item(quoted_content_item_bak.id);
+
+ // Store body with fallback
+ string fallback = FallbackBody.get_quoted_fallback_body(quoted_content_item_bak);
+ out_message.body = fallback + out_message.body;
+
+ // Store fallback location
+ var fallback_location = new Xep.FallbackIndication.FallbackLocation(0, (int)fallback.char_count());
+ var fallback_list = new ArrayList<Xep.FallbackIndication.Fallback>();
+ fallback_list.add(new Xep.FallbackIndication.Fallback(Xep.Replies.NS_URI, new Xep.FallbackIndication.FallbackLocation[] { fallback_location }));
+ out_message.set_fallbacks(fallback_list);
}
stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(out_message, conversation);
}