| 1 |
namespace Xmpp.Xep.Replies { |
| 2 |
|
| 3 |
public const string NS_URI = "urn:xmpp:reply:0"; |
| 4 |
|
| 5 |
public class ReplyTo { |
| 6 |
public Jid to_jid { get; set; } |
| 7 |
public string to_message_id { get; set; } |
| 8 |
|
| 9 |
public ReplyTo(Jid to_jid, string to_message_id) { |
| 10 |
this.to_jid = to_jid; |
| 11 |
this.to_message_id = to_message_id; |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
public static void set_reply_to(MessageStanza message, ReplyTo reply_to) { |
| 16 |
StanzaNode reply_node = (new StanzaNode.build("reply", NS_URI)) |
| 17 |
.add_self_xmlns() |
| 18 |
.put_attribute("to", reply_to.to_jid.to_string()) |
| 19 |
.put_attribute("id", reply_to.to_message_id); |
| 20 |
message.stanza.put_node(reply_node); |
| 21 |
} |
| 22 |
|
| 23 |
public ReplyTo? get_reply_to(MessageStanza message) { |
| 24 |
StanzaNode? reply_node = message.stanza.get_subnode("reply", NS_URI); |
| 25 |
if (reply_node == null) return null; |
| 26 |
|
| 27 |
string? to_str = reply_node.get_attribute("to"); |
| 28 |
if (to_str == null) return null; |
| 29 |
try { |
| 30 |
Jid to_jid = new Jid(to_str); |
| 31 |
|
| 32 |
string? id = reply_node.get_attribute("id"); |
| 33 |
if (id == null) return null; |
| 34 |
|
| 35 |
return new ReplyTo(to_jid, id); |
| 36 |
} catch (InvalidJidError e) { |
| 37 |
return null; |
| 38 |
} |
| 39 |
return null; |
| 40 |
} |
| 41 |
} |