diff options
author | fiaxh <git@lightrise.org> | 2019-12-18 18:23:31 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-12-18 20:35:04 +0100 |
commit | 321c3529f3fedbd5eaa9cd619ee408fb683921ca (patch) | |
tree | 3743e39ee2a8225ed8d1c2bb1259e17b22a1fa47 /xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala | |
parent | 9fe8450571e49aaf376d07b379968c575bc0445c (diff) | |
download | dino-321c3529f3fedbd5eaa9cd619ee408fb683921ca.tar.gz dino-321c3529f3fedbd5eaa9cd619ee408fb683921ca.zip |
Add (partial) support for unique stanza ids (XEP-0359)
Diffstat (limited to 'xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala')
-rw-r--r-- | xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala b/xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala new file mode 100644 index 00000000..b6defc6d --- /dev/null +++ b/xmpp-vala/src/module/xep/0359_unique_stable_stanza_ids.vala @@ -0,0 +1,46 @@ +namespace Xmpp.Xep.UniqueStableStanzaIDs { + +private const string NS_URI = "urn:xmpp:sid:0"; + +private const string HINT_NO_PERMANENT_STORE = "no-permanent-store"; +private const string HINT_NO_STORE = "no-store"; +private const string HINT_NO_COPY = "no-copy"; +private const string HINT_STORE = "store"; + +public class Module : XmppStreamModule { + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0359_unique_and_stable_stanza_ids"); + + public override void attach(XmppStream stream) { + stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); + } + + public override void detach(XmppStream stream) {} + + public override string get_ns() { return NS_URI; } + + public override string get_id() { return IDENTITY.id; } +} + +public static void set_origin_id(MessageStanza message, string origin_id) { + StanzaNode hint_node = (new StanzaNode.build("origin-id", NS_URI)).add_self_xmlns().put_attribute("id", origin_id); + message.stanza.put_node(hint_node); +} + +public static string? get_origin_id(MessageStanza message) { + StanzaNode? node = message.stanza.get_subnode("origin-id", NS_URI); + if (node == null) return null; + + return node.get_attribute("id"); +} + +public static string? get_stanza_id(MessageStanza message, Jid by) { + string by_str = by.to_string(); + foreach (StanzaNode node in message.stanza.get_subnodes("stanza-id", NS_URI)) { + if (node.get_attribute("by") == by_str) { + return node.get_attribute("id"); + } + } + return null; +} + +} |