From 55e0cda8cb36c102205c17aa099a2f31aa85b289 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 14 Jun 2023 08:42:07 -0500 Subject: [PATCH] We shouldn't call UI things like switching conversation from another thread --- .../ui/StartConversationActivity.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index a24e919f9..2b16138fe 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -565,42 +565,44 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } xmppConnectionService.checkIfMuc(account, contactJid, (isMuc) -> { - if (isMuc) { - if (save) { - Bookmark bookmark = account.getBookmark(contactJid); - if (bookmark != null) { - openConversationsForBookmark(bookmark); - } else { - bookmark = new Bookmark(account, contactJid.asBareJid()); - bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin)); - final String nick = contactJid.getResource(); - if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) { - bookmark.setNick(nick); + runOnUiThread(() -> { + if (isMuc) { + if (save) { + Bookmark bookmark = account.getBookmark(contactJid); + if (bookmark != null) { + openConversationsForBookmark(bookmark); + } else { + bookmark = new Bookmark(account, contactJid.asBareJid()); + bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin)); + final String nick = contactJid.getResource(); + if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) { + bookmark.setNick(nick); + } + xmppConnectionService.createBookmark(account, bookmark); + final Conversation conversation = xmppConnectionService + .findOrCreateConversation(account, contactJid, true, true, true); + bookmark.setConversation(conversation); + switchToConversationDoNotAppend(conversation, invite == null ? null : invite.getBody()); } - xmppConnectionService.createBookmark(account, bookmark); - final Conversation conversation = xmppConnectionService - .findOrCreateConversation(account, contactJid, true, true, true); - bookmark.setConversation(conversation); + } else { + final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, true, true, true); switchToConversationDoNotAppend(conversation, invite == null ? null : invite.getBody()); } } else { - final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, true, true, true); - switchToConversationDoNotAppend(conversation, invite == null ? null : invite.getBody()); - } - } else { - if (save) { - final String preAuth = invite == null ? null : invite.getParameter(XmppUri.PARAMETER_PRE_AUTH); - xmppConnectionService.createContact(contact, true, preAuth); - if (invite != null && invite.hasFingerprints()) { - xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints()); + if (save) { + final String preAuth = invite == null ? null : invite.getParameter(XmppUri.PARAMETER_PRE_AUTH); + xmppConnectionService.createContact(contact, true, preAuth); + if (invite != null && invite.hasFingerprints()) { + xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints()); + } } + switchToConversationDoNotAppend(contact, invite == null ? null : invite.getBody(), call ? "call" : null); } - switchToConversationDoNotAppend(contact, invite == null ? null : invite.getBody(), call ? "call" : null); - } - try { - dialog.dismiss(); - } catch (final IllegalStateException e) { } + try { + dialog.dismiss(); + } catch (final IllegalStateException e) { } + }); }); return false; -- 2.45.2