join open group code executed in a coroutine so it's not blocking the UI

This commit is contained in:
Brice-W 2021-05-14 10:26:38 +10:00
parent b562aa5738
commit 8dd606cbb3
2 changed files with 26 additions and 11 deletions

View File

@ -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 ->
GlobalScope.launch(Dispatchers.IO) {
try {
val group = OpenGroupUtilities.addGroup(context, openGroup.server, openGroup.room, openGroup.serverPublicKey)
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()
Toast.makeText(
context,
R.string.activity_join_public_chat_error,
Toast.LENGTH_SHORT
).show()
}
}
}

View File

@ -28,11 +28,11 @@
<ImageView
android:id="@+id/open_group_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="48dp"
android:clickable="false"
android:visibility="gone"
android:layout_margin="8dp"
android:layout_margin="4dp"
android:contentDescription="@string/open_group_invitation_view__join_accessibility_description"
android:src="@drawable/ic_globe" />