From 8dd606cbb32cfdf0f8be00a8282a84cd385284a3 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Fri, 14 May 2021 10:26:38 +1000 Subject: [PATCH] join open group code executed in a coroutine so it's not blocking the UI --- .../loki/views/OpenGroupInvitationView.kt | 31 ++++++++++++++----- .../res/layout/open_group_invitation_view.xml | 6 ++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/views/OpenGroupInvitationView.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/views/OpenGroupInvitationView.kt index 359372b71a..b0d0c440c5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/views/OpenGroupInvitationView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/views/OpenGroupInvitationView.kt @@ -8,6 +8,9 @@ import android.widget.ImageView import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AlertDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import network.loki.messenger.R import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.OpenGroupUrlParser @@ -69,15 +72,27 @@ class OpenGroupInvitationView : FrameLayout { builder.setMessage(message) builder.setPositiveButton(R.string.yes) { dialog, which -> - try { - val group = OpenGroupUtilities.addGroup(context, openGroup.server, openGroup.room, openGroup.serverPublicKey) - val threadID = GroupManager.getOpenGroupThreadID(group.id, context) - val groupID = GroupUtil.getEncodedOpenGroupID(group.id.toByteArray()) + GlobalScope.launch(Dispatchers.IO) { + try { + dialog.dismiss() + val group = OpenGroupUtilities.addGroup( + context, + openGroup.server, + openGroup.room, + openGroup.serverPublicKey + ) + val threadID = GroupManager.getOpenGroupThreadID(group.id, context) + val groupID = GroupUtil.getEncodedOpenGroupID(group.id.toByteArray()) - MultiDeviceProtocol.forceSyncConfigurationNowIfNeeded(context) - } catch (e: Exception) { - Log.e("JoinPublicChatActivity", "Failed to join open group.", e) - Toast.makeText(context, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show() + MultiDeviceProtocol.forceSyncConfigurationNowIfNeeded(context) + } catch (e: Exception) { + Log.e("JoinPublicChatActivity", "Failed to join open group.", e) + Toast.makeText( + context, + R.string.activity_join_public_chat_error, + Toast.LENGTH_SHORT + ).show() + } } } diff --git a/app/src/main/res/layout/open_group_invitation_view.xml b/app/src/main/res/layout/open_group_invitation_view.xml index b70dd8dd2c..4074ca3174 100644 --- a/app/src/main/res/layout/open_group_invitation_view.xml +++ b/app/src/main/res/layout/open_group_invitation_view.xml @@ -28,11 +28,11 @@