fixed concurrent modification of contacts which led to missing presences

This commit is contained in:
Daniel Gultsch 2014-04-18 21:26:01 +02:00
parent 1e5f916b2a
commit 7ccbf0008a
2 changed files with 15 additions and 10 deletions

View file

@ -201,9 +201,13 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ "=?", args); + "=?", args);
} }
public void updateContact(Contact contact) { public void updateContact(Contact contact, boolean updatePresences) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
String[] args = { contact.getUuid() }; String[] args = { contact.getUuid() };
ContentValues values = contact.getContentValues();
if (!updatePresences) {
values.remove(Contact.PRESENCES);
}
db.update(Contact.TABLENAME, contact.getContentValues(), Contact.UUID db.update(Contact.TABLENAME, contact.getContentValues(), Contact.UUID
+ "=?", args); + "=?", args);
} }
@ -227,8 +231,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (cursor.getCount()>=1) { if (cursor.getCount()>=1) {
cursor.moveToFirst(); cursor.moveToFirst();
contact.setUuid(cursor.getString(0)); contact.setUuid(cursor.getString(0));
contact.setPresences(Presences.fromJsonString(cursor.getString(1))); //contact.setPresences(Presences.fromJsonString(cursor.getString(1)));
updateContact(contact); updateContact(contact,false);
} else { } else {
contact.setUuid(UUID.randomUUID().toString()); contact.setUuid(UUID.randomUUID().toString());
createContact(contact); createContact(contact);

View file

@ -317,7 +317,7 @@ public class XmppConnectionService extends Service {
} }
} }
replaceContactInConversation(contact.getJid(), contact); replaceContactInConversation(contact.getJid(), contact);
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,true);
} else { } else {
//Log.d(LOGTAG,"presence without resource "+packet.toString()); //Log.d(LOGTAG,"presence without resource "+packet.toString());
} }
@ -328,7 +328,7 @@ public class XmppConnectionService extends Service {
contact.removePresence(fromParts[1]); contact.removePresence(fromParts[1]);
} }
replaceContactInConversation(contact.getJid(), contact); replaceContactInConversation(contact.getJid(), contact);
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,true);
} 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
@ -339,7 +339,7 @@ public class XmppConnectionService extends Service {
contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT); contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT);
replaceContactInConversation(contact.getJid(), replaceContactInConversation(contact.getJid(),
contact); contact);
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,false);
if ((contact if ((contact
.getSubscriptionOption(Contact.Subscription.ASKING)) .getSubscriptionOption(Contact.Subscription.ASKING))
&& (!contact && (!contact
@ -469,7 +469,7 @@ public class XmppConnectionService extends Service {
replaceContactInConversation(contact.getJid(), null); replaceContactInConversation(contact.getJid(), null);
} else { } else {
contact.parseSubscriptionFromElement(item); contact.parseSubscriptionFromElement(item);
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,false);
replaceContactInConversation(contact.getJid(), contact); replaceContactInConversation(contact.getJid(), contact);
} }
} }
@ -667,6 +667,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onBind(Account account) { public void onBind(Account account) {
Log.d("xmppService","bount. cleaning presences");
databaseBackend.clearPresences(account); databaseBackend.clearPresences(account);
account.clearPresences(); // self presences account.clearPresences(); // self presences
if (account.getXmppConnection().hasFeatureRosterManagment()) { if (account.getXmppConnection().hasFeatureRosterManagment()) {
@ -912,7 +913,7 @@ public class XmppConnectionService extends Service {
.getString("photouri")); .getString("photouri"));
contact.setDisplayName(phoneContact contact.setDisplayName(phoneContact
.getString("displayname")); .getString("displayname"));
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,false);
replaceContactInConversation(contact.getJid(), replaceContactInConversation(contact.getJid(),
contact); contact);
} else { } else {
@ -920,7 +921,7 @@ public class XmppConnectionService extends Service {
|| (contact.getProfilePhoto() != null)) { || (contact.getProfilePhoto() != null)) {
contact.setSystemAccount(null); contact.setSystemAccount(null);
contact.setPhotoUri(null); contact.setPhotoUri(null);
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,false);
replaceContactInConversation( replaceContactInConversation(
contact.getJid(), contact); contact.getJid(), contact);
} }
@ -1212,7 +1213,7 @@ public class XmppConnectionService extends Service {
} }
public void updateContact(Contact contact) { public void updateContact(Contact contact) {
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact,false);
replaceContactInConversation(contact.getJid(), contact); replaceContactInConversation(contact.getJid(), contact);
} }