fix: prevent unknown-user banner flicker
fix: wait for private chat relationship resolution before showing the add-contact banner
This commit is contained in:
@@ -603,6 +603,7 @@ private fun ChatScreen(
|
|||||||
val isPrivateChat = state.chatType.equals("private", ignoreCase = true)
|
val isPrivateChat = state.chatType.equals("private", ignoreCase = true)
|
||||||
val showUnknownPrivateChatBanner = isPrivateChat &&
|
val showUnknownPrivateChatBanner = isPrivateChat &&
|
||||||
state.counterpartUserId != null &&
|
state.counterpartUserId != null &&
|
||||||
|
state.isCounterpartRelationshipResolved &&
|
||||||
!state.isCounterpartContact &&
|
!state.isCounterpartContact &&
|
||||||
!state.isCounterpartBlocked
|
!state.isCounterpartBlocked
|
||||||
val canShowMembersTab = state.chatType.equals("group", ignoreCase = true) ||
|
val canShowMembersTab = state.chatType.equals("group", ignoreCase = true) ||
|
||||||
|
|||||||
@@ -778,6 +778,11 @@ class ChatViewModel @Inject constructor(
|
|||||||
it.copy(
|
it.copy(
|
||||||
chatType = chat.type,
|
chatType = chat.type,
|
||||||
counterpartUserId = chat.counterpartUserId,
|
counterpartUserId = chat.counterpartUserId,
|
||||||
|
isCounterpartRelationshipResolved = if (chat.type.equals("private", ignoreCase = true) && chat.counterpartUserId != null) {
|
||||||
|
it.isCounterpartRelationshipResolved
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
},
|
||||||
chatRole = role,
|
chatRole = role,
|
||||||
chatMuted = chat.muted,
|
chatMuted = chat.muted,
|
||||||
chatTitle = chatTitle,
|
chatTitle = chatTitle,
|
||||||
@@ -819,6 +824,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
is AppResult.Success -> {
|
is AppResult.Success -> {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
isCounterpartRelationshipResolved = true,
|
||||||
isCounterpartContact = true,
|
isCounterpartContact = true,
|
||||||
isCounterpartBlocked = false,
|
isCounterpartBlocked = false,
|
||||||
errorMessage = null,
|
errorMessage = null,
|
||||||
@@ -842,6 +848,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
is AppResult.Success -> {
|
is AppResult.Success -> {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
isCounterpartRelationshipResolved = true,
|
||||||
isCounterpartContact = false,
|
isCounterpartContact = false,
|
||||||
isCounterpartBlocked = true,
|
isCounterpartBlocked = true,
|
||||||
errorMessage = null,
|
errorMessage = null,
|
||||||
@@ -964,6 +971,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
privateChatRelationKey = null
|
privateChatRelationKey = null
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
isCounterpartRelationshipResolved = false,
|
||||||
isCounterpartContact = false,
|
isCounterpartContact = false,
|
||||||
isCounterpartBlocked = false,
|
isCounterpartBlocked = false,
|
||||||
)
|
)
|
||||||
@@ -972,6 +980,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
if (!force && privateChatRelationKey == counterpartUserId) return
|
if (!force && privateChatRelationKey == counterpartUserId) return
|
||||||
privateChatRelationKey = counterpartUserId
|
privateChatRelationKey = counterpartUserId
|
||||||
|
_uiState.update { it.copy(isCounterpartRelationshipResolved = false) }
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val contactsResult = accountRepository.listContacts()
|
val contactsResult = accountRepository.listContacts()
|
||||||
val blockedResult = accountRepository.listBlockedUsers()
|
val blockedResult = accountRepository.listBlockedUsers()
|
||||||
@@ -979,6 +988,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
val isBlocked = (blockedResult as? AppResult.Success)?.data?.any { it.id == counterpartUserId } == true
|
val isBlocked = (blockedResult as? AppResult.Success)?.data?.any { it.id == counterpartUserId } == true
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
isCounterpartRelationshipResolved = true,
|
||||||
isCounterpartContact = isContact,
|
isCounterpartContact = isContact,
|
||||||
isCounterpartBlocked = isBlocked,
|
isCounterpartBlocked = isBlocked,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ data class MessageUiState(
|
|||||||
val chatRole: String? = null,
|
val chatRole: String? = null,
|
||||||
val chatMuted: Boolean = false,
|
val chatMuted: Boolean = false,
|
||||||
val chatUnreadCount: Int = 0,
|
val chatUnreadCount: Int = 0,
|
||||||
|
val isCounterpartRelationshipResolved: Boolean = false,
|
||||||
val isCounterpartContact: Boolean = false,
|
val isCounterpartContact: Boolean = false,
|
||||||
val isCounterpartBlocked: Boolean = false,
|
val isCounterpartBlocked: Boolean = false,
|
||||||
val chatMembers: List<ChatMemberItem> = emptyList(),
|
val chatMembers: List<ChatMemberItem> = emptyList(),
|
||||||
|
|||||||
Reference in New Issue
Block a user