Extract login into GroupManagerV2

This commit is contained in:
SessionHero01
2024-09-18 10:46:49 +10:00
parent 32f95337d5
commit 80e3e563ce
16 changed files with 597 additions and 493 deletions

View File

@@ -177,16 +177,11 @@ interface StorageProtocol {
fun setGroupInviteCompleteIfNeeded(approved: Boolean, invitee: String, closedGroup: AccountId)
fun getLibSessionClosedGroup(groupAccountId: String): GroupInfo.ClosedGroupInfo?
fun getClosedGroupDisplayInfo(groupAccountId: String): GroupDisplayInfo?
fun inviteClosedGroupMembers(groupAccountId: String, invitees: List<String>)
fun insertGroupInfoChange(message: GroupUpdated, closedGroup: AccountId): Long?
fun insertGroupInfoLeaving(closedGroup: AccountId): Long?
fun updateGroupInfoChange(messageId: Long, newType: UpdateMessageData.Kind)
fun promoteMember(groupAccountId: AccountId, promotions: List<AccountId>)
suspend fun removeMember(groupAccountId: AccountId, removedMembers: List<AccountId>, removeMessages: Boolean)
suspend fun handleMemberLeft(message: GroupUpdated, closedGroupId: AccountId)
fun handleMemberLeftNotification(message: GroupUpdated, closedGroupId: AccountId)
fun handleKicked(groupAccountId: AccountId)
fun leaveGroup(groupSessionId: String, deleteOnLeave: Boolean): Boolean
fun setName(groupSessionId: String, newName: String)
fun sendGroupUpdateDeleteMessage(groupSessionId: String, messageHashes: List<String>): Promise<Unit, Exception>

View File

@@ -4,6 +4,7 @@ import android.content.Context
import com.goterl.lazysodium.utils.KeyPair
import org.session.libsession.database.MessageDataProvider
import org.session.libsession.database.StorageProtocol
import org.session.libsession.messaging.groups.GroupManagerV2
import org.session.libsession.messaging.notifications.TokenFetcher
import org.session.libsession.snode.OwnedSwarmAuth
import org.session.libsession.utilities.ConfigFactoryProtocol
@@ -20,6 +21,7 @@ class MessagingModuleConfiguration(
val lastSentTimestampCache: LastSentTimestampCache,
val toaster: Toaster,
val tokenFetcher: TokenFetcher,
val groupManagerV2: GroupManagerV2,
) {
companion object {

View File

@@ -0,0 +1,28 @@
package org.session.libsession.messaging.groups
import org.session.libsession.messaging.messages.control.GroupUpdated
import org.session.libsignal.utilities.AccountId
/**
* Business logic handling group v2 operations like inviting members,
* removing members, promoting members, leaving groups, etc.
*/
interface GroupManagerV2 {
suspend fun inviteMembers(
group: AccountId,
newMembers: List<AccountId>,
shareHistory: Boolean
)
suspend fun removeMembers(
groupAccountId: AccountId,
removedMembers: List<AccountId>,
removeMessages: Boolean
)
suspend fun handleMemberLeft(message: GroupUpdated, closedGroupId: AccountId)
suspend fun leaveGroup(group: AccountId, deleteOnLeave: Boolean)
suspend fun promoteMember(group: AccountId, members: List<AccountId>)
}

View File

@@ -294,12 +294,14 @@ data class ConfigurationSyncJob(val destination: Destination) : Job {
)
}
fun GroupKeysConfig.messageInformation(auth: OwnedSwarmAuth): ConfigMessageInformation {
fun GroupKeysConfig.messageInformation(auth: OwnedSwarmAuth): ConfigMessageInformation? {
val pending = pendingConfig() ?: return null
val sentTimestamp = SnodeAPI.nowWithOffset
val message =
SnodeMessage(
auth.accountId.hexString,
Base64.encodeBytes(pendingConfig()!!), // should not be null from checking has pending
Base64.encodeBytes(pending),
SnodeMessage.CONFIG_TTL,
sentTimestamp
)

View File

@@ -28,7 +28,11 @@ class LibSessionGroupLeavingJob(val accountId: AccountId, val deleteOnLeave: Boo
// do actual group leave request
// on success
if (storage.leaveGroup(accountId.hexString, deleteOnLeave)) {
val leaveGroup = kotlin.runCatching {
MessagingModuleConfiguration.shared.groupManagerV2.leaveGroup(accountId, deleteOnLeave)
}
if (leaveGroup.isSuccess) {
// message is already deleted, succeed
delegate?.handleJobSucceeded(this, dispatcherName)
} else {

View File

@@ -635,9 +635,10 @@ private fun handleMemberChange(message: GroupUpdated, closedGroup: AccountId) {
}
private fun handleMemberLeft(message: GroupUpdated, closedGroup: AccountId) {
val storage = MessagingModuleConfiguration.shared.storage
GlobalScope.launch(Dispatchers.Default) {
storage.handleMemberLeft(message, closedGroup)
runCatching {
MessagingModuleConfiguration.shared.groupManagerV2.handleMemberLeft(message, closedGroup)
}
}
}