From 73f5a097dd4de8291aad7a312c78719f91bbbef5 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 12 Apr 2018 21:02:53 +0200 Subject: sync roster to disk after roster push --- .../messenger/services/XmppConnectionService.java | 61 ++++++++++------------ 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'src/main/java/de/pixart/messenger/services/XmppConnectionService.java') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 601f56e22..d83a2fd7f 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -196,37 +196,30 @@ public class XmppConnectionService extends Service { private OnMessagePacketReceived mMessageParser = new MessageParser(this); private OnPresencePacketReceived mPresenceParser = new PresenceParser(this); private IqParser mIqParser = new IqParser(this); - private OnIqPacketReceived mDefaultIqHandler = new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() != IqPacket.TYPE.RESULT) { - Element error = packet.findChild("error"); - String text = error != null ? error.findChildContent("text") : null; - if (text != null) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received iq error - " + text); - } + private final OnIqPacketReceived mDefaultIqHandler = (account, packet) -> { + if (packet.getType() != IqPacket.TYPE.RESULT) { + Element error = packet.findChild("error"); + String text = error != null ? error.findChildContent("text") : null; + if (text != null) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received iq error - " + text); } } }; private MessageGenerator mMessageGenerator = new MessageGenerator(this); - public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() { - - @Override - public void onContactStatusChanged(Contact contact, boolean online) { - Conversation conversation = find(getConversations(), contact); - if (conversation != null) { - if (online) { - conversation.endOtrIfNeeded(); - if (contact.getPresences().size() == 1) { - sendUnsentMessages(conversation); - } - } else { - //check if the resource we are haveing a conversation with is still online - if (conversation.hasValidOtrSession()) { - String otrResource = conversation.getOtrSession().getSessionID().getUserID(); - if (!(Arrays.asList(contact.getPresences().toResourceArray()).contains(otrResource))) { - conversation.endOtrIfNeeded(); - } + public OnContactStatusChanged onContactStatusChanged = (contact, online) -> { + Conversation conversation = find(getConversations(), contact); + if (conversation != null) { + if (online) { + conversation.endOtrIfNeeded(); + if (contact.getPresences().size() == 1) { + sendUnsentMessages(conversation); + } + } else { + //check if the resource we are haveing a conversation with is still online + if (conversation.hasValidOtrSession()) { + String otrResource = conversation.getOtrSession().getSessionID().getUserID(); + if (!(Arrays.asList(contact.getPresences().toResourceArray()).contains(otrResource))) { + conversation.endOtrIfNeeded(); } } } @@ -1102,7 +1095,7 @@ public class XmppConnectionService extends Service { restoreFromDatabase(); getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver); - new Thread(() -> fileObserver.startWatching()).start(); + new Thread(fileObserver::startWatching).start(); if (Config.supportOpenPgp()) { this.pgpServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() { @Override @@ -1642,6 +1635,10 @@ public class XmppConnectionService extends Service { })); } + public void syncRoster(final Account account) { + mDatabaseWriterExecutor.execute(() -> databaseBackend.writeRoster(account.getRoster())); + } + public List getConversations() { return this.conversations; } @@ -3036,13 +3033,13 @@ public class XmppConnectionService extends Service { iq.query(Namespace.ROSTER).addChild(contact.asElement()); account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler); if (sendUpdates) { - sendPresencePacket(account, - mPresenceGenerator.sendPresenceUpdatesTo(contact)); + sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact)); } if (ask) { - sendPresencePacket(account, - mPresenceGenerator.requestPresenceUpdatesFrom(contact)); + sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact)); } + } else { + syncRoster(contact.getAccount()); } } -- cgit v1.2.3