Merge branch 'disco-caps' of https://github.com/singpolyma/Conversations into singpolyma-disco-caps
This commit is contained in:
commit
4a1a59f0c8
|
@ -136,17 +136,17 @@ public class Contact implements ListItem, Blockable {
|
||||||
tags.add(new Tag(group, UIHelper.getColorForName(group)));
|
tags.add(new Tag(group, UIHelper.getColorForName(group)));
|
||||||
}
|
}
|
||||||
switch (getMostAvailableStatus()) {
|
switch (getMostAvailableStatus()) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
tags.add(new Tag("online", 0xff259b24));
|
tags.add(new Tag("online", 0xff259b24));
|
||||||
break;
|
break;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
tags.add(new Tag("away", 0xffff9800));
|
tags.add(new Tag("away", 0xffff9800));
|
||||||
break;
|
break;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
tags.add(new Tag("not available", 0xfff44336));
|
tags.add(new Tag("not available", 0xfff44336));
|
||||||
break;
|
break;
|
||||||
case Presences.DND:
|
case DND:
|
||||||
tags.add(new Tag("dnd", 0xfff44336));
|
tags.add(new Tag("dnd", 0xfff44336));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -226,8 +226,8 @@ public class Contact implements ListItem, Blockable {
|
||||||
this.presences = pres;
|
this.presences = pres;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePresence(final String resource, final int status) {
|
public void updatePresence(final String resource, final Presence presence) {
|
||||||
this.presences.updatePresence(resource, status);
|
this.presences.updatePresence(resource, presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePresence(final String resource) {
|
public void removePresence(final String resource) {
|
||||||
|
@ -239,8 +239,13 @@ public class Contact implements ListItem, Blockable {
|
||||||
this.resetOption(Options.PENDING_SUBSCRIPTION_REQUEST);
|
this.resetOption(Options.PENDING_SUBSCRIPTION_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMostAvailableStatus() {
|
public Presence.Status getMostAvailableStatus() {
|
||||||
return this.presences.getMostAvailableStatus();
|
Presence p = this.presences.getMostAvailablePresence();
|
||||||
|
if (p == null) {
|
||||||
|
return Presence.Status.OFFLINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setPhotoUri(String uri) {
|
public boolean setPhotoUri(String uri) {
|
||||||
|
|
52
src/main/java/eu/siacs/conversations/entities/Presence.java
Normal file
52
src/main/java/eu/siacs/conversations/entities/Presence.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
|
import java.lang.Comparable;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.xml.Element;
|
||||||
|
|
||||||
|
public class Presence implements Comparable {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Status status;
|
||||||
|
protected final ServiceDiscoveryResult disco;
|
||||||
|
|
||||||
|
public Presence(Element show, ServiceDiscoveryResult disco) {
|
||||||
|
this.disco = disco;
|
||||||
|
|
||||||
|
if ((show == null) || (show.getContent() == null)) {
|
||||||
|
this.status = Status.ONLINE;
|
||||||
|
} else if (show.getContent().equals("away")) {
|
||||||
|
this.status = Status.AWAY;
|
||||||
|
} else if (show.getContent().equals("xa")) {
|
||||||
|
this.status = Status.XA;
|
||||||
|
} else if (show.getContent().equals("chat")) {
|
||||||
|
this.status = Status.CHAT;
|
||||||
|
} else if (show.getContent().equals("dnd")) {
|
||||||
|
this.status = Status.DND;
|
||||||
|
} else {
|
||||||
|
this.status = Status.OFFLINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(Object other) {
|
||||||
|
return this.status.compareTo(((Presence)other).status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +1,21 @@
|
||||||
package eu.siacs.conversations.entities;
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
|
|
||||||
public class Presences {
|
public class Presences {
|
||||||
|
private final Hashtable<String, Presence> presences = new Hashtable<>();
|
||||||
|
|
||||||
public static final int CHAT = -1;
|
public Hashtable<String, Presence> getPresences() {
|
||||||
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 final Hashtable<String, Integer> presences = new Hashtable<>();
|
|
||||||
|
|
||||||
public Hashtable<String, Integer> getPresences() {
|
|
||||||
return this.presences;
|
return this.presences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePresence(String resource, int status) {
|
public void updatePresence(String resource, Presence presence) {
|
||||||
synchronized (this.presences) {
|
synchronized (this.presences) {
|
||||||
this.presences.put(resource, status);
|
this.presences.put(resource, presence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,32 +31,10 @@ public class Presences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMostAvailableStatus() {
|
public Presence getMostAvailablePresence() {
|
||||||
int status = OFFLINE;
|
|
||||||
synchronized (this.presences) {
|
synchronized (this.presences) {
|
||||||
Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
|
if (presences.size() < 1) { return null; }
|
||||||
while (it.hasNext()) {
|
return Collections.min(presences.values());
|
||||||
Entry<String, Integer> entry = it.next();
|
|
||||||
if (entry.getValue() < status)
|
|
||||||
status = entry.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int parseShow(Element show) {
|
|
||||||
if ((show == null) || (show.getContent() == null)) {
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,242 @@
|
||||||
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.util.Base64;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.Comparable;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.xml.Element;
|
||||||
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
|
|
||||||
|
public class ServiceDiscoveryResult {
|
||||||
|
public static final String TABLENAME = "discovery_results";
|
||||||
|
public static final String HASH = "hash";
|
||||||
|
public static final String VER = "ver";
|
||||||
|
public static final String RESULT = "result";
|
||||||
|
|
||||||
|
protected static String blankNull(String s) {
|
||||||
|
return s == null ? "" : s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Identity implements Comparable {
|
||||||
|
protected final String category;
|
||||||
|
protected final String type;
|
||||||
|
protected final String lang;
|
||||||
|
protected final String name;
|
||||||
|
|
||||||
|
public Identity(final String category, final String type, final String lang, final String name) {
|
||||||
|
this.category = category;
|
||||||
|
this.type = type;
|
||||||
|
this.lang = lang;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Identity(final Element el) {
|
||||||
|
this(
|
||||||
|
el.getAttribute("category"),
|
||||||
|
el.getAttribute("type"),
|
||||||
|
el.getAttribute("xml:lang"),
|
||||||
|
el.getAttribute("name")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Identity(final JSONObject o) {
|
||||||
|
this(
|
||||||
|
o.optString("category", null),
|
||||||
|
o.optString("type", null),
|
||||||
|
o.optString("lang", null),
|
||||||
|
o.optString("name", null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return this.category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLang() {
|
||||||
|
return this.lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(Object other) {
|
||||||
|
Identity o = (Identity)other;
|
||||||
|
int r = blankNull(this.getCategory()).compareTo(blankNull(o.getCategory()));
|
||||||
|
if(r == 0) {
|
||||||
|
r = blankNull(this.getType()).compareTo(blankNull(o.getType()));
|
||||||
|
}
|
||||||
|
if(r == 0) {
|
||||||
|
r = blankNull(this.getLang()).compareTo(blankNull(o.getLang()));
|
||||||
|
}
|
||||||
|
if(r == 0) {
|
||||||
|
r = blankNull(this.getName()).compareTo(blankNull(o.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
try {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
o.put("category", this.getCategory());
|
||||||
|
o.put("type", this.getType());
|
||||||
|
o.put("lang", this.getLang());
|
||||||
|
o.put("name", this.getName());
|
||||||
|
return o;
|
||||||
|
} catch(JSONException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String hash;
|
||||||
|
protected final byte[] ver;
|
||||||
|
protected final List<Identity> identities;
|
||||||
|
protected final List<String> features;
|
||||||
|
|
||||||
|
public ServiceDiscoveryResult(final IqPacket packet) {
|
||||||
|
this.identities = new ArrayList<>();
|
||||||
|
this.features = new ArrayList<>();
|
||||||
|
this.hash = "sha-1"; // We only support sha-1 for now
|
||||||
|
|
||||||
|
final List<Element> elements = packet.query().getChildren();
|
||||||
|
|
||||||
|
for (final Element element : elements) {
|
||||||
|
if (element.getName().equals("identity")) {
|
||||||
|
Identity id = new Identity(element);
|
||||||
|
if (id.getType() != null && id.getCategory() != null) {
|
||||||
|
identities.add(id);
|
||||||
|
}
|
||||||
|
} else if (element.getName().equals("feature")) {
|
||||||
|
if (element.getAttribute("var") != null) {
|
||||||
|
features.add(element.getAttribute("var"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ver = this.mkCapHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceDiscoveryResult(String hash, byte[] ver, JSONObject o) throws JSONException {
|
||||||
|
this.identities = new ArrayList<>();
|
||||||
|
this.features = new ArrayList<>();
|
||||||
|
this.hash = hash;
|
||||||
|
this.ver = ver;
|
||||||
|
|
||||||
|
JSONArray identities = o.optJSONArray("identities");
|
||||||
|
for(int i = 0; i < identities.length(); i++) {
|
||||||
|
this.identities.add(new Identity(identities.getJSONObject(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONArray features = o.optJSONArray("features");
|
||||||
|
for(int i = 0; i < features.length(); i++) {
|
||||||
|
this.features.add(features.getString(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceDiscoveryResult(Cursor cursor) throws JSONException {
|
||||||
|
this(
|
||||||
|
cursor.getString(cursor.getColumnIndex(HASH)),
|
||||||
|
Base64.decode(cursor.getString(cursor.getColumnIndex(VER)), Base64.DEFAULT),
|
||||||
|
new JSONObject(cursor.getString(cursor.getColumnIndex(RESULT)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Identity> getIdentities() {
|
||||||
|
return this.identities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getFeatures() {
|
||||||
|
return this.features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasIdentity(String category, String type) {
|
||||||
|
for(Identity id : this.getIdentities()) {
|
||||||
|
if((category == null || id.getCategory().equals(category)) &&
|
||||||
|
(type == null || id.getType().equals(type))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected byte[] mkCapHash() {
|
||||||
|
StringBuilder s = new StringBuilder();
|
||||||
|
|
||||||
|
List<Identity> identities = this.getIdentities();
|
||||||
|
Collections.sort(identities);
|
||||||
|
|
||||||
|
for(Identity id : identities) {
|
||||||
|
s.append(
|
||||||
|
blankNull(id.getCategory()) + "/" +
|
||||||
|
blankNull(id.getType()) + "/" +
|
||||||
|
blankNull(id.getLang()) + "/" +
|
||||||
|
blankNull(id.getName()) + "<"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> features = this.getFeatures();
|
||||||
|
Collections.sort(features);
|
||||||
|
|
||||||
|
for (String feature : features) {
|
||||||
|
s.append(feature + "<");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: data forms?
|
||||||
|
|
||||||
|
MessageDigest md;
|
||||||
|
try {
|
||||||
|
md = MessageDigest.getInstance("SHA-1");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return md.digest(s.toString().getBytes("UTF-8"));
|
||||||
|
} catch(UnsupportedEncodingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
try {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
|
||||||
|
JSONArray ids = new JSONArray();
|
||||||
|
for(Identity id : this.getIdentities()) {
|
||||||
|
ids.put(id.toJSON());
|
||||||
|
}
|
||||||
|
o.put("identites", ids);
|
||||||
|
|
||||||
|
o.put("features", new JSONArray(this.getFeatures()));
|
||||||
|
|
||||||
|
return o;
|
||||||
|
} catch(JSONException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentValues getContentValues() {
|
||||||
|
final ContentValues values = new ContentValues();
|
||||||
|
values.put(HASH, this.hash);
|
||||||
|
values.put(VER, new String(Base64.encode(this.ver, Base64.DEFAULT)).trim());
|
||||||
|
values.put(RESULT, this.toJSON().toString());
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ package eu.siacs.conversations.generator;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presence;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
|
@ -37,21 +37,10 @@ public class PresenceGenerator extends AbstractGenerator {
|
||||||
return subscription("subscribed", contact);
|
return subscription("subscribed", contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket selfPresence(Account account, int presence) {
|
public PresencePacket selfPresence(Account account, Presence.Status status) {
|
||||||
PresencePacket packet = new PresencePacket();
|
PresencePacket packet = new PresencePacket();
|
||||||
switch(presence) {
|
if(status.toShowString() != null) {
|
||||||
case Presences.AWAY:
|
packet.addChild("show").setContent(status.toShowString());
|
||||||
packet.addChild("show").setContent("away");
|
|
||||||
break;
|
|
||||||
case Presences.XA:
|
|
||||||
packet.addChild("show").setContent("xa");
|
|
||||||
break;
|
|
||||||
case Presences.CHAT:
|
|
||||||
packet.addChild("show").setContent("chat");
|
|
||||||
break;
|
|
||||||
case Presences.DND:
|
|
||||||
packet.addChild("show").setContent("dnd");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
packet.setFrom(account.getJid());
|
packet.setFrom(account.getJid());
|
||||||
String sig = account.getPgpSignature();
|
String sig = account.getPgpSignature();
|
||||||
|
|
|
@ -13,13 +13,16 @@ import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presence;
|
||||||
|
import eu.siacs.conversations.entities.ServiceDiscoveryResult;
|
||||||
import eu.siacs.conversations.generator.PresenceGenerator;
|
import eu.siacs.conversations.generator.PresenceGenerator;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
||||||
import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
|
import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||||
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
|
|
||||||
public class PresenceParser extends AbstractParser implements
|
public class PresenceParser extends AbstractParser implements
|
||||||
|
@ -167,7 +170,7 @@ public class PresenceParser extends AbstractParser implements
|
||||||
final String type = packet.getAttribute("type");
|
final String type = packet.getAttribute("type");
|
||||||
final Contact contact = account.getRoster().getContact(from);
|
final Contact contact = account.getRoster().getContact(from);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
String presence = from.isBareJid() ? "" : from.getResourcepart();
|
final String presence = from.isBareJid() ? "" : from.getResourcepart();
|
||||||
contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
|
contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
|
||||||
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
|
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
|
||||||
if (avatar != null && !contact.isSelf()) {
|
if (avatar != null && !contact.isSelf()) {
|
||||||
|
@ -183,7 +186,34 @@ public class PresenceParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sizeBefore = contact.getPresences().size();
|
int sizeBefore = contact.getPresences().size();
|
||||||
contact.updatePresence(presence, Presences.parseShow(packet.findChild("show")));
|
|
||||||
|
ServiceDiscoveryResult disco = null;
|
||||||
|
Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
|
||||||
|
|
||||||
|
if (caps != null) {
|
||||||
|
disco = mXmppConnectionService.databaseBackend.
|
||||||
|
findDiscoveryResult(caps.getAttribute("hash"), caps.getAttribute("ver"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disco != null || caps == null) {
|
||||||
|
contact.updatePresence(presence, new Presence(packet.findChild("show"), disco));
|
||||||
|
} else {
|
||||||
|
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
|
||||||
|
request.setTo(from);
|
||||||
|
request.query("http://jabber.org/protocol/disco#info");
|
||||||
|
|
||||||
|
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
|
||||||
|
@Override
|
||||||
|
public void onIqPacketReceived(Account account, IqPacket discoPacket) {
|
||||||
|
if (discoPacket.getType() == IqPacket.TYPE.RESULT) {
|
||||||
|
ServiceDiscoveryResult disco = new ServiceDiscoveryResult(discoPacket);
|
||||||
|
contact.updatePresence(presence, new Presence(packet.findChild("show"), disco));
|
||||||
|
mXmppConnectionService.databaseBackend.insertDiscoveryResult(disco);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
|
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
|
||||||
Element x = packet.findChild("x", "jabber:x:signed");
|
Element x = packet.findChild("x", "jabber:x:signed");
|
||||||
if (pgp != null && x != null) {
|
if (pgp != null && x != null) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
||||||
|
@ -41,6 +42,7 @@ import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.Roster;
|
import eu.siacs.conversations.entities.Roster;
|
||||||
|
import eu.siacs.conversations.entities.ServiceDiscoveryResult;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
private static DatabaseBackend instance = null;
|
private static DatabaseBackend instance = null;
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "history";
|
private static final String DATABASE_NAME = "history";
|
||||||
private static final int DATABASE_VERSION = 22;
|
private static final int DATABASE_VERSION = 23;
|
||||||
|
|
||||||
private static String CREATE_CONTATCS_STATEMENT = "create table "
|
private static String CREATE_CONTATCS_STATEMENT = "create table "
|
||||||
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
|
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
|
||||||
|
@ -63,6 +65,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
+ ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT + ", "
|
+ ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT + ", "
|
||||||
+ Contact.JID + ") ON CONFLICT REPLACE);";
|
+ Contact.JID + ") ON CONFLICT REPLACE);";
|
||||||
|
|
||||||
|
private static String CREATE_DISCOVERY_RESULTS_STATEMENT = "create table "
|
||||||
|
+ ServiceDiscoveryResult.TABLENAME + "("
|
||||||
|
+ ServiceDiscoveryResult.HASH + " TEXT, "
|
||||||
|
+ ServiceDiscoveryResult.VER + " TEXT, "
|
||||||
|
+ ServiceDiscoveryResult.RESULT + " TEXT, "
|
||||||
|
+ "UNIQUE(" + ServiceDiscoveryResult.HASH + ", "
|
||||||
|
+ ServiceDiscoveryResult.VER + ") ON CONFLICT REPLACE);";
|
||||||
|
|
||||||
private static String CREATE_PREKEYS_STATEMENT = "CREATE TABLE "
|
private static String CREATE_PREKEYS_STATEMENT = "CREATE TABLE "
|
||||||
+ SQLiteAxolotlStore.PREKEY_TABLENAME + "("
|
+ SQLiteAxolotlStore.PREKEY_TABLENAME + "("
|
||||||
+ SQLiteAxolotlStore.ACCOUNT + " TEXT, "
|
+ SQLiteAxolotlStore.ACCOUNT + " TEXT, "
|
||||||
|
@ -158,6 +168,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
+ ") ON DELETE CASCADE);");
|
+ ") ON DELETE CASCADE);");
|
||||||
|
|
||||||
db.execSQL(CREATE_CONTATCS_STATEMENT);
|
db.execSQL(CREATE_CONTATCS_STATEMENT);
|
||||||
|
db.execSQL(CREATE_DISCOVERY_RESULTS_STATEMENT);
|
||||||
db.execSQL(CREATE_SESSIONS_STATEMENT);
|
db.execSQL(CREATE_SESSIONS_STATEMENT);
|
||||||
db.execSQL(CREATE_PREKEYS_STATEMENT);
|
db.execSQL(CREATE_PREKEYS_STATEMENT);
|
||||||
db.execSQL(CREATE_SIGNED_PREKEYS_STATEMENT);
|
db.execSQL(CREATE_SIGNED_PREKEYS_STATEMENT);
|
||||||
|
@ -355,6 +366,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
if (oldVersion < 22 && newVersion >= 22) {
|
if (oldVersion < 22 && newVersion >= 22) {
|
||||||
db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.CERTIFICATE);
|
db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.CERTIFICATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 23 && newVersion >= 23) {
|
||||||
|
db.execSQL(CREATE_DISCOVERY_RESULTS_STATEMENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized DatabaseBackend getInstance(Context context) {
|
public static synchronized DatabaseBackend getInstance(Context context) {
|
||||||
|
@ -379,6 +394,30 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
db.insert(Account.TABLENAME, null, account.getContentValues());
|
db.insert(Account.TABLENAME, null, account.getContentValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertDiscoveryResult(ServiceDiscoveryResult result) {
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
db.insert(ServiceDiscoveryResult.TABLENAME, null, result.getContentValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceDiscoveryResult findDiscoveryResult(final String hash, final String ver) {
|
||||||
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
String[] selectionArgs = {hash, ver};
|
||||||
|
Cursor cursor = db.query(ServiceDiscoveryResult.TABLENAME, null,
|
||||||
|
ServiceDiscoveryResult.HASH + "=? AND " + ServiceDiscoveryResult.VER + "=?",
|
||||||
|
selectionArgs, null, null, null);
|
||||||
|
if (cursor.getCount() == 0)
|
||||||
|
return null;
|
||||||
|
cursor.moveToFirst();
|
||||||
|
|
||||||
|
ServiceDiscoveryResult result = null;
|
||||||
|
try {
|
||||||
|
result = new ServiceDiscoveryResult(cursor);
|
||||||
|
} catch (JSONException e) { /* result is still null */ }
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public CopyOnWriteArrayList<Conversation> getConversations(int status) {
|
public CopyOnWriteArrayList<Conversation> getConversations(int status) {
|
||||||
CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<>();
|
CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<>();
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
|
|
@ -72,6 +72,7 @@ import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
||||||
|
import eu.siacs.conversations.entities.Presence;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
import eu.siacs.conversations.entities.Transferable;
|
import eu.siacs.conversations.entities.Transferable;
|
||||||
import eu.siacs.conversations.entities.TransferablePlaceholder;
|
import eu.siacs.conversations.entities.TransferablePlaceholder;
|
||||||
|
@ -596,13 +597,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
||||||
return getPreferences().getString("picture_compression", "auto");
|
return getPreferences().getString("picture_compression", "auto");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTargetPresence() {
|
private Presence.Status getTargetPresence() {
|
||||||
if (xaOnSilentMode() && isPhoneSilenced()) {
|
if (xaOnSilentMode() && isPhoneSilenced()) {
|
||||||
return Presences.XA;
|
return Presence.Status.XA;
|
||||||
} else if (awayWhenScreenOff() && !isInteractive()) {
|
} else if (awayWhenScreenOff() && !isInteractive()) {
|
||||||
return Presences.AWAY;
|
return Presence.Status.AWAY;
|
||||||
} else {
|
} else {
|
||||||
return Presences.ONLINE;
|
return Presence.Status.ONLINE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.DownloadableFile;
|
import eu.siacs.conversations.entities.DownloadableFile;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
|
import eu.siacs.conversations.entities.Presence;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
import eu.siacs.conversations.entities.Transferable;
|
import eu.siacs.conversations.entities.Transferable;
|
||||||
import eu.siacs.conversations.entities.TransferablePlaceholder;
|
import eu.siacs.conversations.entities.TransferablePlaceholder;
|
||||||
|
@ -862,82 +863,82 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||||
|
|
||||||
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
|
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
|
||||||
|
|
||||||
private int getSendButtonImageResource(SendButtonAction action, int status) {
|
private int getSendButtonImageResource(SendButtonAction action, Presence.Status status) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case TEXT:
|
case TEXT:
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
return R.drawable.ic_send_text_online;
|
return R.drawable.ic_send_text_online;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
return R.drawable.ic_send_text_away;
|
return R.drawable.ic_send_text_away;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
case Presences.DND:
|
case DND:
|
||||||
return R.drawable.ic_send_text_dnd;
|
return R.drawable.ic_send_text_dnd;
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_send_text_offline;
|
return R.drawable.ic_send_text_offline;
|
||||||
}
|
}
|
||||||
case TAKE_PHOTO:
|
case TAKE_PHOTO:
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
return R.drawable.ic_send_photo_online;
|
return R.drawable.ic_send_photo_online;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
return R.drawable.ic_send_photo_away;
|
return R.drawable.ic_send_photo_away;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
case Presences.DND:
|
case DND:
|
||||||
return R.drawable.ic_send_photo_dnd;
|
return R.drawable.ic_send_photo_dnd;
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_send_photo_offline;
|
return R.drawable.ic_send_photo_offline;
|
||||||
}
|
}
|
||||||
case RECORD_VOICE:
|
case RECORD_VOICE:
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
return R.drawable.ic_send_voice_online;
|
return R.drawable.ic_send_voice_online;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
return R.drawable.ic_send_voice_away;
|
return R.drawable.ic_send_voice_away;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
case Presences.DND:
|
case DND:
|
||||||
return R.drawable.ic_send_voice_dnd;
|
return R.drawable.ic_send_voice_dnd;
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_send_voice_offline;
|
return R.drawable.ic_send_voice_offline;
|
||||||
}
|
}
|
||||||
case SEND_LOCATION:
|
case SEND_LOCATION:
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
return R.drawable.ic_send_location_online;
|
return R.drawable.ic_send_location_online;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
return R.drawable.ic_send_location_away;
|
return R.drawable.ic_send_location_away;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
case Presences.DND:
|
case DND:
|
||||||
return R.drawable.ic_send_location_dnd;
|
return R.drawable.ic_send_location_dnd;
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_send_location_offline;
|
return R.drawable.ic_send_location_offline;
|
||||||
}
|
}
|
||||||
case CANCEL:
|
case CANCEL:
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
return R.drawable.ic_send_cancel_online;
|
return R.drawable.ic_send_cancel_online;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
return R.drawable.ic_send_cancel_away;
|
return R.drawable.ic_send_cancel_away;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
case Presences.DND:
|
case DND:
|
||||||
return R.drawable.ic_send_cancel_dnd;
|
return R.drawable.ic_send_cancel_dnd;
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_send_cancel_offline;
|
return R.drawable.ic_send_cancel_offline;
|
||||||
}
|
}
|
||||||
case CHOOSE_PICTURE:
|
case CHOOSE_PICTURE:
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Presences.CHAT:
|
case CHAT:
|
||||||
case Presences.ONLINE:
|
case ONLINE:
|
||||||
return R.drawable.ic_send_picture_online;
|
return R.drawable.ic_send_picture_online;
|
||||||
case Presences.AWAY:
|
case AWAY:
|
||||||
return R.drawable.ic_send_picture_away;
|
return R.drawable.ic_send_picture_away;
|
||||||
case Presences.XA:
|
case XA:
|
||||||
case Presences.DND:
|
case DND:
|
||||||
return R.drawable.ic_send_picture_dnd;
|
return R.drawable.ic_send_picture_dnd;
|
||||||
default:
|
default:
|
||||||
return R.drawable.ic_send_picture_offline;
|
return R.drawable.ic_send_picture_offline;
|
||||||
|
@ -949,7 +950,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||||
public void updateSendButton() {
|
public void updateSendButton() {
|
||||||
final Conversation c = this.conversation;
|
final Conversation c = this.conversation;
|
||||||
final SendButtonAction action;
|
final SendButtonAction action;
|
||||||
final int status;
|
final Presence.Status status;
|
||||||
final boolean empty = this.mEditMessage == null || this.mEditMessage.getText().length() == 0;
|
final boolean empty = this.mEditMessage == null || this.mEditMessage.getText().length() == 0;
|
||||||
final boolean conference = c.getMode() == Conversation.MODE_MULTI;
|
final boolean conference = c.getMode() == Conversation.MODE_MULTI;
|
||||||
if (conference && !c.getAccount().httpUploadAvailable()) {
|
if (conference && !c.getAccount().httpUploadAvailable()) {
|
||||||
|
@ -996,10 +997,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||||
if (c.getMode() == Conversation.MODE_SINGLE) {
|
if (c.getMode() == Conversation.MODE_SINGLE) {
|
||||||
status = c.getContact().getMostAvailableStatus();
|
status = c.getContact().getMostAvailableStatus();
|
||||||
} else {
|
} else {
|
||||||
status = c.getMucOptions().online() ? Presences.ONLINE : Presences.OFFLINE;
|
status = c.getMucOptions().online() ? Presence.Status.ONLINE : Presence.Status.OFFLINE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status = Presences.OFFLINE;
|
status = Presence.Status.OFFLINE;
|
||||||
}
|
}
|
||||||
this.mSendButton.setTag(action);
|
this.mSendButton.setTag(action);
|
||||||
this.mSendButton.setImageResource(getSendButtonImageResource(action, status));
|
this.mSendButton.setImageResource(getSendButtonImageResource(action, status));
|
||||||
|
|
|
@ -63,6 +63,7 @@ import eu.siacs.conversations.entities.Bookmark;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.ListItem;
|
import eu.siacs.conversations.entities.ListItem;
|
||||||
|
import eu.siacs.conversations.entities.Presence;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
|
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
|
||||||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||||
|
@ -725,9 +726,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
for (Account account : xmppConnectionService.getAccounts()) {
|
for (Account account : xmppConnectionService.getAccounts()) {
|
||||||
if (account.getStatus() != Account.State.DISABLED) {
|
if (account.getStatus() != Account.State.DISABLED) {
|
||||||
for (Contact contact : account.getRoster().getContacts()) {
|
for (Contact contact : account.getRoster().getContacts()) {
|
||||||
|
Presence p = contact.getPresences().getMostAvailablePresence();
|
||||||
|
Presence.Status s = p == null ? Presence.Status.OFFLINE : p.getStatus();
|
||||||
if (contact.showInRoster() && contact.match(needle)
|
if (contact.showInRoster() && contact.match(needle)
|
||||||
&& (!this.mHideOfflineContacts
|
&& (!this.mHideOfflineContacts
|
||||||
|| contact.getPresences().getMostAvailableStatus() < Presences.OFFLINE)) {
|
|| s.compareTo(Presence.Status.OFFLINE) < 0)) {
|
||||||
this.contacts.add(contact);
|
this.contacts.add(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ import eu.siacs.conversations.crypto.sasl.SaslMechanism;
|
||||||
import eu.siacs.conversations.crypto.sasl.ScramSha1;
|
import eu.siacs.conversations.crypto.sasl.ScramSha1;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.entities.ServiceDiscoveryResult;
|
||||||
import eu.siacs.conversations.generator.IqGenerator;
|
import eu.siacs.conversations.generator.IqGenerator;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
|
@ -101,7 +102,7 @@ public class XmppConnection implements Runnable {
|
||||||
private boolean needsBinding = true;
|
private boolean needsBinding = true;
|
||||||
private boolean shouldAuthenticate = true;
|
private boolean shouldAuthenticate = true;
|
||||||
private Element streamFeatures;
|
private Element streamFeatures;
|
||||||
private final HashMap<Jid, Info> disco = new HashMap<>();
|
private final HashMap<Jid, ServiceDiscoveryResult> disco = new HashMap<>();
|
||||||
|
|
||||||
private String streamId = null;
|
private String streamId = null;
|
||||||
private int smVersion = 3;
|
private int smVersion = 3;
|
||||||
|
@ -1040,39 +1041,26 @@ public class XmppConnection implements Runnable {
|
||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
boolean advancedStreamFeaturesLoaded;
|
boolean advancedStreamFeaturesLoaded;
|
||||||
synchronized (XmppConnection.this.disco) {
|
synchronized (XmppConnection.this.disco) {
|
||||||
final List<Element> elements = packet.query().getChildren();
|
ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet);
|
||||||
final Info info = new Info();
|
for (final ServiceDiscoveryResult.Identity id : result.getIdentities()) {
|
||||||
for (final Element element : elements) {
|
if (mServerIdentity == Identity.UNKNOWN && id.getType().equals("im") &&
|
||||||
if (element.getName().equals("identity")) {
|
id.getCategory().equals("server") && id.getName() != null &&
|
||||||
String type = element.getAttribute("type");
|
jid.equals(account.getServer())) {
|
||||||
String category = element.getAttribute("category");
|
switch (id.getName()) {
|
||||||
String name = element.getAttribute("name");
|
case "Prosody":
|
||||||
if (type != null && category != null) {
|
mServerIdentity = Identity.PROSODY;
|
||||||
info.identities.add(new Pair<>(category, type));
|
break;
|
||||||
if (mServerIdentity == Identity.UNKNOWN
|
case "ejabberd":
|
||||||
&& type.equals("im")
|
mServerIdentity = Identity.EJABBERD;
|
||||||
&& category.equals("server")) {
|
break;
|
||||||
if (name != null && jid.equals(account.getServer())) {
|
case "Slack-XMPP":
|
||||||
switch (name) {
|
mServerIdentity = Identity.SLACK;
|
||||||
case "Prosody":
|
break;
|
||||||
mServerIdentity = Identity.PROSODY;
|
|
||||||
break;
|
|
||||||
case "ejabberd":
|
|
||||||
mServerIdentity = Identity.EJABBERD;
|
|
||||||
break;
|
|
||||||
case "Slack-XMPP":
|
|
||||||
mServerIdentity = Identity.SLACK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server name: " + name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server name: " + id.getName());
|
||||||
}
|
}
|
||||||
} else if (element.getName().equals("feature")) {
|
|
||||||
info.features.add(element.getAttribute("var"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
disco.put(jid, info);
|
disco.put(jid, result);
|
||||||
advancedStreamFeaturesLoaded = disco.containsKey(account.getServer())
|
advancedStreamFeaturesLoaded = disco.containsKey(account.getServer())
|
||||||
&& disco.containsKey(account.getJid().toBareJid());
|
&& disco.containsKey(account.getJid().toBareJid());
|
||||||
}
|
}
|
||||||
|
@ -1324,8 +1312,8 @@ public class XmppConnection implements Runnable {
|
||||||
public List<Jid> findDiscoItemsByFeature(final String feature) {
|
public List<Jid> findDiscoItemsByFeature(final String feature) {
|
||||||
synchronized (this.disco) {
|
synchronized (this.disco) {
|
||||||
final List<Jid> items = new ArrayList<>();
|
final List<Jid> items = new ArrayList<>();
|
||||||
for (final Entry<Jid, Info> cursor : this.disco.entrySet()) {
|
for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) {
|
||||||
if (cursor.getValue().features.contains(feature)) {
|
if (cursor.getValue().getFeatures().contains(feature)) {
|
||||||
items.add(cursor.getKey());
|
items.add(cursor.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1352,11 +1340,11 @@ public class XmppConnection implements Runnable {
|
||||||
|
|
||||||
public String getMucServer() {
|
public String getMucServer() {
|
||||||
synchronized (this.disco) {
|
synchronized (this.disco) {
|
||||||
for (final Entry<Jid, Info> cursor : disco.entrySet()) {
|
for (final Entry<Jid, ServiceDiscoveryResult> cursor : disco.entrySet()) {
|
||||||
final Info value = cursor.getValue();
|
final ServiceDiscoveryResult value = cursor.getValue();
|
||||||
if (value.features.contains("http://jabber.org/protocol/muc")
|
if (value.getFeatures().contains("http://jabber.org/protocol/muc")
|
||||||
&& !value.features.contains("jabber:iq:gateway")
|
&& !value.getFeatures().contains("jabber:iq:gateway")
|
||||||
&& !value.identities.contains(new Pair<>("conference", "irc"))) {
|
&& !value.hasIdentity("conference", "irc")) {
|
||||||
return cursor.getKey().toString();
|
return cursor.getKey().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1419,11 +1407,6 @@ public class XmppConnection implements Runnable {
|
||||||
return mServerIdentity;
|
return mServerIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Info {
|
|
||||||
public final ArrayList<String> features = new ArrayList<>();
|
|
||||||
public final ArrayList<Pair<String,String>> identities = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UnauthorizedException extends IOException {
|
private class UnauthorizedException extends IOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1458,7 +1441,7 @@ public class XmppConnection implements Runnable {
|
||||||
private boolean hasDiscoFeature(final Jid server, final String feature) {
|
private boolean hasDiscoFeature(final Jid server, final String feature) {
|
||||||
synchronized (XmppConnection.this.disco) {
|
synchronized (XmppConnection.this.disco) {
|
||||||
return connection.disco.containsKey(server) &&
|
return connection.disco.containsKey(server) &&
|
||||||
connection.disco.get(server).features.contains(feature);
|
connection.disco.get(server).getFeatures().contains(feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1486,12 +1469,12 @@ public class XmppConnection implements Runnable {
|
||||||
public boolean pep() {
|
public boolean pep() {
|
||||||
synchronized (XmppConnection.this.disco) {
|
synchronized (XmppConnection.this.disco) {
|
||||||
final Pair<String, String> needle = new Pair<>("pubsub", "pep");
|
final Pair<String, String> needle = new Pair<>("pubsub", "pep");
|
||||||
Info info = disco.get(account.getServer());
|
ServiceDiscoveryResult info = disco.get(account.getServer());
|
||||||
if (info != null && info.identities.contains(needle)) {
|
if (info != null && info.hasIdentity("pubsub", "pep")) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
info = disco.get(account.getJid().toBareJid());
|
info = disco.get(account.getJid().toBareJid());
|
||||||
return info != null && info.identities.contains(needle);
|
return info != null && info.hasIdentity("pubsub", "pep");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue