diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 8266e3821..cef8bd1af 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -192,7 +192,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece public boolean execute(Account account) { if (jid != null) { - Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true); + Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true, false); if (!conversation.getMucOptions().online()) { conversation.getMucOptions().setPassword(password); mXmppConnectionService.databaseBackend.updateConversation(conversation); @@ -415,7 +415,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) { - final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); + final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query, false); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; if (serverMsgId == null) { diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 4ff11401e..eb8593f89 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -253,7 +253,7 @@ public class PresenceParser extends AbstractParser implements } else { contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); final Conversation conversation = mXmppConnectionService.findOrCreateConversation( - account, contact.getJid().toBareJid(), false); + account, contact.getJid().toBareJid(), false, false); final String statusMessage = packet.findChildContent("status"); if (statusMessage != null && !statusMessage.isEmpty() diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 56717488f..5c6baf9d2 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1413,7 +1413,7 @@ public class XmppConnectionService extends Service { if (conversation != null) { conversation.setBookmark(bookmark); } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) { - conversation = findOrCreateConversation(account, bookmark.getJid(), true, true); + conversation = findOrCreateConversation(account, bookmark.getJid(), true, true, false); conversation.setBookmark(bookmark); } } @@ -1681,15 +1681,15 @@ public class XmppConnectionService extends Service { return null; } - public Conversation findOrCreateConversation(Account account, Jid jid, boolean muc) { - return this.findOrCreateConversation(account,jid,muc,false); + public Conversation findOrCreateConversation(Account account, Jid jid, boolean muc, final boolean async) { + return this.findOrCreateConversation(account,jid,muc,false, async); } - public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate) { - return this.findOrCreateConversation(account, jid, muc, joinAfterCreate, null); + public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final boolean async) { + return this.findOrCreateConversation(account, jid, muc, joinAfterCreate, null, async); } - public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final MessageArchiveService.Query query) { + public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final MessageArchiveService.Query query, final boolean async) { synchronized (this.conversations) { Conversation conversation = find(account, jid); if (conversation != null) { @@ -1728,7 +1728,7 @@ public class XmppConnectionService extends Service { loadMessagesFromDb = false; } final Conversation c = conversation; - mDatabaseExecutor.execute(new Runnable() { + final Runnable runnable = new Runnable() { @Override public void run() { if (loadMessagesFromDb) { @@ -1752,7 +1752,12 @@ public class XmppConnectionService extends Service { joinMuc(c); } } - }); + }; + if (async) { + mDatabaseExecutor.execute(runnable); + } else { + runnable.run(); + } this.conversations.add(conversation); updateConversationUi(); return conversation; @@ -2454,7 +2459,7 @@ public class XmppConnectionService extends Service { return false; } final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null); - final Conversation conversation = findOrCreateConversation(account, jid, true, false); + final Conversation conversation = findOrCreateConversation(account, jid, true, false, true); joinMuc(conversation, new OnConferenceJoined() { @Override public void onConferenceJoined(final Conversation conversation) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index da9ba754f..b58073298 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -482,7 +482,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers protected void startConversation(User user) { if (user.getRealJid() != null) { - Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false); + Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getRealJid().toBareJid(),false,true); switchToConversation(conversation); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index 9cb7c87ee..c79782fd6 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -265,7 +265,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer try { conversation = xmppConnectionService - .findOrCreateConversation(account, Jid.fromString(share.contact), false); + .findOrCreateConversation(account, Jid.fromString(share.contact), false,true); } catch (final InvalidJidException e) { return; } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 32f2de5cb..35d6201ae 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -316,7 +316,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU protected void openConversationForContact(Contact contact) { Conversation conversation = xmppConnectionService .findOrCreateConversation(contact.getAccount(), - contact.getJid(), false); + contact.getJid(), false, true); switchToConversation(conversation); } @@ -357,7 +357,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show(); return; } - Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true); + Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true); conversation.setBookmark(bookmark); if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", true)) { bookmark.setAutojoin(true); @@ -513,7 +513,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU account.getBookmarks().add(bookmark); xmppConnectionService.pushBookmarks(account); final Conversation conversation = xmppConnectionService - .findOrCreateConversation(account, conferenceJid, true, true); + .findOrCreateConversation(account, conferenceJid, true, true, true); conversation.setBookmark(bookmark); dialog.dismiss(); mCurrentDialog = null; @@ -521,7 +521,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } } else { final Conversation conversation = xmppConnectionService - .findOrCreateConversation(account,conferenceJid, true, true); + .findOrCreateConversation(account,conferenceJid, true, true, true); dialog.dismiss(); mCurrentDialog = null; switchToConversation(conversation); @@ -582,7 +582,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU protected void switchToConversation(Contact contact, String body) { Conversation conversation = xmppConnectionService .findOrCreateConversation(contact.getAccount(), - contact.getJid(),false); + contact.getJid(),false,true); switchToConversation(conversation, body, false); } diff --git a/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java b/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java index 46405fd90..b3184dff1 100644 --- a/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java @@ -100,7 +100,7 @@ public class ExceptionHelper { Conversation conversation = null; try { conversation = service.findOrCreateConversation(finalAccount, - Jid.fromString(Config.BUG_REPORTS), false); + Jid.fromString(Config.BUG_REPORTS), false, true); } catch (final InvalidJidException ignored) { } Message message = new Message(conversation, report diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 38098bbed..a7bb66978 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -313,7 +313,7 @@ public class JingleConnection implements Transferable { this.mJingleStatus = JINGLE_STATUS_INITIATED; Conversation conversation = this.mXmppConnectionService .findOrCreateConversation(account, - packet.getFrom().toBareJid(), false); + packet.getFrom().toBareJid(), false, false); this.message = new Message(conversation, "", Message.ENCRYPTION_NONE); this.message.setStatus(Message.STATUS_RECEIVED); this.mStatus = Transferable.STATUS_OFFER;