mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
Leaving message sending optimisation
This commit is contained in:
parent
88df9ff65a
commit
afb7cc1485
@ -3,12 +3,15 @@ package org.thoughtcrime.securesms.groups
|
||||
import android.content.Context
|
||||
import com.google.protobuf.ByteString
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
import kotlinx.coroutines.withContext
|
||||
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_VISIBLE
|
||||
import network.loki.messenger.libsession_util.util.Conversation
|
||||
@ -388,7 +391,7 @@ class GroupManagerV2Impl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun leaveGroup(groupId: AccountId, deleteOnLeave: Boolean) {
|
||||
override suspend fun leaveGroup(groupId: AccountId, deleteOnLeave: Boolean) = withContext(dispatcher + SupervisorJob()) {
|
||||
val group = configFactory.getClosedGroup(groupId)
|
||||
|
||||
// Only send the left/left notification group message when we are not kicked and we are not the only admin (only admin has a special treatment)
|
||||
@ -400,8 +403,10 @@ class GroupManagerV2Impl @Inject constructor(
|
||||
|
||||
if (group?.kicked == false) {
|
||||
val destination = Destination.ClosedGroup(groupId.hexString)
|
||||
val sendMessageTasks = mutableListOf<Deferred<*>>()
|
||||
|
||||
// Always send a "XXX left" message to the group if we can
|
||||
sendMessageTasks += async {
|
||||
MessageSender.send(
|
||||
GroupUpdated(
|
||||
GroupUpdateMessage.newBuilder()
|
||||
@ -410,10 +415,13 @@ class GroupManagerV2Impl @Inject constructor(
|
||||
),
|
||||
destination,
|
||||
isSyncMessage = false
|
||||
)
|
||||
).await()
|
||||
}
|
||||
|
||||
|
||||
// If we are not the only admin, send a left message for other admin to handle the member removal
|
||||
if (!weAreTheOnlyAdmin) {
|
||||
sendMessageTasks += async {
|
||||
MessageSender.send(
|
||||
GroupUpdated(
|
||||
GroupUpdateMessage.newBuilder()
|
||||
@ -426,6 +434,9 @@ class GroupManagerV2Impl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
sendMessageTasks.awaitAll()
|
||||
}
|
||||
|
||||
// If we are the only admin, leaving this group will destroy the group
|
||||
if (weAreTheOnlyAdmin) {
|
||||
configFactory.withMutableGroupConfigs(groupId) { configs ->
|
||||
|
@ -44,7 +44,8 @@ interface GroupManagerV2 {
|
||||
|
||||
suspend fun handleMemberLeft(message: GroupUpdated, group: AccountId)
|
||||
|
||||
suspend fun leaveGroup(groupId: AccountId, deleteOnLeave: Boolean)
|
||||
suspend fun leaveGroup(groupId:
|
||||
AccountId, deleteOnLeave: Boolean)
|
||||
|
||||
suspend fun promoteMember(group: AccountId, members: List<AccountId>)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user