feat: Integrate ChatsListViewModel for user block/unblock functionality in OtherProfileScreen

This commit is contained in:
2026-01-28 02:26:35 +05:00
parent 6b59ed9bd8
commit 9afd9c1d67
5 changed files with 34 additions and 13 deletions

View File

@@ -20,6 +20,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.rosetta.messenger.data.MessageRepository
import com.rosetta.messenger.database.RosettaDatabase
import com.rosetta.messenger.ui.chats.ChatViewModel
import com.rosetta.messenger.ui.chats.ChatsListViewModel
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
import com.rosetta.messenger.ui.components.VerifiedBadge
import androidx.compose.ui.Alignment
@@ -78,6 +79,15 @@ fun OtherProfileScreen(
// 🔥 Получаем тот же ChatViewModel что и в ChatDetailScreen для очистки истории
val viewModel: ChatViewModel = viewModel(key = "chat_${user.publicKey}")
// 🔥 ChatsListViewModel для блокировки/разблокировки
val chatsListViewModel: ChatsListViewModel = viewModel()
val coroutineScope = rememberCoroutineScope()
// 🔥 Загружаем статус блокировки при открытии экрана
LaunchedEffect(user.publicKey) {
isBlocked = chatsListViewModel.isUserBlocked(user.publicKey)
}
// 🎹 Для закрытия клавиатуры
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current
@@ -201,7 +211,17 @@ fun OtherProfileScreen(
showAvatarMenu = showAvatarMenu,
onAvatarMenuChange = { showAvatarMenu = it },
isBlocked = isBlocked,
onBlockToggle = { isBlocked = !isBlocked },
onBlockToggle = {
coroutineScope.launch {
if (isBlocked) {
chatsListViewModel.unblockUser(user.publicKey)
} else {
chatsListViewModel.blockUser(user.publicKey)
}
// Обновляем локальное состояние
isBlocked = !isBlocked
}
},
avatarRepository = avatarRepository,
onClearChat = {
viewModel.clearChatHistory()