Various issues

This commit is contained in:
SessionHero01
2024-10-02 15:17:13 +10:00
parent 3faae5ddbe
commit 1f5fde0d9a
13 changed files with 133 additions and 104 deletions

View File

@@ -41,6 +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.libsignal.crypto.ecc.DjbECPublicKey
import org.session.libsignal.utilities.AccountId
import org.session.libsignal.utilities.Hex
@@ -299,11 +300,7 @@ class ConfigFactory @Inject constructor(
override fun <T> withGroupConfigs(groupId: AccountId, cb: (GroupConfigs) -> T): T {
val configs = groupConfigs.getOrPut(groupId) {
val groupAdminKey = requireNotNull(withUserConfigs {
it.userGroups.getClosedGroup(groupId.hexString)
}) {
"Group not found"
}.adminKey
val groupAdminKey = getClosedGroup(groupId)?.adminKey
GroupConfigsImpl(
requiresCurrentUserED25519SecKey(),
@@ -318,7 +315,14 @@ class ConfigFactory @Inject constructor(
}
}
private fun <T> doWithMutableGroupConfigs(groupId: AccountId, cb: (GroupConfigsImpl) -> Pair<T, Boolean>): T {
private fun <T> doWithMutableGroupConfigs(
groupId: AccountId,
recreateConfigInstances: Boolean,
cb: (GroupConfigsImpl) -> Pair<T, Boolean>): T {
if (recreateConfigInstances) {
groupConfigs.remove(groupId)
}
val (result, changed) = withGroupConfigs(groupId) { configs ->
cb(configs as GroupConfigsImpl)
}
@@ -336,9 +340,10 @@ class ConfigFactory @Inject constructor(
override fun <T> withMutableGroupConfigs(
groupId: AccountId,
recreateConfigInstances: Boolean,
cb: (MutableGroupConfigs) -> T
): T {
return doWithMutableGroupConfigs(groupId) {
return doWithMutableGroupConfigs(recreateConfigInstances = recreateConfigInstances, groupId = groupId) {
cb(it) to it.dumpIfNeeded()
}
}
@@ -376,7 +381,7 @@ class ConfigFactory @Inject constructor(
info: List<ConfigMessage>,
members: List<ConfigMessage>
) {
doWithMutableGroupConfigs(groupId) { configs ->
doWithMutableGroupConfigs(groupId, false) { configs ->
// Keys must be loaded first as they are used to decrypt the other config messages
val keysLoaded = keys.fold(false) { acc, msg ->
configs.groupKeys.loadKey(msg.data, msg.hash, msg.timestamp, configs.groupInfo.pointer, configs.groupMembers.pointer) || acc
@@ -424,7 +429,7 @@ class ConfigFactory @Inject constructor(
return
}
doWithMutableGroupConfigs(groupId) { configs ->
doWithMutableGroupConfigs(groupId, false) { configs ->
members?.let { (push, result) -> configs.groupMembers.confirmPushed(push.seqNo, result.hash) }
info?.let { (push, result) -> configs.groupInfo.confirmPushed(push.seqNo, result.hash) }
keysPush?.let { (hash, timestamp) ->

View File

@@ -634,7 +634,7 @@ class GroupManagerV2Impl @Inject constructor(
pollerFactory.pollerFor(group.groupAccountId)?.start()
}
override suspend fun onReceiveInvitation(
override suspend fun handleInvitation(
groupId: AccountId,
groupName: String,
authData: ByteArray,
@@ -663,7 +663,7 @@ class GroupManagerV2Impl @Inject constructor(
}
}
override suspend fun onReceivePromotion(
override suspend fun handlePromotion(
groupId: AccountId,
groupName: String,
adminKey: ByteArray,
@@ -692,7 +692,7 @@ class GroupManagerV2Impl @Inject constructor(
}
// Update our promote state
configFactory.withMutableGroupConfigs(groupId) { configs ->
configFactory.withMutableGroupConfigs(recreateConfigInstances = true, groupId = groupId) { configs ->
configs.groupMembers.get(userAuth.accountId.hexString)?.let { member ->
configs.groupMembers.set(member.setPromoteSuccess())
}

View File

@@ -60,7 +60,7 @@ internal class LoadingViewModel @Inject constructor(
val events = _events.asSharedFlow()
init {
viewModelScope.launch(Dispatchers.IO) {
viewModelScope.launch {
state.flatMapLatest {
when (it) {
State.LOADING -> progress(0f, 1f, TIMEOUT_TIME)