feat: Enhance OtherProfileScreen with keyboard management and dialog deletion; expose myPublicKey in ChatViewModel
This commit is contained in:
@@ -78,7 +78,8 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
|
|
||||||
// Текущий диалог
|
// Текущий диалог
|
||||||
private var opponentKey: String? = null
|
private var opponentKey: String? = null
|
||||||
private var myPublicKey: String? = null
|
var myPublicKey: String? = null // 🔥 Публичный доступ для OtherProfileScreen
|
||||||
|
private set
|
||||||
private var myPrivateKey: String? = null
|
private var myPrivateKey: String? = null
|
||||||
|
|
||||||
// UI State
|
// UI State
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ import androidx.compose.material.icons.filled.MoreVert
|
|||||||
import androidx.compose.material.icons.outlined.Block
|
import androidx.compose.material.icons.outlined.Block
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.rosetta.messenger.data.MessageRepository
|
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.ChatViewModel
|
||||||
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
|
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
|
||||||
import com.rosetta.messenger.ui.components.VerifiedBadge
|
import com.rosetta.messenger.ui.components.VerifiedBadge
|
||||||
@@ -33,6 +35,8 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
|
|||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -40,6 +44,9 @@ import androidx.compose.ui.unit.IntOffset
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.rosetta.messenger.network.SearchUser
|
import com.rosetta.messenger.network.SearchUser
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
// Collapsing header constants
|
// Collapsing header constants
|
||||||
@@ -48,7 +55,7 @@ private val COLLAPSED_HEADER_HEIGHT_OTHER = 64.dp
|
|||||||
private val AVATAR_SIZE_EXPANDED_OTHER = 120.dp
|
private val AVATAR_SIZE_EXPANDED_OTHER = 120.dp
|
||||||
private val AVATAR_SIZE_COLLAPSED_OTHER = 36.dp
|
private val AVATAR_SIZE_COLLAPSED_OTHER = 36.dp
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun OtherProfileScreen(
|
fun OtherProfileScreen(
|
||||||
user: SearchUser,
|
user: SearchUser,
|
||||||
@@ -64,9 +71,22 @@ fun OtherProfileScreen(
|
|||||||
val avatarColors = getAvatarColor(user.publicKey, isDarkTheme)
|
val avatarColors = getAvatarColor(user.publicKey, isDarkTheme)
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
// <EFBFBD> Получаем тот же ChatViewModel что и в ChatDetailScreen для очистки истории
|
// 🔥 Получаем тот же ChatViewModel что и в ChatDetailScreen для очистки истории
|
||||||
val viewModel: ChatViewModel = viewModel(key = "chat_${user.publicKey}")
|
val viewModel: ChatViewModel = viewModel(key = "chat_${user.publicKey}")
|
||||||
|
|
||||||
|
// 🎹 Для закрытия клавиатуры
|
||||||
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
val focusManager = LocalFocusManager.current
|
||||||
|
|
||||||
|
// 🗑️ Для удаления диалога
|
||||||
|
val database = remember { RosettaDatabase.getDatabase(context) }
|
||||||
|
|
||||||
|
// 🔥 Закрываем клавиатуру при открытии экрана
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
keyboardController?.hide()
|
||||||
|
focusManager.clearFocus()
|
||||||
|
}
|
||||||
|
|
||||||
// <20>🟢 Наблюдаем за онлайн статусом пользователя в реальном времени
|
// <20>🟢 Наблюдаем за онлайн статусом пользователя в реальном времени
|
||||||
val messageRepository = remember { MessageRepository.getInstance(context) }
|
val messageRepository = remember { MessageRepository.getInstance(context) }
|
||||||
val onlineStatus by messageRepository.observeUserOnlineStatus(user.publicKey)
|
val onlineStatus by messageRepository.observeUserOnlineStatus(user.publicKey)
|
||||||
@@ -178,7 +198,18 @@ fun OtherProfileScreen(
|
|||||||
onAvatarMenuChange = { showAvatarMenu = it },
|
onAvatarMenuChange = { showAvatarMenu = it },
|
||||||
isBlocked = isBlocked,
|
isBlocked = isBlocked,
|
||||||
onBlockToggle = { isBlocked = !isBlocked },
|
onBlockToggle = { isBlocked = !isBlocked },
|
||||||
onClearChat = { viewModel.clearChatHistory() }
|
onClearChat = {
|
||||||
|
viewModel.clearChatHistory()
|
||||||
|
// 🗑️ Удаляем диалог из списка после очистки истории
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val account = viewModel.myPublicKey ?: return@launch
|
||||||
|
database.dialogDao().deleteDialog(account, user.publicKey)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
android.util.Log.e("OtherProfileScreen", "Failed to delete dialog", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user