@@ -35,6 +35,7 @@ import org.thoughtcrime.securesms.api.server.execute
3535import org.thoughtcrime.securesms.database.Storage
3636import org.thoughtcrime.securesms.dependencies.ConfigFactory
3737import org.thoughtcrime.securesms.notifications.PushUnregisterApi
38+ import kotlin.jvm.Throws
3839
3940@HiltWorker
4041class GroupLeavingWorker @AssistedInject constructor(
@@ -140,15 +141,24 @@ class GroupLeavingWorker @AssistedInject constructor(
140141
141142 // We now have an admin option to leave group so we need a way of Deleting the group
142143 // even if there are more admins
143- if (weAreTheOnlyAdmin || deleteGroup) {
144- configFactory.withMutableGroupConfigs(groupId) { configs ->
145- configs.groupInfo.destroyGroup()
144+ if ((weAreTheOnlyAdmin || deleteGroup)) {
145+ try {
146+ configFactory.withMutableGroupConfigs(groupId) { configs ->
147+ configs.groupInfo.destroyGroup()
148+ }
149+
150+ // Must wait until the config is pushed, otherwise if we go through the rest
151+ // of the code it will destroy the conversation, destroying the necessary configs
152+ // along the way, we won't be able to push the "destroyed" state anymore.
153+ configFactory.waitUntilGroupConfigsPushed(groupId, timeoutMills = 0L )
154+ } catch (e: CancellationException ) {
155+ throw e
156+ } catch (e: Throwable ) {
157+ // If the destruction of group can't be done, there's nothing
158+ // else we can do. So we will proceed with the rest where
159+ // we remove the group entry from the database.
160+ Log .e(TAG , " Error while destroying group $groupId . Proceeding..." , e)
146161 }
147-
148- // Must wait until the config is pushed, otherwise if we go through the rest
149- // of the code it will destroy the conversation, destroying the necessary configs
150- // along the way, we won't be able to push the "destroyed" state anymore.
151- configFactory.waitUntilGroupConfigsPushed(groupId, timeoutMills = 0L )
152162 }
153163 }
154164
0 commit comments