Display group avatars and restrict editing to group key holders

This commit is contained in:
evgeny committed 2026-10-06 13:44:49 +02:00
1 parent 8e3ff6fd81
commit 4062ecdfb1
3 files changed
+53

No files matched your search

@@ -1,5 +1,6 @@
#include <QCoreApplication>
#include "channelsettingsdialog.h"
#include "avatars/groupavatarmanager.h"
#include "../db/db_manager.h"
#include "../transport/gui_bridge.h"
#include "../../lib/mem.h"
@@ -10,6 +11,7 @@ extern "C" {
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QFileDialog>
#include <cstring>
ChannelSettingsDialog::ChannelSettingsDialog(const QString& channelId, DbManager* db, QWidget* parent)
@@ -34,6 +36,36 @@ ChannelSettingsDialog::ChannelSettingsDialog(const QString& channelId, DbManager
chIdLabel->setWordWrap(true);
layout->addWidget(chIdLabel);
if (auto* avatars = GroupAvatarManager::instance()) {
auto* preview = new QLabel(this); preview->setFixedSize(64, 64); layout->addWidget(preview);
auto* buttons = new QHBoxLayout;
auto* upload = new QPushButton(QCoreApplication::translate("ChatGui", "Upload group avatar"), this);
auto* remove = new QPushButton(QCoreApplication::translate("ChatGui", "Remove group avatar"), this);
upload->setObjectName("uploadGroupAvatar"); remove->setObjectName("removeGroupAvatar");
bool hasKey = false;
if (db && db->isOpen()) for (const auto& row : db->getChannels())
if (row.channelId == channelId) hasKey = row.ed25519_privkey.size() == 32;
upload->setEnabled(hasKey); remove->setEnabled(hasKey);
auto* info = new QLabel(QCoreApplication::translate("ChatGui", "Group avatar: up to 16 KiB. Changes apply immediately and require the group key."), this);
info->setWordWrap(true); auto* result = new QLabel(this); result->setWordWrap(true);
buttons->addWidget(upload); buttons->addWidget(remove); layout->addLayout(buttons); layout->addWidget(info); layout->addWidget(result);
auto refresh = [avatars, preview, channelId] {
const QImage image = avatars->image(channelId);
if (image.isNull()) { preview->setPixmap(QPixmap()); preview->setText(QCoreApplication::translate("ChatGui", "No avatar")); }
else preview->setPixmap(QPixmap::fromImage(image).scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
};
connect(avatars, &GroupAvatarManager::changed, this, [channelId, refresh](const QString& channel) { if (channel == channelId) refresh(); });
connect(avatars, &GroupAvatarManager::status, this, [channelId, result, refresh](const QString& channel, const QString& message) {
if (channel == channelId) { result->setText(message); refresh(); }
});
connect(upload, &QPushButton::clicked, this, [this, avatars, channelId] {
const QString file = QFileDialog::getOpenFileName(this, QCoreApplication::translate("ChatGui", "Choose avatar"), {},
QCoreApplication::translate("ChatGui", "Images (*.png *.jpg *.jpeg *.webp)"));
if (!file.isEmpty()) avatars->upload(channelId, file);
});
connect(remove, &QPushButton::clicked, this, [avatars, channelId] { avatars->remove(channelId); }); refresh();
}
layout->addSpacing(8);
m_autoPlayVoice = new QCheckBox(QCoreApplication::translate("ChatGui", "Auto-play voice messages on receive"), this);