mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-16 08:21:26 +00:00
Merge pull request #452 from hjubb/group_explicit_leave_flag
Group explicit leave flag, docs, null fix
This commit is contained in:
commit
e89f54a0b9
@ -298,7 +298,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}.failUi { exception ->
|
}.failUi { exception ->
|
||||||
val message = if (exception is ClosedGroupsProtocol.Error) exception.description else "An error occurred"
|
val message = if (exception is ClosedGroupsProtocol.Error) exception.description else "An error occurred"
|
||||||
Toast.makeText(this@EditClosedGroupActivity, message, Toast.LENGTH_LONG).show()
|
Toast.makeText(this@EditClosedGroupActivity, message, Toast.LENGTH_LONG).show()
|
||||||
loader.fadeOut()
|
loaderContainer.fadeOut()
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,7 +358,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
|||||||
isSSKBasedClosedGroup = false
|
isSSKBasedClosedGroup = false
|
||||||
}
|
}
|
||||||
if (isSSKBasedClosedGroup) {
|
if (isSSKBasedClosedGroup) {
|
||||||
ClosedGroupsProtocolV2.explicitLeave(context, groupPublicKey!!)
|
ClosedGroupsProtocolV2.explicitLeave(context, groupPublicKey!!, notifyUser = false)
|
||||||
} else if (!ClosedGroupsProtocol.leaveLegacyGroup(context, recipient)) {
|
} else if (!ClosedGroupsProtocol.leaveLegacyGroup(context, recipient)) {
|
||||||
Toast.makeText(context, R.string.activity_home_leaving_group_failed_message, Toast.LENGTH_LONG).show()
|
Toast.makeText(context, R.string.activity_home_leaving_group_failed_message, Toast.LENGTH_LONG).show()
|
||||||
return@launch
|
return@launch
|
||||||
|
@ -94,8 +94,12 @@ object ClosedGroupsProtocolV2 {
|
|||||||
return deferred.promise
|
return deferred.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
/**
|
||||||
fun explicitLeave(context: Context, groupPublicKey: String): Promise<Unit, Exception> {
|
* @param notifyUser Inserts an outgoing info message for the user's leave message, useful to set `false` if
|
||||||
|
* you are exiting asynchronously and deleting the thread from [HomeActivity][org.thoughtcrime.securesms.loki.activities.HomeActivity.deleteConversation]
|
||||||
|
*/
|
||||||
|
@JvmStatic @JvmOverloads
|
||||||
|
fun explicitLeave(context: Context, groupPublicKey: String, notifyUser: Boolean = true): Promise<Unit, Exception> {
|
||||||
val deferred = deferred<Unit, Exception>()
|
val deferred = deferred<Unit, Exception>()
|
||||||
ThreadUtils.queue {
|
ThreadUtils.queue {
|
||||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
||||||
@ -119,7 +123,9 @@ object ClosedGroupsProtocolV2 {
|
|||||||
// Notify the user
|
// Notify the user
|
||||||
val infoType = GroupContext.Type.QUIT
|
val infoType = GroupContext.Type.QUIT
|
||||||
val threadID = DatabaseFactory.getThreadDatabase(context).getOrCreateThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false))
|
val threadID = DatabaseFactory.getThreadDatabase(context).getOrCreateThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false))
|
||||||
|
if (notifyUser) {
|
||||||
insertOutgoingInfoMessage(context, groupID, infoType, name, updatedMembers, admins, threadID, sentTime)
|
insertOutgoingInfoMessage(context, groupID, infoType, name, updatedMembers, admins, threadID, sentTime)
|
||||||
|
}
|
||||||
// Remove the group private key and unsubscribe from PNs
|
// Remove the group private key and unsubscribe from PNs
|
||||||
disableLocalGroupAndUnsubscribe(context, apiDB, groupPublicKey, groupDB, groupID, userPublicKey)
|
disableLocalGroupAndUnsubscribe(context, apiDB, groupPublicKey, groupDB, groupID, userPublicKey)
|
||||||
deferred.resolve(Unit)
|
deferred.resolve(Unit)
|
||||||
@ -143,9 +149,7 @@ object ClosedGroupsProtocolV2 {
|
|||||||
val admins = group.admins.map { it.serialize() }
|
val admins = group.admins.map { it.serialize() }
|
||||||
val adminsAsData = admins.map { Hex.fromStringCondensed(it) }
|
val adminsAsData = admins.map { Hex.fromStringCondensed(it) }
|
||||||
val sentTime = System.currentTimeMillis()
|
val sentTime = System.currentTimeMillis()
|
||||||
val encryptionKeyPair = pendingKeyPair.getOrElse(groupPublicKey) {
|
val encryptionKeyPair = pendingKeyPair[groupPublicKey]?.orNull() ?: Optional.fromNullable(apiDB.getLatestClosedGroupEncryptionKeyPair(groupPublicKey)).orNull()
|
||||||
Optional.fromNullable(apiDB.getLatestClosedGroupEncryptionKeyPair(groupPublicKey))
|
|
||||||
}.orNull()
|
|
||||||
if (encryptionKeyPair == null) {
|
if (encryptionKeyPair == null) {
|
||||||
Log.d("Loki", "Couldn't get encryption key pair for closed group.")
|
Log.d("Loki", "Couldn't get encryption key pair for closed group.")
|
||||||
throw Error.NoKeyPair
|
throw Error.NoKeyPair
|
||||||
@ -516,7 +520,7 @@ object ClosedGroupsProtocolV2 {
|
|||||||
val userLeft = userPublicKey == senderPublicKey
|
val userLeft = userPublicKey == senderPublicKey
|
||||||
|
|
||||||
// if the admin left, we left, or we are the only remaining member: remove the group
|
// if the admin left, we left, or we are the only remaining member: remove the group
|
||||||
if (didAdminLeave || userLeft || updatedMemberList.size == 1) {
|
if (didAdminLeave || userLeft) {
|
||||||
disableLocalGroupAndUnsubscribe(context, apiDB, groupPublicKey, groupDB, groupID, userPublicKey)
|
disableLocalGroupAndUnsubscribe(context, apiDB, groupPublicKey, groupDB, groupID, userPublicKey)
|
||||||
} else {
|
} else {
|
||||||
val isCurrentUserAdmin = admins.contains(userPublicKey)
|
val isCurrentUserAdmin = admins.contains(userPublicKey)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user