aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/roster/item.vala
blob: 78974a357c3d453cee77fd87697740665c2fe5bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Gee;

namespace Xmpp.Roster {

public class Item {

    public const string NODE_JID = "jid";
    public const string NODE_NAME = "name";
    public const string NODE_SUBSCRIPTION = "subscription";

    public const string SUBSCRIPTION_NONE = "none";
    public const string SUBSCRIPTION_TO = "to";
    public const string SUBSCRIPTION_FROM = "from";
    public const string SUBSCRIPTION_BOTH = "both";
    public const string SUBSCRIPTION_REMOVE = "remove";

    public StanzaNode stanza_node;

    private Jid jid_;
    public Jid? jid {
        get {
            try {
                return jid_ ?? (jid_ = new Jid(stanza_node.get_attribute(NODE_JID)));
            } catch (InvalidJidError e) {
                warning("Ignoring invalid Jid in roster entry: %s", e.message);
                return null;
            }
        }
        set { stanza_node.set_attribute(NODE_JID, value.to_string()); }
    }

    public string? name {
        get { return stanza_node.get_attribute(NODE_NAME); }
        set { if (value != null) stanza_node.set_attribute(NODE_NAME, value); }
    }

    public string? subscription {
        get { return stanza_node.get_attribute(NODE_SUBSCRIPTION); }
        set { if (value != null) stanza_node.set_attribute(NODE_SUBSCRIPTION, value); }
    }

    public Item() {
        stanza_node = new StanzaNode.build("item", NS_URI);
    }

    public Item.from_stanza_node(StanzaNode stanza_node) {
        this.stanza_node = stanza_node;
    }
}

}