diff --git a/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigUploader.kt b/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigUploader.kt index 26b16c031e..8e8651539e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigUploader.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigUploader.kt @@ -25,7 +25,7 @@ import org.session.libsession.utilities.ConfigFactoryProtocol import org.session.libsession.utilities.ConfigPushResult import org.session.libsession.utilities.ConfigUpdateNotification import org.session.libsession.utilities.UserConfigType -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsignal.utilities.AccountId import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.Log @@ -98,7 +98,7 @@ class ConfigUploader @Inject constructor( private suspend fun pushGroupConfigsChangesIfNeeded(groupId: AccountId) = coroutineScope { // Only admin can push group configs - val adminKey = configFactory.getClosedGroup(groupId)?.adminKey + val adminKey = configFactory.getGroup(groupId)?.adminKey if (adminKey == null) { Log.i(TAG, "Skipping group config push without admin key") return@coroutineScope diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index ef619d3066..bafb5a7bdd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -32,6 +32,7 @@ import org.session.libsession.messaging.utilities.SodiumUtilities import org.session.libsession.utilities.Address import org.session.libsession.utilities.Address.Companion.fromSerialized import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsession.utilities.getGroup import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.MessageType import org.session.libsession.utilities.recipients.getType diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 9bdd5c33b0..8caf7a4483 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -62,7 +62,7 @@ import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.ProfileKeyUtil import org.session.libsession.utilities.SSKEnvironment import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient.DisappearingState import org.session.libsession.utilities.recipients.MessageType @@ -1016,7 +1016,7 @@ open class Storage @Inject constructor( } override fun getClosedGroupDisplayInfo(groupAccountId: String): GroupDisplayInfo? { - val groupIsAdmin = configFactory.getClosedGroup(AccountId(groupAccountId))?.hasAdminKey() ?: return null + val groupIsAdmin = configFactory.getGroup(AccountId(groupAccountId))?.hasAdminKey() ?: return null return configFactory.withGroupConfigs(AccountId(groupAccountId)) { configs -> val info = configs.groupInfo @@ -1037,7 +1037,7 @@ open class Storage @Inject constructor( val sentTimestamp = message.sentTimestamp ?: clock.currentTimeMills() val senderPublicKey = message.sender val groupName = configFactory.withGroupConfigs(closedGroup) { it.groupInfo.getName() } - ?: configFactory.getClosedGroup(closedGroup)?.name + ?: configFactory.getGroup(closedGroup)?.name val updateData = UpdateMessageData.buildGroupUpdate(message, groupName.orEmpty()) ?: return null diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt index df0100ae64..f0191615e2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt @@ -41,7 +41,7 @@ import org.session.libsession.utilities.MutableUserConfigs import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.UserConfigType import org.session.libsession.utilities.UserConfigs -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsignal.crypto.ecc.DjbECPublicKey import org.session.libsignal.utilities.AccountId import org.session.libsignal.utilities.Hex @@ -118,7 +118,7 @@ class ConfigFactory @Inject constructor( } private fun ensureGroupConfigsInitialized(groupId: AccountId): Pair { - val groupAdminKey = getClosedGroup(groupId)?.adminKey + val groupAdminKey = getGroup(groupId)?.adminKey return synchronized(groupConfigs) { groupConfigs.getOrPut(groupId) { ReentrantReadWriteLock() to GroupConfigsImpl( diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt index 516eb0089e..d030e5bb7b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt @@ -43,7 +43,7 @@ import org.session.libsession.snode.model.BatchResponse import org.session.libsession.snode.utilities.await import org.session.libsession.utilities.Address import org.session.libsession.utilities.SSKEnvironment -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.waitUntilGroupConfigsPushed import org.session.libsignal.messages.SignalServiceGroup @@ -87,7 +87,7 @@ class GroupManagerV2Impl @Inject constructor( */ private fun requireAdminAccess(group: AccountId): ByteArray { return checkNotNull( - configFactory.getClosedGroup(group) + configFactory.getGroup(group) ?.adminKey ?.takeIf { it.isNotEmpty() } ) { "Only admin is allowed to invite members" } @@ -384,7 +384,7 @@ class GroupManagerV2Impl @Inject constructor( return@withContext } - val groupAdminAuth = configFactory.getClosedGroup(groupAccountId)?.adminKey?.let { + val groupAdminAuth = configFactory.getGroup(groupAccountId)?.adminKey?.let { OwnedSwarmAuth.ofClosedGroup(groupAccountId, it) } ?: return@withContext @@ -392,7 +392,7 @@ class GroupManagerV2Impl @Inject constructor( } override suspend fun handleMemberLeftMessage(memberId: AccountId, group: AccountId) { - val closedGroup = configFactory.getClosedGroup(group) ?: return + val closedGroup = configFactory.getGroup(group) ?: return val groupAdminKey = closedGroup.adminKey if (groupAdminKey != null) { @@ -406,7 +406,7 @@ class GroupManagerV2Impl @Inject constructor( } override suspend fun leaveGroup(groupId: AccountId, deleteOnLeave: Boolean) = withContext(dispatcher + SupervisorJob()) { - val group = configFactory.getClosedGroup(groupId) + val group = configFactory.getGroup(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) val weAreTheOnlyAdmin = configFactory.withGroupConfigs(groupId) { config -> @@ -664,7 +664,7 @@ class GroupManagerV2Impl @Inject constructor( promoteMessageTimestamp: Long, ): Unit = withContext(dispatcher) { val userAuth = requireNotNull(storage.userAuth) { "No current user available" } - val group = configFactory.getClosedGroup(groupId) + val group = configFactory.getGroup(groupId) if (group == null) { // If we haven't got the group in the config, it could mean that we haven't @@ -722,7 +722,7 @@ class GroupManagerV2Impl @Inject constructor( inviteMessageTimestamp: Long ) { // If we have already received an invitation in the past, we should not process this one - if (configFactory.getClosedGroup(groupId)?.invited == true) { + if (configFactory.getGroup(groupId)?.invited == true) { return } @@ -772,7 +772,7 @@ class GroupManagerV2Impl @Inject constructor( return@withContext } - val adminKey = configFactory.getClosedGroup(groupId)?.adminKey + val adminKey = configFactory.getGroup(groupId)?.adminKey if (adminKey == null || adminKey.isEmpty()) { return@withContext // We don't have the admin key, we can't process the invite response } @@ -794,7 +794,7 @@ class GroupManagerV2Impl @Inject constructor( pollerFactory.pollerFor(groupId)?.stop() val userId = requireNotNull(storage.getUserPublicKey()) { "No current user available" } - val group = configFactory.getClosedGroup(groupId) ?: return@withContext + val group = configFactory.getGroup(groupId) ?: return@withContext // Retrieve the group name one last time from the group info, // as we are going to clear the keys, we won't have the chance to @@ -877,7 +877,7 @@ class GroupManagerV2Impl @Inject constructor( // meanwhile, if we are admin we can just delete those messages from the group swarm, and otherwise // the admins can pick up the group message and delete the messages on our behalf. - val group = requireNotNull(configFactory.getClosedGroup(groupId)) { + val group = requireNotNull(configFactory.getGroup(groupId)) { "Group doesn't exist" } val userPubKey = requireNotNull(storage.getUserPublicKey()) { "No current user available" } @@ -981,7 +981,7 @@ class GroupManagerV2Impl @Inject constructor( } } - val adminKey = configFactory.getClosedGroup(groupId)?.adminKey + val adminKey = configFactory.getGroup(groupId)?.adminKey if (!senderIsVerifiedAdmin && adminKey != null && hashes.isNotEmpty()) { // If the deletion request comes from a non-admin, and we as an admin, will also delete // the content from the swarm, provided that the messages are actually sent by that user diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/InviteContactsJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/InviteContactsJob.kt index f77fa556a4..4a05a51960 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/InviteContactsJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/InviteContactsJob.kt @@ -20,12 +20,11 @@ import org.session.libsession.snode.utilities.await import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.OTHER_NAME_KEY -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsession.utilities.truncateIdForDisplay import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateInviteMessage import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateMessage import org.session.libsignal.utilities.AccountId -import org.session.libsignal.utilities.prettifiedDescription class InviteContactsJob(val groupSessionId: String, val memberSessionIds: Array) : Job { @@ -101,7 +100,7 @@ class InviteContactsJob(val groupSessionId: String, val memberSessionIds: Array< } val groupName = configs.withGroupConfigs(sessionId) { it.groupInfo.getName() } - ?: configs.getClosedGroup(sessionId)?.name + ?: configs.getGroup(sessionId)?.name val failures = results.filter { it.second.isFailure } // if there are failed invites, display a message diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt index 42cd01ba18..903372e4c2 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt @@ -22,10 +22,9 @@ import org.session.libsession.snode.RawResponse import org.session.libsession.snode.SnodeAPI import org.session.libsession.snode.SnodeClock import org.session.libsession.snode.model.RetrieveMessageResponse -import org.session.libsession.snode.utilities.await import org.session.libsession.utilities.ConfigFactoryProtocol import org.session.libsession.utilities.ConfigMessage -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsignal.database.LokiAPIDatabaseProtocol import org.session.libsignal.exceptions.NonRetryableException import org.session.libsignal.utilities.AccountId @@ -136,7 +135,7 @@ class ClosedGroupPoller( } } - val group = configFactoryProtocol.getClosedGroup(closedGroupSessionId) + val group = configFactoryProtocol.getGroup(closedGroupSessionId) if (group == null) { throw NonRetryableException("Group doesn't exist") } diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt index 13c07b8482..058365869e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt @@ -26,7 +26,7 @@ import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_K import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.OTHER_NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.TIME_KEY -import org.session.libsession.utilities.getClosedGroup +import org.session.libsession.utilities.getGroup import org.session.libsignal.utilities.AccountId object UpdateMessageBuilder { @@ -282,7 +282,7 @@ object UpdateMessageBuilder { } is UpdateMessageData.Kind.GroupInvitation -> { val invitingAdmin = Recipient.from(context, Address.fromSerialized(updateData.invitingAdmin), false) - val approved = configFactory.getClosedGroup(AccountId(updateData.groupAccountId))?.invited == false + val approved = configFactory.getGroup(AccountId(updateData.groupAccountId))?.invited == false return if (invitingAdmin.name != null && !approved) { Phrase.from(context, R.string.messageRequestGroupInvite) .put(NAME_KEY, invitingAdmin.name) diff --git a/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt b/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt index 87c8b08dc9..697806e078 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt @@ -97,7 +97,7 @@ enum class UserConfigType(val namespace: Int) { /** * Shortcut to get the group info for a closed group. Equivalent to: `withUserConfigs { it.userGroups.getClosedGroup(groupId) }` */ -fun ConfigFactoryProtocol.getClosedGroup(groupId: AccountId): GroupInfo.ClosedGroupInfo? { +fun ConfigFactoryProtocol.getGroup(groupId: AccountId): GroupInfo.ClosedGroupInfo? { return withUserConfigs { it.userGroups.getClosedGroup(groupId.hexString) } }