synchronize around the disco object
This commit is contained in:
parent
0bd4105b1d
commit
adca670196
|
@ -812,7 +812,7 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
private void sendBindRequest() {
|
||||
while(!mXmppConnectionService.areMessagesInitialized()) {
|
||||
while(!mXmppConnectionService.areMessagesInitialized() && socket != null && !socket.isClosed()) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (final InterruptedException ignored) {
|
||||
|
@ -907,7 +907,9 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
features.carbonsEnabled = false;
|
||||
features.blockListRequested = false;
|
||||
disco.clear();
|
||||
synchronized (this.disco) {
|
||||
this.disco.clear();
|
||||
}
|
||||
sendServiceDiscoveryInfo(account.getServer());
|
||||
sendServiceDiscoveryInfo(account.getJid().toBareJid());
|
||||
sendServiceDiscoveryItems(account.getServer());
|
||||
|
@ -920,11 +922,6 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
private void sendServiceDiscoveryInfo(final Jid jid) {
|
||||
if (disco.containsKey(jid)) {
|
||||
if (account.getServer().equals(jid)) {
|
||||
enableAdvancedStreamFeatures();
|
||||
}
|
||||
} else {
|
||||
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
||||
iq.setTo(jid);
|
||||
iq.query("http://jabber.org/protocol/disco#info");
|
||||
|
@ -933,6 +930,8 @@ public class XmppConnection implements Runnable {
|
|||
@Override
|
||||
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||
boolean advancedStreamFeaturesLoaded = false;
|
||||
synchronized (XmppConnection.this.disco) {
|
||||
final List<Element> elements = packet.query().getChildren();
|
||||
final Info info = new Info();
|
||||
for (final Element element : elements) {
|
||||
|
@ -947,18 +946,18 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
}
|
||||
disco.put(jid, info);
|
||||
if ((jid.equals(account.getServer()) || jid.equals(account.getJid().toBareJid()))
|
||||
&& disco.containsKey(account.getServer())
|
||||
&& disco.containsKey(account.getJid().toBareJid())) {
|
||||
advancedStreamFeaturesLoaded = disco.containsKey(account.getServer())
|
||||
&& disco.containsKey(account.getJid().toBareJid());
|
||||
}
|
||||
if (advancedStreamFeaturesLoaded && (jid.equals(account.getServer()) || jid.equals(account.getJid().toBareJid()))) {
|
||||
enableAdvancedStreamFeatures();
|
||||
}
|
||||
} else {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not query disco info for "+jid.toString());
|
||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco info for " + jid.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void enableAdvancedStreamFeatures() {
|
||||
if (getFeatures().carbons() && !features.carbonsEnabled) {
|
||||
|
@ -1184,14 +1183,16 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
public List<Jid> findDiscoItemsByFeature(final String feature) {
|
||||
synchronized (this.disco) {
|
||||
final List<Jid> items = new ArrayList<>();
|
||||
for (final Entry<Jid, Info> cursor : disco.entrySet()) {
|
||||
for (final Entry<Jid, Info> cursor : this.disco.entrySet()) {
|
||||
if (cursor.getValue().features.contains(feature)) {
|
||||
items.add(cursor.getKey());
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
public Jid findDiscoItemByFeature(final String feature) {
|
||||
final List<Jid> items = findDiscoItemsByFeature(feature);
|
||||
|
@ -1211,14 +1212,16 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
public String getMucServer() {
|
||||
synchronized (this.disco) {
|
||||
for (final Entry<Jid, Info> cursor : disco.entrySet()) {
|
||||
final Info value = cursor.getValue();
|
||||
if (value.features.contains("http://jabber.org/protocol/muc")
|
||||
&& !value.features.contains("jabber:iq:gateway")
|
||||
&& !value.identities.contains(new Pair<>("conference","irc"))) {
|
||||
&& !value.identities.contains(new Pair<>("conference", "irc"))) {
|
||||
return cursor.getKey().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1302,9 +1305,11 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
private boolean hasDiscoFeature(final Jid server, final String feature) {
|
||||
synchronized (XmppConnection.this.disco) {
|
||||
return connection.disco.containsKey(server) &&
|
||||
connection.disco.get(server).features.contains(feature);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean carbons() {
|
||||
return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2");
|
||||
|
@ -1328,7 +1333,8 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
public boolean pep() {
|
||||
final Pair<String,String> needle = new Pair<>("pubsub","pep");
|
||||
synchronized (XmppConnection.this.disco) {
|
||||
final Pair<String, String> needle = new Pair<>("pubsub", "pep");
|
||||
Info info = disco.get(account.getServer());
|
||||
if (info != null && info.identities.contains(needle)) {
|
||||
return true;
|
||||
|
@ -1337,6 +1343,7 @@ public class XmppConnection implements Runnable {
|
|||
return info != null && info.identities.contains(needle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mam() {
|
||||
if (hasDiscoFeature(account.getJid().toBareJid(), "urn:xmpp:mam:0")) {
|
||||
|
@ -1347,8 +1354,10 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
|
||||
public boolean advancedStreamFeaturesLoaded() {
|
||||
synchronized (XmppConnection.this.disco) {
|
||||
return disco.containsKey(account.getServer());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean rosterVersioning() {
|
||||
return connection.streamFeatures != null && connection.streamFeatures.hasChild("ver");
|
||||
|
|
Loading…
Reference in a new issue