summaryrefslogtreecommitdiffstats
path: root/src/gui/Contact.vala
blob: d79cfffb8595b2dfc21523dfc793e92e1dd65f3b (plain)
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
52
53
54
55
56
57
58
59
public class Contact : Object {
  public enum Show {
    ONLINE, AWAY, CHAT, DND, XA, UNDEFINED
  }
  
  public enum Subscription {
    BOTH
  }
  
  public Contact(string jid0, string? name0) {
    Object(jid: jid0, name: name0);
    
    update_display_string();
  }
  
  public class Resource : Object {
    public Resource(int prio0, Show show0, string? status0) {
      Object(priority: prio0, show: show0, status: status0);
    }
    
    public int priority {get; construct;}
    public Show show {get; construct;}
    public string? status {get; construct;}
  }
  
  public string jid {get; construct;}
  public string? name {get; construct;}
  public Subscription subscription {get; set;}
  public Gee.TreeSet<string> groups = new Gee.TreeSet<string>();
  public string display_string {get; private set;}
  
  private Gee.HashMap<string, Resource> resources = new Gee.HashMap<string, Resource>();
  
  private void update_display_string() {
    if (name != null)
      display_string = name;
    else
      display_string = jid;
  }
  
  public Gee.Map.Entry<string, Resource>? get_resource_with_highest_priority() {
    int max_prio = int.MIN;
    Gee.Map.Entry<string, Resource> ret = null;
    
    foreach(Gee.Map.Entry<string, Resource> res in resources) {
      if(res.value.priority > max_prio) {
        max_prio = res.value.priority;
        ret = res;
      }
    }
    
    return ret;
  }
  
  public void update_resource(string resource_name, Resource resource) {
    resources[resource_name] = resource;
    update_display_string();
  }
}