diff options
| author | fiaxh <git@lightrise.org> | 2025-06-13 19:37:27 +0200 |
|---|---|---|
| committer | fiaxh <git@lightrise.org> | 2025-06-13 19:37:27 +0200 |
| commit | 2e6454a92e85e87e17ce88924155d825b2b6eca3 (patch) | |
| tree | 201627b31fd28b02f75fbcb6a46376809e94a379 | |
| parent | 715b874801201390eb5ffe440acc4af171a9ddaa (diff) | |
Add support for whole body fallbacks
| -rw-r--r-- | libdino/src/entity/message.vala | 2 | ||||
| -rw-r--r-- | libdino/src/util/send_message.vala | 2 | ||||
| -rw-r--r-- | xmpp-vala/src/module/xep/0428_fallback_indication.vala | 40 |
3 files changed, 29 insertions, 15 deletions
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index e5aad25f..7e15cfe4 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -200,7 +200,7 @@ public class Message : Object { if (!fallbacks_by_ns.has_key(ns_uri)) { fallbacks_by_ns[ns_uri] = new ArrayList<Xep.FallbackIndication.FallbackLocation>(); } - fallbacks_by_ns[ns_uri].add(new Xep.FallbackIndication.FallbackLocation(row[db.body_meta.from_char], row[db.body_meta.to_char])); + fallbacks_by_ns[ns_uri].add(new Xep.FallbackIndication.FallbackLocation.partial_body(row[db.body_meta.from_char], row[db.body_meta.to_char])); break; case Xep.MessageMarkup.NS_URI: var types = new ArrayList<Xep.MessageMarkup.SpanType>(); diff --git a/libdino/src/util/send_message.vala b/libdino/src/util/send_message.vala index 234a1644..8312cf17 100644 --- a/libdino/src/util/send_message.vala +++ b/libdino/src/util/send_message.vala @@ -26,7 +26,7 @@ namespace Dino { out_message.body = fallback + out_message.body; // Store fallback location - var fallback_location = new Xep.FallbackIndication.FallbackLocation(0, (int)fallback.char_count()); + var fallback_location = new Xep.FallbackIndication.FallbackLocation.partial_body(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); diff --git a/xmpp-vala/src/module/xep/0428_fallback_indication.vala b/xmpp-vala/src/module/xep/0428_fallback_indication.vala index 6686b0ee..3cad689b 100644 --- a/xmpp-vala/src/module/xep/0428_fallback_indication.vala +++ b/xmpp-vala/src/module/xep/0428_fallback_indication.vala @@ -16,13 +16,19 @@ namespace Xmpp.Xep.FallbackIndication { } public class FallbackLocation { + public bool is_whole { get { return from_char == -1 && to_char == -1; } } public int from_char { get; set; } public int to_char { get; set; } - public FallbackLocation(int from_char, int to_char) { + public FallbackLocation.partial_body(int from_char, int to_char) { this.from_char = from_char; this.to_char = to_char; } + + public FallbackLocation.whole_body() { + this.from_char = -1; + this.to_char = -1; + } } public static void set_fallback(MessageStanza message, Fallback fallback) { @@ -30,10 +36,12 @@ namespace Xmpp.Xep.FallbackIndication { .add_self_xmlns() .put_attribute("for", fallback.ns_uri); foreach (FallbackLocation location in fallback.locations) { - fallback_node.put_node(new StanzaNode.build("body", NS_URI) - .add_self_xmlns() - .put_attribute("start", location.from_char.to_string()) - .put_attribute("end", location.to_char.to_string())); + var node = new StanzaNode.build("body", NS_URI).add_self_xmlns(); + if (!location.is_whole) { + node.put_attribute("start", location.from_char.to_string()) + .put_attribute("end", location.to_char.to_string()); + } + fallback_node.put_node(node); } message.stanza.put_node(fallback_node); } @@ -48,15 +56,21 @@ namespace Xmpp.Xep.FallbackIndication { string? ns_uri = fallback_node.get_attribute("for"); if (ns_uri == null) continue; - Gee.List<StanzaNode> body_nodes = fallback_node.get_subnodes("body", NS_URI); - if (body_nodes.is_empty) continue; - var locations = new ArrayList<FallbackLocation>(); - foreach (StanzaNode body_node in body_nodes) { - int start_char = body_node.get_attribute_int("start", -1); - int end_char = body_node.get_attribute_int("end", -1); - if (start_char == -1 || end_char == -1) continue; - locations.add(new FallbackLocation(start_char, end_char)); + if (fallback_node.get_all_subnodes().is_empty) { + locations.add(new FallbackLocation.whole_body()); + } else { + Gee.List<StanzaNode> body_nodes = fallback_node.get_subnodes("body", NS_URI); + foreach (StanzaNode body_node in body_nodes) { + int start_char = body_node.get_attribute_int("start", -1); + int end_char = body_node.get_attribute_int("end", -1); + if (start_char == -1 && end_char == -1) { + locations.add(new FallbackLocation.whole_body()); + continue; + } + if (start_char == -1 || end_char == -1) continue; + locations.add(new FallbackLocation.partial_body(start_char, end_char)); + } } if (locations.is_empty) continue; ret.add(new Fallback(ns_uri, locations.to_array())); |
