2014-02-28 18:46:01 +01:00
|
|
|
package eu.siacs.conversations.entities;
|
2014-02-09 00:47:11 +01:00
|
|
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
2014-03-19 16:16:40 +01:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
2014-02-09 00:47:11 +01:00
|
|
|
public class Presences {
|
|
|
|
|
|
|
|
public static final int CHAT = -1;
|
|
|
|
public static final int ONLINE = 0;
|
|
|
|
public static final int AWAY = 1;
|
|
|
|
public static final int XA = 2;
|
|
|
|
public static final int DND = 3;
|
|
|
|
public static final int OFFLINE = 4;
|
|
|
|
|
|
|
|
private Hashtable<String, Integer> presences = new Hashtable<String, Integer>();
|
|
|
|
|
|
|
|
public Hashtable<String, Integer> getPresences() {
|
|
|
|
return this.presences;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePresence(String resource, int status) {
|
|
|
|
this.presences.put(resource, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removePresence(String resource) {
|
|
|
|
this.presences.remove(resource);
|
|
|
|
}
|
|
|
|
|
2014-04-16 19:14:20 +02:00
|
|
|
public void clearPresences() {
|
|
|
|
this.presences.clear();
|
|
|
|
}
|
|
|
|
|
2014-02-09 00:47:11 +01:00
|
|
|
public int getMostAvailableStatus() {
|
|
|
|
int status = OFFLINE;
|
|
|
|
Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Entry<String, Integer> entry = it.next();
|
|
|
|
if (entry.getValue()<status) status = entry.getValue();
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-03-19 16:16:40 +01:00
|
|
|
public static int parseShow(Element show) {
|
2014-07-01 14:53:39 +02:00
|
|
|
if ((show == null)||(show.getContent() == null)) {
|
2014-03-19 16:16:40 +01:00
|
|
|
return Presences.ONLINE;
|
|
|
|
} else if (show.getContent().equals("away")) {
|
|
|
|
return Presences.AWAY;
|
|
|
|
} else if (show.getContent().equals("xa")) {
|
|
|
|
return Presences.XA;
|
|
|
|
} else if (show.getContent().equals("chat")) {
|
|
|
|
return Presences.CHAT;
|
|
|
|
} else if (show.getContent().equals("dnd")) {
|
|
|
|
return Presences.DND;
|
|
|
|
} else {
|
|
|
|
return Presences.OFFLINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int size() {
|
|
|
|
return presences.size();
|
|
|
|
}
|
2014-06-11 21:53:25 +02:00
|
|
|
|
|
|
|
public String[] asStringArray() {
|
|
|
|
final String[] presencesArray = new String[presences.size()];
|
|
|
|
presences.keySet().toArray(presencesArray);
|
|
|
|
return presencesArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean has(String presence) {
|
|
|
|
return presences.containsKey(presence);
|
|
|
|
}
|
2014-02-09 00:47:11 +01:00
|
|
|
}
|