2016-01-17 21:28:38 +00:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2018-04-22 09:07:00 +00:00
|
|
|
|
2016-02-19 10:09:28 +00:00
|
|
|
import java.util.Locale;
|
2016-01-17 21:28:38 +00:00
|
|
|
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
2021-01-21 15:47:30 +00:00
|
|
|
public class Presence implements Comparable<Presence> {
|
2016-01-17 21:28:38 +00:00
|
|
|
|
|
|
|
public enum Status {
|
|
|
|
CHAT, ONLINE, AWAY, XA, DND, OFFLINE;
|
|
|
|
|
|
|
|
public String toShowString() {
|
|
|
|
switch(this) {
|
|
|
|
case CHAT: return "chat";
|
|
|
|
case AWAY: return "away";
|
|
|
|
case XA: return "xa";
|
|
|
|
case DND: return "dnd";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-22 19:25:06 +00:00
|
|
|
|
|
|
|
public static Status fromShowString(String show) {
|
|
|
|
if (show == null) {
|
|
|
|
return ONLINE;
|
|
|
|
} else {
|
|
|
|
switch (show.toLowerCase(Locale.US)) {
|
|
|
|
case "away":
|
|
|
|
return AWAY;
|
|
|
|
case "xa":
|
|
|
|
return XA;
|
|
|
|
case "dnd":
|
|
|
|
return DND;
|
|
|
|
case "chat":
|
|
|
|
return CHAT;
|
|
|
|
default:
|
|
|
|
return ONLINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-17 21:28:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 12:20:11 +00:00
|
|
|
private final Status status;
|
|
|
|
private ServiceDiscoveryResult disco;
|
|
|
|
private final String ver;
|
|
|
|
private final String hash;
|
2018-04-14 16:43:11 +00:00
|
|
|
private final String node;
|
2016-05-12 12:20:11 +00:00
|
|
|
private final String message;
|
2016-01-17 21:46:32 +00:00
|
|
|
|
2018-04-14 16:43:11 +00:00
|
|
|
private Presence(Status status, String ver, String hash, String node, String message) {
|
2016-02-03 09:40:02 +00:00
|
|
|
this.status = status;
|
|
|
|
this.ver = ver;
|
|
|
|
this.hash = hash;
|
2018-04-14 16:43:11 +00:00
|
|
|
this.node = node;
|
2016-04-22 19:25:06 +00:00
|
|
|
this.message = message;
|
2016-02-03 09:40:02 +00:00
|
|
|
}
|
2016-01-17 21:28:38 +00:00
|
|
|
|
2016-04-22 19:25:06 +00:00
|
|
|
public static Presence parse(String show, Element caps, String message) {
|
2016-02-03 09:40:02 +00:00
|
|
|
final String hash = caps == null ? null : caps.getAttribute("hash");
|
|
|
|
final String ver = caps == null ? null : caps.getAttribute("ver");
|
2018-04-14 16:43:11 +00:00
|
|
|
final String node = caps == null ? null : caps.getAttribute("node");
|
|
|
|
return new Presence(Status.fromShowString(show), ver, hash, node, message);
|
2016-01-17 21:28:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 15:47:30 +00:00
|
|
|
public int compareTo(@NonNull Presence other) {
|
2021-01-23 08:25:34 +00:00
|
|
|
return this.status.compareTo(other.status);
|
2016-01-17 21:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status getStatus() {
|
|
|
|
return this.status;
|
|
|
|
}
|
2016-02-03 09:40:02 +00:00
|
|
|
|
|
|
|
public boolean hasCaps() {
|
|
|
|
return ver != null && hash != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getVer() {
|
|
|
|
return this.ver;
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:43:11 +00:00
|
|
|
public String getNode() {
|
|
|
|
return this.node;
|
|
|
|
}
|
|
|
|
|
2016-02-03 09:40:02 +00:00
|
|
|
public String getHash() {
|
|
|
|
return this.hash;
|
|
|
|
}
|
|
|
|
|
2016-05-12 12:20:11 +00:00
|
|
|
public String getMessage() {
|
|
|
|
return this.message;
|
|
|
|
}
|
|
|
|
|
2016-02-03 09:40:02 +00:00
|
|
|
public void setServiceDiscoveryResult(ServiceDiscoveryResult disco) {
|
|
|
|
this.disco = disco;
|
|
|
|
}
|
2016-05-12 12:20:11 +00:00
|
|
|
|
|
|
|
public ServiceDiscoveryResult getServiceDiscoveryResult() {
|
|
|
|
return disco;
|
|
|
|
}
|
2016-01-17 21:28:38 +00:00
|
|
|
}
|