From 9be90a589e211f24e89f2e95fc9cb71a3a4c7ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asiel=20D=C3=ADaz=20Ben=C3=ADtez?= Date: Wed, 4 Aug 2021 09:05:33 -0400 Subject: [PATCH 1/2] avoid NullPointerException (#2013) --- .../thoughtcrime/securesms/ConversationListFragment.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index 7cc125877..e7f076dcd 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -418,7 +418,14 @@ public class ConversationListFragment extends Fragment } else { listflags |= DcContext.DC_GCL_ADD_ALLDONE_HINT; } - DcChatlist chatlist = DcHelper.getContext(getContext()).getChatlist(listflags, queryFilter.isEmpty() ? null : queryFilter, 0); + + Context context = getContext(); + if (context == null) { + // can't load chat list at this time, see: https://github.com/deltachat/deltachat-android/issues/2012 + Log.w(TAG, "Ignoring call to loadChatlist()"); + return; + } + DcChatlist chatlist = DcHelper.getContext(context).getChatlist(listflags, queryFilter.isEmpty() ? null : queryFilter, 0); Util.runOnMain(() -> { if (chatlist.getCnt() <= 0 && TextUtils.isEmpty(queryFilter)) { From 726f751cac08f723bf8d48de860d30c619d3eeea Mon Sep 17 00:00:00 2001 From: bjoern Date: Wed, 4 Aug 2021 15:05:45 +0200 Subject: [PATCH 2/2] keep selection when migrating several accounts (#2011) postpone selection after the last migration as migrateAccount() currently selects the migrated account. before, the selectAccount() call was useless if another migrateAccount() call follows. --- .../thoughtcrime/securesms/connect/AccountManager.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/connect/AccountManager.java b/src/org/thoughtcrime/securesms/connect/AccountManager.java index 626fde6f8..276bc174d 100644 --- a/src/org/thoughtcrime/securesms/connect/AccountManager.java +++ b/src/org/thoughtcrime/securesms/connect/AccountManager.java @@ -52,6 +52,8 @@ public class AccountManager { public void migrateToDcAccounts(ApplicationContext context) { try { + int selectAccountId = 0; + File[] files = context.getFilesDir().listFiles(); for (File file : files) { // old accounts have the pattern "messenger*.db" @@ -61,11 +63,17 @@ public class AccountManager { String selName = PreferenceManager.getDefaultSharedPreferences(context) .getString("curr_account_db_name", "messenger.db"); if (file.getName().equals(selName)) { - context.dcAccounts.selectAccount(accountId); + // postpone selection as it will otherwise be overwritten by the next migrateAccount() call + // (if more than one account needs to be migrated) + selectAccountId = accountId; } } } } + + if (selectAccountId != 0) { + context.dcAccounts.selectAccount(selectAccountId); + } } catch (Exception e) { e.printStackTrace(); }