| 1 |
namespace Xmpp.Xep.UniqueStableStanzaIDs { |
| 2 |
|
| 3 |
public const string NS_URI = "urn:xmpp:sid:0"; |
| 4 |
|
| 5 |
private const string HINT_NO_PERMANENT_STORE = "no-permanent-store"; |
| 6 |
private const string HINT_NO_STORE = "no-store"; |
| 7 |
private const string HINT_NO_COPY = "no-copy"; |
| 8 |
private const string HINT_STORE = "store"; |
| 9 |
|
| 10 |
public class Module : XmppStreamModule { |
| 11 |
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0359_unique_and_stable_stanza_ids"); |
| 12 |
|
| 13 |
public override void attach(XmppStream stream) { |
| 14 |
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); |
| 15 |
} |
| 16 |
|
| 17 |
public override void detach(XmppStream stream) { |
| 18 |
stream.get_module(ServiceDiscovery.Module.IDENTITY).remove_feature(stream, NS_URI); |
| 19 |
} |
| 20 |
|
| 21 |
public override string get_ns() { return NS_URI; } |
| 22 |
|
| 23 |
public override string get_id() { return IDENTITY.id; } |
| 24 |
} |
| 25 |
|
| 26 |
public static void set_origin_id(MessageStanza message, string origin_id) { |
| 27 |
StanzaNode hint_node = (new StanzaNode.build("origin-id", NS_URI)).add_self_xmlns().put_attribute("id", origin_id); |
| 28 |
message.stanza.put_node(hint_node); |
| 29 |
} |
| 30 |
|
| 31 |
public static string? get_origin_id(MessageStanza message) { |
| 32 |
StanzaNode? node = message.stanza.get_subnode("origin-id", NS_URI); |
| 33 |
if (node == null) return null; |
| 34 |
|
| 35 |
return node.get_attribute("id"); |
| 36 |
} |
| 37 |
|
| 38 |
public static string? get_stanza_id(MessageStanza message, Jid by) { |
| 39 |
string by_str = by.to_string(); |
| 40 |
foreach (StanzaNode node in message.stanza.get_subnodes("stanza-id", NS_URI)) { |
| 41 |
if (node.get_attribute("by") == by_str) { |
| 42 |
return node.get_attribute("id"); |
| 43 |
} |
| 44 |
} |
| 45 |
return null; |
| 46 |
} |
| 47 |
|
| 48 |
} |