mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Show a loader while the group is updating
This commit is contained in:
parent
a34b1f74b3
commit
389b4b9768
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context="org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivity">
|
||||
|
||||
<LinearLayout
|
||||
@ -146,4 +146,22 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/loader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#A4000000"
|
||||
android:visibility="gone"
|
||||
android:alpha="0">
|
||||
|
||||
<com.github.ybq.android.spinkit.SpinKitView
|
||||
style="@style/SpinKitView.Large.ThreeBounce"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_centerInParent="true"
|
||||
app:SpinKit_Color="@android:color/white" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
@ -13,17 +13,23 @@ import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import kotlinx.android.synthetic.main.activity_create_closed_group.*
|
||||
import kotlinx.android.synthetic.main.activity_create_closed_group.emptyStateContainer
|
||||
import kotlinx.android.synthetic.main.activity_create_closed_group.mainContentContainer
|
||||
import kotlinx.android.synthetic.main.activity_edit_closed_group.*
|
||||
import kotlinx.android.synthetic.main.activity_edit_closed_group.loader
|
||||
import kotlinx.android.synthetic.main.activity_linked_devices.recyclerView
|
||||
import network.loki.messenger.R
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.groups.GroupManager
|
||||
import org.thoughtcrime.securesms.loki.dialogs.ClosedGroupEditingOptionsBottomSheet
|
||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
|
||||
import org.thoughtcrime.securesms.loki.utilities.fadeIn
|
||||
import org.thoughtcrime.securesms.loki.utilities.fadeOut
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.GroupUtil
|
||||
@ -238,10 +244,16 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
||||
}
|
||||
|
||||
if (isSSKBasedClosedGroup) {
|
||||
ClosedGroupsProtocol.update(this, groupPublicKey!!, members.map { it.address.serialize() }, name)
|
||||
loader.fadeIn()
|
||||
ClosedGroupsProtocol.update(this, groupPublicKey!!, members.map { it.address.serialize() }, name).successUi {
|
||||
loader.fadeOut()
|
||||
finish()
|
||||
}.failUi { exception ->
|
||||
val message = if (exception is ClosedGroupsProtocol.Error) exception.description else "An error occurred"
|
||||
Toast.makeText(this@EditClosedGroupActivity, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
} else {
|
||||
GroupManager.updateGroup(this, groupID, members, null, name, admins)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup.GroupType
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext
|
||||
import org.whispersystems.signalservice.loki.api.SnodeAPI
|
||||
import org.whispersystems.signalservice.loki.protocol.closedgroups.ClosedGroupRatchet
|
||||
import org.whispersystems.signalservice.loki.protocol.closedgroups.ClosedGroupSenderKey
|
||||
import org.whispersystems.signalservice.loki.protocol.closedgroups.SharedSenderKeysImplementation
|
||||
@ -39,6 +40,12 @@ object ClosedGroupsProtocol {
|
||||
val isSharedSenderKeysEnabled = true
|
||||
val groupSizeLimit = 20
|
||||
|
||||
sealed class Error(val description: String) : Exception() {
|
||||
object NoThread : Error("Couldn't find a thread associated with the given group public key")
|
||||
object NoPrivateKey : Error("Couldn't find a private key associated with the given group public key.")
|
||||
object InvalidUpdate : Error("Invalid group update.")
|
||||
}
|
||||
|
||||
public fun createClosedGroup(context: Context, name: String, members: Collection<String>): Promise<String, Exception> {
|
||||
val deferred = deferred<String, Exception>()
|
||||
Thread {
|
||||
@ -98,10 +105,12 @@ object ClosedGroupsProtocol {
|
||||
val name = group.title
|
||||
val oldMembers = group.members.map { it.serialize() }.toSet()
|
||||
val newMembers = oldMembers.minus(userPublicKey)
|
||||
update(context, groupPublicKey, newMembers, name)
|
||||
return update(context, groupPublicKey, newMembers, name).get()
|
||||
}
|
||||
|
||||
public fun update(context: Context, groupPublicKey: String, members: Collection<String>, name: String) {
|
||||
public fun update(context: Context, groupPublicKey: String, members: Collection<String>, name: String): Promise<Unit, Exception> {
|
||||
val deferred = deferred<Unit, Exception>()
|
||||
Thread {
|
||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
||||
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
||||
@ -109,7 +118,7 @@ object ClosedGroupsProtocol {
|
||||
val group = groupDB.getGroup(groupID).orNull()
|
||||
if (group == null) {
|
||||
Log.d("Loki", "Can't update nonexistent closed group.")
|
||||
return
|
||||
return@Thread deferred.reject(Error.NoThread)
|
||||
}
|
||||
val oldMembers = group.members.map { it.serialize() }.toSet()
|
||||
val newMembers = members.minus(oldMembers)
|
||||
@ -119,7 +128,7 @@ object ClosedGroupsProtocol {
|
||||
val groupPrivateKey = DatabaseFactory.getSSKDatabase(context).getClosedGroupPrivateKey(groupPublicKey)
|
||||
if (groupPrivateKey == null) {
|
||||
Log.d("Loki", "Couldn't get private key for closed group.")
|
||||
return
|
||||
return@Thread deferred.reject(Error.NoPrivateKey)
|
||||
}
|
||||
val wasAnyUserRemoved = members.toSet().intersect(oldMembers) != oldMembers.toSet()
|
||||
val removedMembers = oldMembers.minus(members)
|
||||
@ -128,7 +137,7 @@ object ClosedGroupsProtocol {
|
||||
if (wasAnyUserRemoved) {
|
||||
if (isUserLeaving && removedMembers.count() != 1) {
|
||||
Log.d("Loki", "Can't remove self and others simultaneously.")
|
||||
return
|
||||
return@Thread deferred.reject(Error.InvalidUpdate)
|
||||
}
|
||||
// Establish sessions if needed
|
||||
establishSessionsWithMembersIfNeeded(context, members)
|
||||
@ -215,6 +224,9 @@ object ClosedGroupsProtocol {
|
||||
val infoType = if (isUserLeaving) GroupContext.Type.QUIT else GroupContext.Type.UPDATE
|
||||
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false))
|
||||
insertOutgoingInfoMessage(context, groupID, infoType, name, members, admins, threadID)
|
||||
deferred.resolve(Unit)
|
||||
}.start()
|
||||
return deferred.promise
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
Loading…
x
Reference in New Issue
Block a user