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

View File

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