| 1 |
namespace Xmpp.Presence { |
| 2 |
|
| 3 |
public class Stanza : Xmpp.Stanza { |
| 4 |
|
| 5 |
public const string NODE_PRIORITY = "priority"; |
| 6 |
public const string NODE_STATUS = "status"; |
| 7 |
public const string NODE_SHOW = "show"; |
| 8 |
|
| 9 |
public const string SHOW_ONLINE = "online"; |
| 10 |
public const string SHOW_AWAY = "away"; |
| 11 |
public const string SHOW_CHAT = "chat"; |
| 12 |
public const string SHOW_DND = "dnd"; |
| 13 |
public const string SHOW_XA = "xa"; |
| 14 |
|
| 15 |
public const string TYPE_AVAILABLE = "available"; |
| 16 |
public const string TYPE_PROBE = "probe"; |
| 17 |
public const string TYPE_SUBSCRIBE = "subscribe"; |
| 18 |
public const string TYPE_SUBSCRIBED = "subscribed"; |
| 19 |
public const string TYPE_UNAVAILABLE = "unavailable"; |
| 20 |
public const string TYPE_UNSUBSCRIBE = "unsubscribe"; |
| 21 |
public const string TYPE_UNSUBSCRIBED = "unsubscribed"; |
| 22 |
|
| 23 |
public int priority { |
| 24 |
get { |
| 25 |
StanzaNode? priority_node = stanza.get_subnode(NODE_PRIORITY); |
| 26 |
if (priority_node == null) { |
| 27 |
return 0; |
| 28 |
} else { |
| 29 |
return int.parse(priority_node.get_string_content()); |
| 30 |
} |
| 31 |
} |
| 32 |
set { |
| 33 |
StanzaNode? priority_node = stanza.get_subnode(NODE_PRIORITY); |
| 34 |
if (priority_node == null) { |
| 35 |
priority_node = new StanzaNode.build(NODE_PRIORITY); |
| 36 |
stanza.put_node(priority_node); |
| 37 |
} |
| 38 |
priority_node.val = value.to_string(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public string? status { |
| 43 |
get { |
| 44 |
StanzaNode? status_node = stanza.get_subnode(NODE_STATUS); |
| 45 |
return status_node != null ? status_node.get_string_content() : null; |
| 46 |
} |
| 47 |
set { |
| 48 |
StanzaNode? status_node = stanza.get_subnode(NODE_STATUS); |
| 49 |
if (status_node == null) { |
| 50 |
status_node = new StanzaNode.build(NODE_STATUS); |
| 51 |
stanza.put_node(status_node); |
| 52 |
} |
| 53 |
status_node.val = value; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
public string show { |
| 58 |
get { |
| 59 |
StanzaNode? show_node = stanza.get_subnode(NODE_SHOW); |
| 60 |
if (show_node == null) { |
| 61 |
return SHOW_ONLINE; |
| 62 |
} |
| 63 |
return show_node.get_string_content() ?? SHOW_ONLINE; |
| 64 |
} |
| 65 |
set { |
| 66 |
if (value != SHOW_ONLINE) { |
| 67 |
StanzaNode? show_node = stanza.get_subnode(NODE_SHOW); |
| 68 |
if (show_node == null) { |
| 69 |
show_node = new StanzaNode.build(NODE_SHOW); |
| 70 |
stanza.put_node(show_node); |
| 71 |
} |
| 72 |
show_node.val = value; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
public override string? type_ { |
| 78 |
get { |
| 79 |
return base.type_ ?? TYPE_AVAILABLE; |
| 80 |
} |
| 81 |
set { base.type_ = value; } |
| 82 |
} |
| 83 |
|
| 84 |
public Stanza(string? id = null) { |
| 85 |
stanza = new StanzaNode.build("presence"); |
| 86 |
this.id = id ?? random_uuid(); |
| 87 |
} |
| 88 |
|
| 89 |
public Stanza.from_stanza(StanzaNode stanza_node, Jid my_jid) { |
| 90 |
base.incoming(stanza_node, my_jid); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
} |