chatgui: invite link dialogs, zxing-cpp QR code, crypto transport, channel improvements; msg_transport: chat protocol support

This commit is contained in:
Evgeny committed 2026-06-25 09:29:44 +03:00
1 parent d8c8c1c5b0
commit 22c24d135e
2206 files changed
+33191 -257

No files matched your search

+61 -6
View File
@@ -2,32 +2,66 @@
#include "channellist.h"
#include "messagelist.h"
#include "accountlist.h"
#include "invitedialog.h"
#include "invite_link.h"
#include "../db/db_manager.h"
#include "../transport/msg_client.h"
#include "../transport/chat_propagator.h"
#include "../transport/crypto.h"
#include <QSplitter>
#include <QCloseEvent>
#include <QApplication>
#include <QStyle>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
MainWindow::MainWindow(QWidget *parent, DbManager* db)
: QMainWindow(parent)
, m_channelList(nullptr)
, m_messageList(nullptr)
, m_accountList(nullptr)
, m_trayIcon(nullptr)
, m_trayMenu(nullptr)
, m_db(db)
, m_client(nullptr)
, m_propagator(nullptr)
{
setWindowTitle("Chat");
resize(900, 600);
setupUi();
setupTray();
if (m_db && m_db->isOpen()) {
m_client = new MsgClient(this);
m_propagator = new ChatPropagator(m_client, m_db, this);
m_messageList->setPropagator(m_propagator);
connect(m_propagator, &ChatPropagator::messageReceived,
m_messageList, &MessageList::addMessage);
connect(m_channelList, &ChannelList::channelSelected,
this, [this](const QString& channelId) {
m_db->setUiState("last_channel_id", channelId);
m_messageList->loadChannel(channelId);
});
connect(m_channelList, &ChannelList::inviteRequested,
this, &MainWindow::showInviteDialog);
m_channelList->loadChannels();
m_accountList->loadAccounts();
QString lastCid = m_db->getUiState("last_channel_id");
if (!lastCid.isEmpty())
m_channelList->selectChannel(lastCid);
}
}
void MainWindow::setupUi() {
auto *splitter = new QSplitter(Qt::Horizontal, this);
m_channelList = new ChannelList(splitter);
m_messageList = new MessageList(splitter);
m_accountList = new AccountList(splitter);
m_channelList = new ChannelList(m_db, splitter);
m_messageList = new MessageList(m_db, splitter);
m_accountList = new AccountList(m_db, splitter);
splitter->addWidget(m_channelList);
splitter->addWidget(m_messageList);
@@ -69,7 +103,7 @@ void MainWindow::setupTray() {
void MainWindow::closeEvent(QCloseEvent *event) {
hide();
m_trayIcon->showMessage("Chat", "Application minimized to tray.",
QSystemTrayIcon::Information, 2000);
QSystemTrayIcon::Information, 2000);
event->ignore();
}
@@ -81,3 +115,24 @@ void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) {
activateWindow();
}
}
void MainWindow::showInviteDialog(const QString& channelId) {
if (!m_db || !m_db->isOpen()) return;
QByteArray pubkey = m_db->getLocalPubkey();
if (pubkey.size() != 32) {
QMessageBox::warning(this, "Ошибка", "Не удалось получить публичный ключ узла.");
return;
}
QList<NodeAddr> addrs = m_db->getOnlinePeerAddresses(m_db->myNodeId());
QString link = encodeInviteLink(channelId, pubkey, addrs);
if (link.isEmpty()) {
QMessageBox::warning(this, "Ошибка", "Не удалось сформировать пригласительную ссылку.");
return;
}
InviteDialog dlg(link, this);
dlg.exec();
}