From df80c43a57a51d87ae31f782a60ebc9432db99db Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 26 Oct 2026 21:24:40 +0100 Subject: [PATCH] Offer conversation deletion in the desktop PM context menu --- tools/chatgui/src/channellist.cpp | 17 ++++++++++++++++- tools/chatgui/src/channellist.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/chatgui/src/channellist.cpp b/tools/chatgui/src/channellist.cpp index a3b2d078..1f319cf9 100644 --- a/tools/chatgui/src/channellist.cpp +++ b/tools/chatgui/src/channellist.cpp @@ -224,8 +224,17 @@ ChannelList::ChannelList(DbManager* db, QWidget *parent) connect(m_listView, &QWidget::customContextMenuRequested, this, [this](const QPoint& point) { auto index = m_listView->indexAt(point); QString channel = index.data(ChannelChannelIdRole).toString(); - if (!index.isValid() || channel.isEmpty() || channel.startsWith(QStringLiteral("dm:"))) return; + if (!index.isValid() || channel.isEmpty()) return; QMenu menu(this); + if (channel.startsWith(QStringLiteral("dm:"))) { + const QString conv = channel.mid(3), name = index.data(ChannelNameRole).toString(); + const quint64 generation = index.data(ChannelDmGenerationRole).toULongLong(); + auto* remove = menu.addAction(QCoreApplication::translate("ChatGui", "Delete conversation")); + remove->setObjectName(QStringLiteral("deleteDmAction")); + remove->setEnabled(generation && m_dmDeleting.value(conv) != generation); + if (menu.exec(m_listView->viewport()->mapToGlobal(point)) == remove) emit dmDeleteRequested(conv, generation, name); + return; + } auto* files = menu.addAction(QCoreApplication::translate("ChatGui", "Group files")); if (menu.exec(m_listView->viewport()->mapToGlobal(point)) == files) emit filesRequested(channel); }); @@ -271,6 +280,11 @@ bool ChannelList::eventFilter(QObject* target, QEvent* event) { return true; } +void ChannelList::setDmDeleting(const QString& convId, quint64 generation, bool deleting) { + if (deleting) m_dmDeleting.insert(convId, generation); + else if (m_dmDeleting.value(convId) == generation) m_dmDeleting.remove(convId); +} + void ChannelList::refreshDmPresence() { if (!m_dmPresenceTimer->isActive()) m_dmPresenceTimer->start(); } @@ -367,6 +381,7 @@ void ChannelList::loadChannels() { auto *item = new QStandardItem(); item->setData(name, ChannelNameRole); item->setData(QStringLiteral("dm:") + dm.convId, ChannelChannelIdRole); + item->setData(QVariant::fromValue(dm.generation), ChannelDmGenerationRole); item->setData(m_dmOnline.value(dm.convId), ChannelDmOnlineRole); item->setData(QString(), ChannelLastMessageRole); item->setData(0, ChannelUnreadCountRole); diff --git a/tools/chatgui/src/channellist.h b/tools/chatgui/src/channellist.h index 272c70cf..5c5c069e 100644 --- a/tools/chatgui/src/channellist.h +++ b/tools/chatgui/src/channellist.h @@ -23,6 +23,8 @@ public: void refreshDmPresence(); void onDmCallRoute(const uint8_t* data, int len); void clearDmPresence(); + /* Отмечает ожидающее удаление поколения PM; повторное действие в меню недоступно до результата. */ + void setDmDeleting(const QString& convId, quint64 generation, bool deleting); void selectChannel(const QString& channelId); void setChannelPeersOnline(const QString& channelId, int count); void setAutoConnectActive(bool active); @@ -32,6 +34,7 @@ public: signals: void channelSelected(const QString& channelId); + void dmDeleteRequested(const QString& convId, quint64 generation, const QString& name); void filesRequested(const QString& channelId); void ownFilesDropped(const QString& channelId, const QStringList& paths); void joinRequested(); @@ -50,6 +53,7 @@ private: QLabel *m_dropHint; bool m_autoConnectActive = false; QHash m_dmOnline; + QHash m_dmDeleting; /* conv_id → поколение ожидающего удаления */ QTimer* m_dmPresenceTimer; CpuLoadIndicator* m_cpuLoad; };