mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 11:05:25 +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 android.content.Context
|
||||||
import com.google.protobuf.ByteString
|
import com.google.protobuf.ByteString
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.filterIsInstance
|
import kotlinx.coroutines.flow.filterIsInstance
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.supervisorScope
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_VISIBLE
|
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_VISIBLE
|
||||||
import network.loki.messenger.libsession_util.util.Conversation
|
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)
|
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)
|
// 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,30 +403,38 @@ class GroupManagerV2Impl @Inject constructor(
|
|||||||
|
|
||||||
if (group?.kicked == false) {
|
if (group?.kicked == false) {
|
||||||
val destination = Destination.ClosedGroup(groupId.hexString)
|
val destination = Destination.ClosedGroup(groupId.hexString)
|
||||||
|
val sendMessageTasks = mutableListOf<Deferred<*>>()
|
||||||
|
|
||||||
// Always send a "XXX left" message to the group if we can
|
// Always send a "XXX left" message to the group if we can
|
||||||
MessageSender.send(
|
sendMessageTasks += async {
|
||||||
GroupUpdated(
|
|
||||||
GroupUpdateMessage.newBuilder()
|
|
||||||
.setMemberLeftNotificationMessage(DataMessage.GroupUpdateMemberLeftNotificationMessage.getDefaultInstance())
|
|
||||||
.build()
|
|
||||||
),
|
|
||||||
destination,
|
|
||||||
isSyncMessage = false
|
|
||||||
)
|
|
||||||
|
|
||||||
// If we are not the only admin, send a left message for other admin to handle the member removal
|
|
||||||
if (!weAreTheOnlyAdmin) {
|
|
||||||
MessageSender.send(
|
MessageSender.send(
|
||||||
GroupUpdated(
|
GroupUpdated(
|
||||||
GroupUpdateMessage.newBuilder()
|
GroupUpdateMessage.newBuilder()
|
||||||
.setMemberLeftMessage(DataMessage.GroupUpdateMemberLeftMessage.getDefaultInstance())
|
.setMemberLeftNotificationMessage(DataMessage.GroupUpdateMemberLeftNotificationMessage.getDefaultInstance())
|
||||||
.build()
|
.build()
|
||||||
),
|
),
|
||||||
destination,
|
destination,
|
||||||
isSyncMessage = false
|
isSyncMessage = false
|
||||||
).await()
|
).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()
|
||||||
|
.setMemberLeftMessage(DataMessage.GroupUpdateMemberLeftMessage.getDefaultInstance())
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
destination,
|
||||||
|
isSyncMessage = false
|
||||||
|
).await()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessageTasks.awaitAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are the only admin, leaving this group will destroy the group
|
// If we are the only admin, leaving this group will destroy the group
|
||||||
|
@ -44,7 +44,8 @@ interface GroupManagerV2 {
|
|||||||
|
|
||||||
suspend fun handleMemberLeft(message: GroupUpdated, group: AccountId)
|
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>)
|
suspend fun promoteMember(group: AccountId, members: List<AccountId>)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user