From e15c8b73161faf9bd2acb2a548fb0e77a10f218e Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 14 Mar 2017 20:32:21 +0100 Subject: don't open conversation when opening contact details --- .../messenger/services/XmppConnectionService.java | 55 ++++++++++++++++++++++ .../messenger/ui/ContactDetailsActivity.java | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index ce839766d..4ea6b5f35 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1861,6 +1861,61 @@ public class XmppConnectionService extends Service { } } + public Conversation findConversation(final Account account, final Jid jid, final boolean muc) { + synchronized (this.conversations) { + Conversation conversation = find(account, jid); + if (conversation != null) { + return conversation; + } + conversation = databaseBackend.findConversation(account, jid); + final boolean loadMessagesFromDb; + if (conversation != null) { + conversation.setStatus(Conversation.STATUS_AVAILABLE); + conversation.setAccount(account); + if (muc) { + conversation.setMode(Conversation.MODE_MULTI); + conversation.setContactJid(jid); + } else { + conversation.setMode(Conversation.MODE_SINGLE); + conversation.setContactJid(jid.toBareJid()); + } + databaseBackend.updateConversation(conversation); + loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true,false); + } else { + String conversationName; + Contact contact = account.getRoster().getContact(jid); + if (contact != null) { + conversationName = contact.getDisplayName(); + } else { + conversationName = jid.getLocalpart(); + } + if (muc) { + conversation = new Conversation(conversationName, account, jid, + Conversation.MODE_MULTI); + } else { + conversation = new Conversation(conversationName, account, jid.toBareJid(), + Conversation.MODE_SINGLE); + } + this.databaseBackend.createConversation(conversation); + loadMessagesFromDb = false; + } + final Conversation c = conversation; + mDatabaseExecutor.execute(new Runnable() { + @Override + public void run() { + if (loadMessagesFromDb) { + c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE)); + updateConversationUi(); + c.messagesLoaded.set(true); + } + checkDeletedFiles(c); + } + }); + updateConversationUi(); + return conversation; + } + } + public void archiveConversation(Conversation conversation) { getNotificationService().clear(conversation); conversation.setStatus(Conversation.STATUS_ARCHIVED); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 1837e6df5..063054c0b 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -669,7 +669,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp if (account == null) { return; } - this.mConversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false); + this.mConversation = xmppConnectionService.findConversation(account, contactJid, false); if (this.mConversation != null) { populateView(); } -- cgit v1.2.3