Debian Codegraph @

xmpp-vala/src/module/roster/item.vala

raw
1 using Gee;
2
3 namespace Xmpp.Roster {
4
5 public class Item {
6
7 public const string SUBSCRIPTION_NONE = "none";
8 /** the user has a subscription to the contact's presence, but the contact does not have a subscription to the user's presence */
9 public const string SUBSCRIPTION_TO = "to";
10 /** the contact has a subscription to the user's presence, but the user does not have a subscription to the contact's presence */
11 public const string SUBSCRIPTION_FROM = "from";
12 public const string SUBSCRIPTION_BOTH = "both";
13 public const string SUBSCRIPTION_REMOVE = "remove";
14
15 public StanzaNode stanza_node;
16
17 private Jid jid_;
18 public Jid? jid {
19 get {
20 try {
21 return jid_ ?? (jid_ = new Jid(stanza_node.get_attribute("jid")));
22 } catch (InvalidJidError e) {
23 warning("Ignoring invalid Jid in roster entry: %s", e.message);
24 return null;
25 }
26 }
27 set { stanza_node.set_attribute("jid", value.to_string()); }
28 }
29
30 public string? name {
31 get { return stanza_node.get_attribute("name"); }
32 set { if (value != null) stanza_node.set_attribute("name", value); }
33 }
34
35 public string? subscription {
36 get { return stanza_node.get_attribute("subscription"); }
37 set { if (value != null) stanza_node.set_attribute("subscription", value); }
38 }
39
40 public string? ask {
41 get { return stanza_node.get_attribute("ask"); }
42 }
43
44 public bool subscription_requested {
45 get { return this.ask != null; }
46 }
47
48 public Item() {
49 stanza_node = new StanzaNode.build("item", NS_URI);
50 }
51
52 public Item.from_stanza_node(StanzaNode stanza_node) {
53 this.stanza_node = stanza_node;
54 }
55 }
56
57 }