aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/fallback_body.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2023-01-06 13:19:42 +0100
committerfiaxh <git@lightrise.org>2023-01-06 14:03:54 +0100
commitdc52e7595cca06d0a2da7d11b3c88cb2f7ce529c (patch)
tree111f4a86a8541ce51bba7ec56f5b32197fcefc83 /libdino/src/service/fallback_body.vala
parent4d7809bb12199a598b531ca3ca019a4bb5a867f7 (diff)
downloaddino-dc52e7595cca06d0a2da7d11b3c88cb2f7ce529c.tar.gz
dino-dc52e7595cca06d0a2da7d11b3c88cb2f7ce529c.zip
Add support for XEP-0461 replies (with fallback)
Diffstat (limited to 'libdino/src/service/fallback_body.vala')
-rw-r--r--libdino/src/service/fallback_body.vala67
1 files changed, 67 insertions, 0 deletions
diff --git a/libdino/src/service/fallback_body.vala b/libdino/src/service/fallback_body.vala
new file mode 100644
index 00000000..cc9ba9a6
--- /dev/null
+++ b/libdino/src/service/fallback_body.vala
@@ -0,0 +1,67 @@
+using Gee;
+using Qlite;
+
+using Xmpp;
+using Xmpp.Xep;
+using Dino.Entities;
+
+public class Dino.FallbackBody : StreamInteractionModule, Object {
+ public static ModuleIdentity<FallbackBody> IDENTITY = new ModuleIdentity<FallbackBody>("fallback-body");
+ public string id { get { return IDENTITY.id; } }
+
+ private StreamInteractor stream_interactor;
+ private Database db;
+
+ private ReceivedMessageListener received_message_listener;
+
+ public static void start(StreamInteractor stream_interactor, Database db) {
+ FallbackBody m = new FallbackBody(stream_interactor, db);
+ stream_interactor.add_module(m);
+ }
+
+ private FallbackBody(StreamInteractor stream_interactor, Database db) {
+ this.stream_interactor = stream_interactor;
+ this.db = db;
+ this.received_message_listener = new ReceivedMessageListener(stream_interactor, db);
+
+ stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(received_message_listener);
+ }
+
+ private class ReceivedMessageListener : MessageListener {
+
+ public string[] after_actions_const = new string[]{ "STORE" };
+ public override string action_group { get { return "Quote"; } }
+ public override string[] after_actions { get { return after_actions_const; } }
+
+ private StreamInteractor stream_interactor;
+ private Database db;
+
+ public ReceivedMessageListener(StreamInteractor stream_interactor, Database db) {
+ this.stream_interactor = stream_interactor;
+ this.db = db;
+ }
+
+ public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) {
+ Gee.List<Xep.FallbackIndication.Fallback> fallbacks = Xep.FallbackIndication.get_fallbacks(stanza);
+ 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);
+ }
+
+ return false;
+ }
+ }
+} \ No newline at end of file