From e351be41c98b2c3c0eae678a8d50e27670ab6b0f Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 11 Sep 2020 09:03:57 +1000 Subject: [PATCH] Fix legacy closed group leaving crash --- .../securesms/loki/activities/HomeActivity.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index 251f756761..e0bba59ccf 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -52,6 +52,7 @@ import org.whispersystems.signalservice.loki.protocol.sessionmanagement.SessionM import org.whispersystems.signalservice.loki.protocol.shelved.multidevice.MultiDeviceProtocol import org.whispersystems.signalservice.loki.protocol.shelved.syncmessages.SyncMessagesProtocol import org.whispersystems.signalservice.loki.utilities.toHexString +import java.io.IOException class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListener, SeedReminderViewDelegate, NewConversationButtonSetViewDelegate { private lateinit var glide: GlideRequests @@ -361,10 +362,17 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe val isClosedGroup = recipient.address.isClosedGroup // Send a leave group message if this is an active closed group if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) { - val groupPublicKey = ClosedGroupsProtocol.doubleDecodeGroupID(recipient.address.toString()).toHexString() - val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey) + var isSSKBasedClosedGroup: Boolean + var groupPublicKey: String? + try { + groupPublicKey = ClosedGroupsProtocol.doubleDecodeGroupID(recipient.address.toString()).toHexString() + isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey) + } catch (e: IOException) { + groupPublicKey = null + isSSKBasedClosedGroup = false + } if (isSSKBasedClosedGroup) { - ClosedGroupsProtocol.leave(this, groupPublicKey) + ClosedGroupsProtocol.leave(this, groupPublicKey!!) } else if (!ClosedGroupsProtocol.leaveLegacyGroup(this, recipient)) { Toast.makeText(this, R.string.activity_home_leaving_group_failed_message, Toast.LENGTH_LONG).show() return@setPositiveButton