Debian Codegraph @

xmpp-vala/src/module/xep/0048_conference.vala

raw
1 namespace Xmpp.Xep.Bookmarks {
2
3 public class Bookmarks1Conference : Conference {
4
5 public const string ATTRIBUTE_AUTOJOIN = "autojoin";
6 public const string ATTRIBUTE_JID = "jid";
7 public const string ATTRIBUTE_NAME = "name";
8
9 public const string NODE_NICK = "nick";
10 public const string NODE_PASSWORD = "password";
11
12 public StanzaNode stanza_node;
13
14 public override bool autojoin {
15 get {
16 string? attr = stanza_node.get_attribute(ATTRIBUTE_AUTOJOIN);
17 return attr == "true" || attr == "1";
18 }
19 set { stanza_node.set_attribute(ATTRIBUTE_AUTOJOIN, value.to_string()); }
20 }
21
22 private Jid jid_;
23 public override Jid? jid {
24 get {
25 try {
26 return jid_ ?? (jid_ = new Jid(stanza_node.get_attribute(ATTRIBUTE_JID)));
27 } catch (InvalidJidError e) {
28 return null;
29 }
30 }
31 set { stanza_node.set_attribute(ATTRIBUTE_JID, value.to_string()); }
32 }
33
34 public override string? name {
35 get { return stanza_node.get_attribute(ATTRIBUTE_NAME); }
36 set {
37 if (value == null) return; // TODO actually remove
38 stanza_node.set_attribute(ATTRIBUTE_NAME, value);
39 }
40 }
41
42 public override string? nick {
43 get {
44 StanzaNode? nick_node = stanza_node.get_subnode(NODE_NICK);
45 return nick_node == null ? null : nick_node.get_string_content();
46 }
47 set {
48 StanzaNode? nick_node = stanza_node.get_subnode(NODE_NICK);
49 if (value == null) {
50 if (nick_node != null) stanza_node.sub_nodes.remove(nick_node);
51 return;
52 }
53 if (nick_node == null) {
54 nick_node = new StanzaNode.build(NODE_NICK, NS_URI);
55 stanza_node.put_node(nick_node);
56 }
57 nick_node.sub_nodes.clear();
58 nick_node.put_node(new StanzaNode.text(value));
59 }
60 }
61
62 public override string? password {
63 get {
64 StanzaNode? password_node = stanza_node.get_subnode(NODE_PASSWORD);
65 return password_node == null ? null : password_node.get_string_content();
66 }
67 set {
68 StanzaNode? password_node = stanza_node.get_subnode(NODE_PASSWORD);
69 if (value == null) {
70 if (password_node != null) stanza_node.sub_nodes.remove(password_node);
71 return;
72 }
73 if (password_node == null) {
74 password_node = new StanzaNode.build(NODE_PASSWORD, NS_URI);
75 stanza_node.put_node(password_node);
76 }
77 password_node.sub_nodes.clear();
78 password_node.put_node(new StanzaNode.text(value));
79 }
80 }
81
82 public Bookmarks1Conference(Jid jid) {
83 this.stanza_node = new StanzaNode.build("conference", NS_URI);
84 this.jid = jid;
85 }
86
87 public static Conference? create_from_stanza_node(StanzaNode stanza_node) {
88 if (stanza_node.get_attribute(ATTRIBUTE_JID) != null) {
89 return new Bookmarks1Conference.from_stanza_node(stanza_node);
90 }
91 return null;
92 }
93
94 private Bookmarks1Conference.from_stanza_node(StanzaNode stanza_node) {
95 this.stanza_node = stanza_node;
96 }
97 }
98
99 }