Fix MAX emoji attachments

This commit is contained in:
sevenhill
2026-07-04 15:56:39 +03:00
parent 438f7323d1
commit b3192d793d
6 changed files with 319 additions and 18 deletions
@@ -2233,6 +2233,7 @@ private fun replyPreviewBody(message: MessageDto): String {
message.text?.takeIf { it.isNotBlank() }?.let { return it }
val attachment = message.attachments.firstOrNull() ?: return "Message"
return when {
attachment.isEmojiAttachment() -> "Emoji"
attachment.isImageAttachment() -> "Photo"
attachment.isVideoAttachment() -> "Video"
attachment.isVoiceAttachment() -> "Voice message"
@@ -2389,6 +2390,13 @@ private fun AttachmentView(
val cachedImagePath = state.cachedImagePaths[attachment.id]
when {
attachment.isContactAttachment() -> ContactAttachment(attachment, vm)
attachment.isEmojiAttachment() -> EmojiAttachment(
attachment,
url,
session.accessToken,
cachedImagePath,
vm
)
attachment.isImageAttachment() -> ImageAttachment(
attachment,
url,
@@ -2403,6 +2411,27 @@ private fun AttachmentView(
}
}
@Composable
private fun EmojiAttachment(
attachment: AttachmentDto,
url: String,
token: String,
cachedImagePath: String?,
vm: QMaxViewModel
) {
LaunchedEffect(attachment.id, url) {
vm.cacheImage(attachment)
}
val model = cachedImagePath?.let(::File) ?: imageRequest(url, token)
val emojiSize = if (attachment.fileSizeBytes <= 2_048L) 22.dp else 44.dp
AsyncImage(
model = model,
contentDescription = attachment.fileName,
contentScale = ContentScale.Fit,
modifier = Modifier.size(emojiSize)
)
}
@Composable
private fun ImageAttachment(
attachment: AttachmentDto,
@@ -3294,12 +3323,21 @@ private fun imageRequest(url: String, token: String): ImageRequest {
}
private fun AttachmentDto.isImageAttachment(): Boolean {
if (isEmojiAttachment()) {
return false
}
return kind.equals("Image", true) ||
kind.equals("Gif", true) ||
contentType.startsWith("image/", ignoreCase = true) ||
extension() in setOf("jpg", "jpeg", "png", "webp", "gif", "bmp", "heic", "heif")
}
private fun AttachmentDto.isEmojiAttachment(): Boolean {
val normalizedFileName = fileName.lowercase(Locale.ROOT)
return normalizedFileName.startsWith("max-emoji-") ||
kind.equals("Emoji", true)
}
private fun AttachmentDto.isContactAttachment(): Boolean {
return kind.equals("Contact", true) ||
contentType.contains("vcard", ignoreCase = true) ||