Реакции, но с багом

This commit is contained in:
Халимов Рустам
2026-04-18 00:41:05 +03:00
parent b68f68a1f2
commit 629fddfca0
18 changed files with 471 additions and 26 deletions
@@ -15,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.layout.onGloballyPositioned
@@ -57,8 +58,13 @@ fun MessageBubble(
autoPlay: Boolean = false,
initialPlaybackSpeed: Float = 1.0f,
onVoiceFinished: (Float) -> Unit = {},
onReply: (Message) -> Unit = {},
onReplyClick: (Message) -> Unit = {},
onSelect: (String) -> Unit = {},
onForward: (Message) -> Unit = {},
onPin: (Message) -> Unit = {},
onEdit: (Message) -> Unit = {},
onDelete: (Message, Boolean) -> Unit = { _, _ -> },
isSelected: Boolean = false,
isSelectionMode: Boolean = false,
onMediaClick: (chats.domain.model.Media) -> Unit = {}
@@ -69,6 +75,7 @@ fun MessageBubble(
val contentColor = Color.White
var showContextMenu by remember { mutableStateOf(false) }
var showDeleteDialog by remember { mutableStateOf(false) }
val backgroundColor = when {
isSelected -> if (isCurrentUser) Color(0xFF3096E5).copy(alpha = 0.5f) else Color(0xFF212121).copy(alpha = 0.5f)
@@ -156,6 +163,8 @@ fun MessageBubble(
)
) {
MessageContextMenu(
isMyMessage = isCurrentUser,
isPinned = message.isPinned,
onReactionSelected = {
onReactionClick(it)
showContextMenu = false
@@ -163,19 +172,36 @@ fun MessageBubble(
onAction = { action ->
showContextMenu = false
when(action) {
"reply" -> onReplyClick(message)
"reply" -> onReply(message)
"select" -> onSelect(message.id)
"forward" -> onForward(message)
"pin" -> onPin(message)
"edit" -> onEdit(message)
"copy" -> {
val clipboard = context.getSystemService(android.content.Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
val clip = android.content.ClipData.newPlainText("message", message.content)
clipboard.setPrimaryClip(clip)
}
"delete" -> {
showDeleteDialog = true
}
}
}
)
}
}
// Forwarded Info
if (message.isForwarded) {
Text(
text = "Forwarded from ${message.forwardedFromName ?: "Unknown"}",
style = MaterialTheme.typography.labelSmall,
color = contentColor.copy(alpha = 0.7f),
fontStyle = androidx.compose.ui.text.font.FontStyle.Italic,
modifier = Modifier.padding(bottom = 4.dp)
)
}
// Reply Info
message.replyTo?.let { reply ->
Row(
@@ -447,6 +473,14 @@ fun MessageBubble(
color = contentColor.copy(alpha = 0.6f),
fontSize = 11.sp
)
if (message.isPinned) {
Icon(
imageVector = Icons.Default.PushPin,
contentDescription = "Pinned",
modifier = Modifier.size(12.dp).padding(start = 2.dp).graphicsLayer { rotationZ = 45f },
tint = contentColor.copy(alpha = 0.6f)
)
}
if (isCurrentUser) {
Spacer(modifier = Modifier.width(2.dp))
Icon(
@@ -481,6 +515,48 @@ fun MessageBubble(
onClose = { lightboxMediaIndex = null }
)
}
if (showDeleteDialog) {
var deleteForEveryone by remember { mutableStateOf(false) }
AlertDialog(
onDismissRequest = { showDeleteDialog = false },
title = { Text("Удалить сообщение?") },
text = {
Column {
Text("Вы уверены, что хотите удалить это сообщение?")
if (isCurrentUser) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(top = 8.dp).clickable { deleteForEveryone = !deleteForEveryone }
) {
Checkbox(
checked = deleteForEveryone,
onCheckedChange = { deleteForEveryone = it }
)
Text("Удалить у всех")
}
}
}
},
confirmButton = {
TextButton(
onClick = {
onDelete(message, deleteForEveryone)
showDeleteDialog = false
},
colors = ButtonDefaults.textButtonColors(contentColor = Color(0xFFE53935))
) {
Text("Удалить")
}
},
dismissButton = {
TextButton(onClick = { showDeleteDialog = false }) {
Text("Отмена")
}
}
)
}
}
@Composable
@@ -645,6 +721,8 @@ fun GridItem(media: Media, modifier: Modifier = Modifier) {
@Composable
fun MessageContextMenu(
isMyMessage: Boolean,
isPinned: Boolean,
onReactionSelected: (String) -> Unit,
onAction: (String) -> Unit
) {
@@ -712,9 +790,15 @@ fun MessageContextMenu(
ContextMenuItem(Icons.Default.Reply, "Ответить", onClick = { onAction("reply") })
ContextMenuItem(Icons.Default.CheckCircle, "Выбрать", onClick = { onAction("select") })
ContextMenuItem(Icons.Default.Forward, "Переслать", onClick = { onAction("forward") })
ContextMenuItem(Icons.Default.PushPin, "Закрепить", onClick = { onAction("pin") })
ContextMenuItem(
icon = Icons.Default.PushPin,
text = if (isPinned) "Открепить" else "Закрепить",
onClick = { onAction("pin") }
)
ContextMenuItem(Icons.Default.ContentCopy, "Копировать", onClick = { onAction("copy") })
ContextMenuItem(Icons.Default.Edit, "Редактировать", onClick = { onAction("edit") })
if (isMyMessage) {
ContextMenuItem(Icons.Default.Edit, "Редактировать", onClick = { onAction("edit") })
}
Divider(color = Color.White.copy(alpha = 0.1f))