From b99779432cd63d7d136fb288f61db90f8ab9f34c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 22 May 2014 14:33:17 +0200 Subject: offline crud of contacts --- .../services/XmppConnectionService.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index c01c7a1af..f879de113 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -234,6 +234,7 @@ public class XmppConnectionService extends Service { sendUnsendMessages(conversations.get(i)); } } + syncDirtyContacts(account); scheduleWakeupCall(PING_MAX_INTERVAL, true); } else if (account.getStatus() == Account.STATUS_OFFLINE) { if (!account.isOptionSet(Account.OPTION_DISABLED)) { @@ -490,9 +491,12 @@ public class XmppConnectionService extends Service { String name = item.getAttribute("name"); String subscription = item.getAttribute("subscription"); Contact contact = account.getRoster().getContact(jid); - contact.setServerName(name); + if (!contact.getOption(Contact.Options.DIRTY_PUSH)) { + contact.setServerName(name); + } if (subscription.equals("remove")) { contact.resetOption(Contact.Options.IN_ROSTER); + contact.resetOption(Contact.Options.DIRTY_DELETE); } else { contact.setOption(Contact.Options.IN_ROSTER); contact.parseSubscriptionFromElement(item); @@ -1191,6 +1195,18 @@ public class XmppConnectionService extends Service { public void updateMessage(Message message) { databaseBackend.updateMessage(message); } + + protected void syncDirtyContacts(Account account) { + for(Contact contact : account.getRoster().getContacts()) { + if (contact.getOption(Contact.Options.DIRTY_PUSH)) { + pushContactToServer(contact); + } + if (contact.getOption(Contact.Options.DIRTY_DELETE)) { + Log.d(LOGTAG,"dirty delete"); + deleteContactOnServer(contact); + } + } + } public void createContact(Contact contact) { SharedPreferences sharedPref = getPreferences(); @@ -1203,12 +1219,12 @@ public class XmppConnectionService extends Service { } public void pushContactToServer(Contact contact) { + contact.resetOption(Contact.Options.DIRTY_DELETE); Account account = contact.getAccount(); if (account.getStatus() == Account.STATUS_ONLINE) { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); iq.query("jabber:iq:roster").addChild(contact.asElement()); account.getXmppConnection().sendIqPacket(iq, null); - contact.resetOption(Contact.Options.DIRTY_PUSH); if (contact.getOption(Contact.Options.ASKING)) { requestPresenceUpdatesFrom(contact); } @@ -1223,6 +1239,7 @@ public class XmppConnectionService extends Service { } public void deleteContactOnServer(Contact contact) { + contact.resetOption(Contact.Options.DIRTY_PUSH); Account account = contact.getAccount(); if (account.getStatus() == Account.STATUS_ONLINE) { IqPacket iq = new IqPacket(IqPacket.TYPE_SET); @@ -1266,7 +1283,6 @@ public class XmppConnectionService extends Service { packet.setAttribute("to", contact.getJid()); packet.setAttribute("from", contact.getAccount().getJid()); contact.getAccount().getXmppConnection().sendPresencePacket(packet); - contact.resetOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); } public void sendPresence(Account account) { -- cgit v1.2.3