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

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

View File

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

View File

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

View File

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