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