diff options
Diffstat (limited to 'src/main/java/de')
6 files changed, 43 insertions, 44 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index 1abbed25a..6946f63f7 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java @@ -98,8 +98,7 @@ public class IqGenerator extends AbstractGenerator { protected IqPacket publish(final String node, final Element item, final Bundle options) { final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); - final Element pubsub = packet.addChild("pubsub", - "http://jabber.org/protocol/pubsub"); + final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB); final Element publish = pubsub.addChild("publish"); publish.setAttribute("node", node); publish.addChild(item); @@ -116,8 +115,7 @@ public class IqGenerator extends AbstractGenerator { protected IqPacket retrieve(String node, Element item) { final IqPacket packet = new IqPacket(IqPacket.TYPE.GET); - final Element pubsub = packet.addChild("pubsub", - "http://jabber.org/protocol/pubsub"); + final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB); final Element items = pubsub.addChild("items"); items.setAttribute("node", node); if (item != null) { @@ -409,7 +407,7 @@ public class IqGenerator extends AbstractGenerator { enable.setAttribute("jid", jid.toString()); enable.setAttribute("node", node); Data data = new Data(); - data.setFormType("http://jabber.org/protocol/pubsub#publish-options"); + data.setFormType(Namespace.PUBSUB_PUBLISH_OPTIONS); data.put("secret", secret); data.submit(); enable.addChild(data); diff --git a/src/main/java/de/pixart/messenger/parser/IqParser.java b/src/main/java/de/pixart/messenger/parser/IqParser.java index 999137a02..8f8cf9ae4 100644 --- a/src/main/java/de/pixart/messenger/parser/IqParser.java +++ b/src/main/java/de/pixart/messenger/parser/IqParser.java @@ -82,11 +82,11 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateRosterUi(); mXmppConnectionService.getShortcutService().refresh(); + mXmppConnectionService.syncRoster(account); } public String avatarData(final IqPacket packet) { - final Element pubsub = packet.findChild("pubsub", - "http://jabber.org/protocol/pubsub"); + final Element pubsub = packet.findChild("pubsub", Namespace.PUBSUB); if (pubsub == null) { return null; } @@ -98,8 +98,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { } public Element getItem(final IqPacket packet) { - final Element pubsub = packet.findChild("pubsub", - "http://jabber.org/protocol/pubsub"); + final Element pubsub = packet.findChild("pubsub", Namespace.PUBSUB); if (pubsub == null) { return null; } diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 6013ca7e9..152a59f94 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -7,6 +7,7 @@ import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.os.Environment; +import android.os.SystemClock; import android.util.Base64; import android.util.Log; @@ -862,6 +863,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { } public void writeRoster(final Roster roster) { + long start = SystemClock.elapsedRealtime(); final Account account = roster.getAccount(); final SQLiteDatabase db = this.getWritableDatabase(); db.beginTransaction(); @@ -878,6 +880,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.endTransaction(); account.setRosterVersion(roster.getVersion()); updateAccount(account); + long duration = SystemClock.elapsedRealtime() - start; + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": persisted roster in " + duration + "ms"); } public void deleteMessagesInConversation(Conversation conversation) { 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<Conversation> 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()); } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 2c8d72aa0..109e0fe5f 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -873,7 +873,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } private void hidePrepareFileToast(final Toast prepareFileToast) { - if (prepareFileToast != null) { + if (prepareFileToast != null && activity != null) { activity.runOnUiThread(prepareFileToast::cancel); } } diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java index 2d6b4708f..b70d8040f 100644 --- a/src/main/java/de/pixart/messenger/utils/Namespace.java +++ b/src/main/java/de/pixart/messenger/utils/Namespace.java @@ -14,8 +14,9 @@ public final class Namespace { public static final String OOB = "jabber:x:oob"; public static final String SASL = "urn:ietf:params:xml:ns:xmpp-sasl"; public static final String TLS = "urn:ietf:params:xml:ns:xmpp-tls"; - public static final String PUBSUB_PUBLISH_OPTIONS = "http://jabber.org/protocol/pubsub#publish-options"; - public static final String PUBSUB_ERROR = "http://jabber.org/protocol/pubsub#errors"; + public static final String PUBSUB = "http://jabber.org/protocol/pubsub"; + public static final String PUBSUB_PUBLISH_OPTIONS = PUBSUB + "#publish-options"; + public static final String PUBSUB_ERROR = PUBSUB + "#errors"; public static final String NICK = "http://jabber.org/protocol/nick"; public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline"; public static final String BIND = "urn:ietf:params:xml:ns:xmpp-bind"; |