Добавлено сохранение аватаров для групповых сообщений, улучшена логика обработки ключей диалога в компонентах сообщений.

This commit is contained in:
2026-03-07 18:08:30 +05:00
parent c5737e51b0
commit c674a1ea99
4 changed files with 28 additions and 10 deletions

View File

@@ -764,10 +764,13 @@ class MessageRepository private constructor(private val context: Context) {
groupKey groupKey
) )
// 📸 Обрабатываем AVATAR attachments - сохраняем аватар отправителя // 📸 Обрабатываем AVATAR attachments:
// в личке — сохраняем аватар отправителя, в группе — аватар группы (desktop parity)
val avatarOwnerKey =
if (isGroupMessage) packet.toPublicKey else packet.fromPublicKey
processAvatarAttachments( processAvatarAttachments(
packet.attachments, packet.attachments,
packet.fromPublicKey, avatarOwnerKey,
packet.chachaKey, packet.chachaKey,
privateKey, privateKey,
plainKeyAndNonce, plainKeyAndNonce,
@@ -1510,7 +1513,7 @@ class MessageRepository private constructor(private val context: Context) {
*/ */
private suspend fun processAvatarAttachments( private suspend fun processAvatarAttachments(
attachments: List<MessageAttachment>, attachments: List<MessageAttachment>,
fromPublicKey: String, avatarOwnerKey: String,
encryptedKey: String, encryptedKey: String,
privateKey: String, privateKey: String,
plainKeyAndNonce: ByteArray? = null, plainKeyAndNonce: ByteArray? = null,
@@ -1540,18 +1543,18 @@ class MessageRepository private constructor(private val context: Context) {
if (decryptedBlob != null) { if (decryptedBlob != null) {
// 2. Сохраняем аватар в кэш // 2. Сохраняем аватар в кэш
val filePath = val filePath =
AvatarFileManager.saveAvatar(context, decryptedBlob, fromPublicKey) AvatarFileManager.saveAvatar(context, decryptedBlob, avatarOwnerKey)
val entity = val entity =
AvatarCacheEntity( AvatarCacheEntity(
publicKey = fromPublicKey, publicKey = avatarOwnerKey,
avatar = filePath, avatar = filePath,
timestamp = System.currentTimeMillis() timestamp = System.currentTimeMillis()
) )
avatarDao.insertAvatar(entity) avatarDao.insertAvatar(entity)
// 3. Очищаем старые аватары (оставляем последние 5) // 3. Очищаем старые аватары (оставляем последние 5)
avatarDao.deleteOldAvatars(fromPublicKey, 5) avatarDao.deleteOldAvatars(avatarOwnerKey, 5)
} else {} } else {}
} catch (e: Exception) {} } catch (e: Exception) {}
} }

View File

@@ -2170,6 +2170,8 @@ fun ChatDetailScreen(
message.senderName, message.senderName,
isGroupChat = isGroupChat =
isGroupChat, isGroupChat,
dialogPublicKey =
user.publicKey,
showGroupSenderLabel = showGroupSenderLabel =
isGroupChat && isGroupChat &&
!message.isOutgoing, !message.isOutgoing,

View File

@@ -332,6 +332,8 @@ fun MessageAttachments(
isOutgoing: Boolean, isOutgoing: Boolean,
isDarkTheme: Boolean, isDarkTheme: Boolean,
senderPublicKey: String, senderPublicKey: String,
dialogPublicKey: String = "",
isGroupChat: Boolean = false,
timestamp: java.util.Date, timestamp: java.util.Date,
messageStatus: MessageStatus = MessageStatus.READ, messageStatus: MessageStatus = MessageStatus.READ,
avatarRepository: AvatarRepository? = null, avatarRepository: AvatarRepository? = null,
@@ -392,6 +394,8 @@ fun MessageAttachments(
chachaKey = chachaKey, chachaKey = chachaKey,
privateKey = privateKey, privateKey = privateKey,
senderPublicKey = senderPublicKey, senderPublicKey = senderPublicKey,
dialogPublicKey = dialogPublicKey,
isGroupChat = isGroupChat,
avatarRepository = avatarRepository, avatarRepository = avatarRepository,
currentUserPublicKey = currentUserPublicKey, currentUserPublicKey = currentUserPublicKey,
isOutgoing = isOutgoing, isOutgoing = isOutgoing,
@@ -1775,6 +1779,8 @@ fun AvatarAttachment(
chachaKey: String, chachaKey: String,
privateKey: String, privateKey: String,
senderPublicKey: String, senderPublicKey: String,
dialogPublicKey: String = "",
isGroupChat: Boolean = false,
avatarRepository: AvatarRepository?, avatarRepository: AvatarRepository?,
currentUserPublicKey: String = "", currentUserPublicKey: String = "",
isOutgoing: Boolean, isOutgoing: Boolean,
@@ -1924,11 +1930,15 @@ fun AvatarAttachment(
// Сохраняем аватар в репозиторий (для UI обновления) // Сохраняем аватар в репозиторий (для UI обновления)
// Если это исходящее сообщение с аватаром, сохраняем для текущего // Если это исходящее сообщение с аватаром, сохраняем для текущего
// пользователя // пользователя
val normalizedDialogKey = dialogPublicKey.trim()
val isGroupAvatarAttachment = isGroupChat || isGroupStoredKey(chachaKey)
val targetPublicKey = val targetPublicKey =
if (isOutgoing && currentUserPublicKey.isNotEmpty()) { when {
currentUserPublicKey isGroupAvatarAttachment && normalizedDialogKey.isNotEmpty() ->
} else { normalizedDialogKey
senderPublicKey isOutgoing && currentUserPublicKey.isNotEmpty() ->
currentUserPublicKey
else -> senderPublicKey
} }
// ВАЖНО: ждем завершения сохранения в репозиторий // ВАЖНО: ждем завершения сохранения в репозиторий

View File

@@ -297,6 +297,7 @@ fun MessageBubble(
senderPublicKey: String = "", senderPublicKey: String = "",
senderName: String = "", senderName: String = "",
isGroupChat: Boolean = false, isGroupChat: Boolean = false,
dialogPublicKey: String = "",
showGroupSenderLabel: Boolean = false, showGroupSenderLabel: Boolean = false,
isGroupSenderAdmin: Boolean = false, isGroupSenderAdmin: Boolean = false,
currentUserPublicKey: String = "", currentUserPublicKey: String = "",
@@ -846,6 +847,8 @@ fun MessageBubble(
isOutgoing = message.isOutgoing, isOutgoing = message.isOutgoing,
isDarkTheme = isDarkTheme, isDarkTheme = isDarkTheme,
senderPublicKey = senderPublicKey, senderPublicKey = senderPublicKey,
dialogPublicKey = dialogPublicKey,
isGroupChat = isGroupChat,
timestamp = message.timestamp, timestamp = message.timestamp,
messageStatus = attachmentDisplayStatus, messageStatus = attachmentDisplayStatus,
avatarRepository = avatarRepository, avatarRepository = avatarRepository,