1package eu.siacs.conversations.entities;
2
3import java.lang.Comparable;
4
5import eu.siacs.conversations.xml.Element;
6
7public class Presence implements Comparable {
8
9 public enum Status {
10 CHAT, ONLINE, AWAY, XA, DND, OFFLINE;
11
12 public String toShowString() {
13 switch(this) {
14 case CHAT: return "chat";
15 case AWAY: return "away";
16 case XA: return "xa";
17 case DND: return "dnd";
18 }
19
20 return null;
21 }
22 }
23
24 protected final Status status;
25
26 public Presence(Element show) {
27 if ((show == null) || (show.getContent() == null)) {
28 this.status = Status.ONLINE;
29 } else if (show.getContent().equals("away")) {
30 this.status = Status.AWAY;
31 } else if (show.getContent().equals("xa")) {
32 this.status = Status.XA;
33 } else if (show.getContent().equals("chat")) {
34 this.status = Status.CHAT;
35 } else if (show.getContent().equals("dnd")) {
36 this.status = Status.DND;
37 } else {
38 this.status = Status.OFFLINE;
39 }
40 }
41
42 public int compareTo(Object other) {
43 return this.status.compareTo(((Presence)other).status);
44 }
45
46 public Status getStatus() {
47 return this.status;
48 }
49}