dm-76
This commit is contained in:
parent
18243f8582
commit
69d634fd9d
2 changed files with 19 additions and 10 deletions
|
|
@ -186,15 +186,21 @@ fun MessageMessaging(
|
|||
)
|
||||
},
|
||||
bottomBar = {
|
||||
// 👈 1. 直接將 actionMessage 作為 targetState
|
||||
// 👈 直接將 actionMessage 作為 targetState
|
||||
AnimatedContent(
|
||||
targetState = actionMessage,
|
||||
label = "BottomBarSwitchAnimation"
|
||||
) { currentActionMessage -> // 👈 2. 這裡拿到的 currentActionMessage 在動畫期間會保持不變
|
||||
) { currentActionMessage ->
|
||||
if (currentActionMessage != null) {
|
||||
|
||||
// 💡 核心修正:從目前的 uiState 中安全地取出當前使用者的 ID 來做比較
|
||||
val currentUserId = (uiState as? MessagesUiState.Success)?.currentUserId
|
||||
val isOwnMessage = currentActionMessage.senderId == currentUserId
|
||||
|
||||
// 顯示動作選單
|
||||
MessageActionMenuRow(
|
||||
message = currentActionMessage, // 👈 3. 乾淨安全,再也不需要寫 !! 了
|
||||
message = currentActionMessage,
|
||||
isOwnMessage = isOwnMessage, // 👈 記得要把這個新參數帶進去!
|
||||
onCancel = { viewModel.clearActionMessage() },
|
||||
onReplyClick = { msg ->
|
||||
viewModel.setReplyingMessage(msg)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ fun MessageActionMenuRow(
|
|||
onCancel: () -> Unit,
|
||||
onReplyClick: (Message) -> Unit, // 👈 修正:這裡只需要定義型態
|
||||
onDeleteClick: (Message) -> Unit,
|
||||
isOwnMessage: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
// 💡 取得系統剪貼簿,用來實作「複製文字」功能
|
||||
|
|
@ -117,7 +118,8 @@ fun MessageActionMenuRow(
|
|||
}
|
||||
)
|
||||
|
||||
// 3. 刪除
|
||||
// 3. 刪除:只有在自己的訊息時才顯示 👈
|
||||
if (isOwnMessage) {
|
||||
ChatMenuButton(
|
||||
imageVector = Icons.Default.Delete,
|
||||
label = "刪除",
|
||||
|
|
@ -125,6 +127,7 @@ fun MessageActionMenuRow(
|
|||
onClick = { onDeleteClick(message) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 為了讓中間的按鈕群置中,右邊放一個等寬的 Spacer
|
||||
Spacer(modifier = Modifier.size(48.dp))
|
||||
|
|
|
|||
Loading…
Reference in a new issue