Using groupId as the key instead of the server alone

This commit is contained in:
ThomasSession 2024-09-16 09:35:19 +10:00
parent 915c617364
commit 1f6a1b13b2
2 changed files with 9 additions and 6 deletions

View File

@ -117,15 +117,19 @@ class ConversationViewModel(
communityWriteAccessJob?.cancel()
communityWriteAccessJob = viewModelScope.launch {
OpenGroupManager.getCommunitiesWriteAccessFlow()
.map { it[openGroup?.server] }
.map {
if(openGroup?.groupId != null)
it[openGroup?.groupId]
else null
}
.filterNotNull()
.collect{
// update our community object
_openGroup.updateTo(openGroup?.copy(canWrite = it))
// when we get an update on the write access of a community
// we need to update the input text accordingly
_uiState.update {
it.copy(hideInputBar = shouldHideInputBar())
_uiState.update { state ->
state.copy(hideInputBar = shouldHideInputBar())
}
}
}

View File

@ -172,13 +172,12 @@ object OpenGroupManager {
fun updateOpenGroup(openGroup: OpenGroup, context: Context) {
val threadDB = DatabaseComponent.get(context).lokiThreadDatabase()
val openGroupID = "${openGroup.server}.${openGroup.room}"
val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
val threadID = GroupManager.getOpenGroupThreadID(openGroup.groupId, context)
threadDB.setOpenGroupChat(openGroup, threadID)
// update write access for this community
val writeAccesses = _communityWriteAccess.value.toMutableMap()
writeAccesses[openGroup.server] = openGroup.canWrite
writeAccesses[openGroup.groupId] = openGroup.canWrite
_communityWriteAccess.value = writeAccesses
}