fixed possible race conditions with presences
This commit is contained in:
parent
4a36abf30f
commit
a04d736f75
|
@ -13,6 +13,7 @@ import eu.siacs.conversations.xml.Element;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class Contact extends AbstractEntity implements Serializable {
|
public class Contact extends AbstractEntity implements Serializable {
|
||||||
private static final long serialVersionUID = -4570817093119419962L;
|
private static final long serialVersionUID = -4570817093119419962L;
|
||||||
|
@ -163,12 +164,17 @@ public class Contact extends AbstractEntity implements Serializable {
|
||||||
|
|
||||||
public void updatePresence(String resource, int status) {
|
public void updatePresence(String resource, int status) {
|
||||||
this.presences.updatePresence(resource, status);
|
this.presences.updatePresence(resource, status);
|
||||||
|
Log.d("xmppService","updatingPresence for contact="+this.jid+" resource="+resource+" num="+presences.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePresence(String resource) {
|
public void removePresence(String resource) {
|
||||||
this.presences.removePresence(resource);
|
this.presences.removePresence(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearPresences() {
|
||||||
|
this.presences.clearPresences();
|
||||||
|
}
|
||||||
|
|
||||||
public int getMostAvailableStatus() {
|
public int getMostAvailableStatus() {
|
||||||
return this.presences.getMostAvailableStatus();
|
return this.presences.getMostAvailableStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class Presences {
|
||||||
this.presences.remove(resource);
|
this.presences.remove(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearPresences() {
|
||||||
|
this.presences.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public int getMostAvailableStatus() {
|
public int getMostAvailableStatus() {
|
||||||
int status = OFFLINE;
|
int status = OFFLINE;
|
||||||
Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
|
Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -288,8 +287,7 @@ public class XmppConnectionService extends Service {
|
||||||
} else {
|
} else {
|
||||||
Contact contact = findContact(account, fromParts[0]);
|
Contact contact = findContact(account, fromParts[0]);
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
//Log.d(LOGTAG,"contact was null");
|
Log.d(LOGTAG,packet.getFrom()+ " could not be found");
|
||||||
// most likely roster not synced
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
|
@ -314,17 +312,19 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
replaceContactInConversation(contact.getJid(), contact);
|
||||||
databaseBackend.updateContact(contact);
|
databaseBackend.updateContact(contact);
|
||||||
} else {
|
} else {
|
||||||
// Log.d(LOGTAG,"presence without resource "+packet.toString());
|
//Log.d(LOGTAG,"presence without resource "+packet.toString());
|
||||||
}
|
}
|
||||||
} else if (type.equals("unavailable")) {
|
} else if (type.equals("unavailable")) {
|
||||||
if (fromParts.length != 2) {
|
if (fromParts.length != 2) {
|
||||||
// Log.d(LOGTAG,"received presence with no resource "+packet.toString());
|
contact.clearPresences();
|
||||||
} else {
|
} else {
|
||||||
contact.removePresence(fromParts[1]);
|
contact.removePresence(fromParts[1]);
|
||||||
databaseBackend.updateContact(contact);
|
|
||||||
}
|
}
|
||||||
|
replaceContactInConversation(contact.getJid(), contact);
|
||||||
|
databaseBackend.updateContact(contact);
|
||||||
} else if (type.equals("subscribe")) {
|
} else if (type.equals("subscribe")) {
|
||||||
Log.d(LOGTAG,"received subscribe packet from "+packet.getFrom());
|
Log.d(LOGTAG,"received subscribe packet from "+packet.getFrom());
|
||||||
if (contact
|
if (contact
|
||||||
|
@ -348,7 +348,6 @@ public class XmppConnectionService extends Service {
|
||||||
} else {
|
} else {
|
||||||
//Log.d(LOGTAG, packet.toString());
|
//Log.d(LOGTAG, packet.toString());
|
||||||
}
|
}
|
||||||
replaceContactInConversation(contact.getJid(), contact);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,11 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
status.setTextColor(0xFFe92727);
|
status.setTextColor(0xFFe92727);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
contactJid.setText(contact.getJid());
|
if (contact.getPresences().size() > 1) {
|
||||||
|
contactJid.setText(contact.getJid()+" ("+contact.getPresences().size()+")");
|
||||||
|
} else {
|
||||||
|
contactJid.setText(contact.getJid());
|
||||||
|
}
|
||||||
accountJid.setText(contact.getAccount().getJid());
|
accountJid.setText(contact.getAccount().getJid());
|
||||||
|
|
||||||
UIHelper.prepareContactBadge(this, badge, contact, getApplicationContext());
|
UIHelper.prepareContactBadge(this, badge, contact, getApplicationContext());
|
||||||
|
|
|
@ -674,7 +674,6 @@ public class XmppConnection implements Runnable {
|
||||||
"var"));
|
"var"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(LOGTAG,"put "+server+" "+features.toString());
|
|
||||||
disco.put(server, features);
|
disco.put(server, features);
|
||||||
|
|
||||||
if (account.getServer().equals(server)) {
|
if (account.getServer().equals(server)) {
|
||||||
|
|
Loading…
Reference in a new issue