chatgui: выпилить все записи в БД из GUI потока (DbManager)
- DbManager теперь read-only, получает sqlite3* handle через setDb() - chat_core — единственный владелец БД (SQLITE_OPEN_FULLMUTEX + WAL) - initTables/seedStubData/createChannel/insertMessage/setUiState удалены из DbManager - seed 5 stub-аккаунтов перенесён в chat_core_init() - GUI_EVT_DB_READY — уведомление о готовности БД - setUiState заменён на QSettings - каналы загружаются по DB_READY коллбэку - убран двойной sqlite3_open (один файл, один хендл)
This commit is contained in:
1 parent
409a99f56b
commit
371208d489
9 files changed
+82
-359
No files matched your search
@@ -16,6 +16,7 @@
|
||||
#include <QStyle>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
|
||||
extern "C" {
|
||||
#include "../transport/chat_core.h"
|
||||
@@ -78,7 +79,7 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
||||
setupUi();
|
||||
setupTray();
|
||||
|
||||
if (m_db && m_db->isOpen()) {
|
||||
if (m_db) {
|
||||
s_mainWindow = this;
|
||||
gui_bridge_set_msg_received_cb(onMsgReceivedCallback);
|
||||
gui_bridge_set_channel_updated_cb(onChannelUpdatedCallback);
|
||||
@@ -89,13 +90,25 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
||||
});
|
||||
gui_bridge_set_auto_connect_status_cb(onAutoConnectStatusCallback);
|
||||
gui_bridge_set_channel_peers_online_cb(onChannelPeersOnlineCallback);
|
||||
gui_bridge_set_db_ready_cb([]() {
|
||||
if (!s_mainWindow || !s_mainWindow->m_db) return;
|
||||
s_mainWindow->m_db->setDb(chat_core_get_db());
|
||||
s_mainWindow->m_channelList->loadChannels();
|
||||
|
||||
QString lastCid = QSettings().value("last_channel_id").toString();
|
||||
if (!lastCid.isEmpty()) {
|
||||
s_mainWindow->m_channelList->selectChannel(lastCid);
|
||||
s_mainWindow->m_accountList->setChannel(lastCid);
|
||||
}
|
||||
});
|
||||
|
||||
setupNode();
|
||||
setupMessaging();
|
||||
|
||||
connect(m_channelList, &ChannelList::channelSelected,
|
||||
this, [this](const QString& channelId) {
|
||||
m_db->setUiState("last_channel_id", channelId);
|
||||
QSettings().setValue("last_channel_id", channelId);
|
||||
m_currentChannelId = channelId;
|
||||
m_messageList->loadChannel(channelId);
|
||||
m_accountList->setChannel(channelId);
|
||||
});
|
||||
@@ -108,14 +121,6 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
||||
this, &MainWindow::onCreateGroupRequested);
|
||||
connect(m_channelList, &ChannelList::settingsRequested,
|
||||
this, &MainWindow::showSettings);
|
||||
|
||||
m_channelList->loadChannels();
|
||||
|
||||
QString lastCid = m_db->getUiState("last_channel_id");
|
||||
if (!lastCid.isEmpty()) {
|
||||
m_channelList->selectChannel(lastCid);
|
||||
m_accountList->setChannel(lastCid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +271,7 @@ void MainWindow::onMessageReceived(const char* ch_id) {
|
||||
}
|
||||
|
||||
void MainWindow::onMembersChanged(const char* ch_id) {
|
||||
QString cur = m_db->getUiState("last_channel_id");
|
||||
QString cur = QSettings().value("last_channel_id").toString();
|
||||
if (cur == QString::fromUtf8(ch_id))
|
||||
m_accountList->refresh();
|
||||
}
|
||||
@@ -292,7 +297,8 @@ void MainWindow::reloadChannels() {
|
||||
m_channelList->selectChannel(m_pendingChannelSelect);
|
||||
m_accountList->setChannel(m_pendingChannelSelect);
|
||||
m_messageList->loadChannel(m_pendingChannelSelect);
|
||||
m_db->setUiState("last_channel_id", m_pendingChannelSelect);
|
||||
QSettings().setValue("last_channel_id", m_pendingChannelSelect);
|
||||
m_currentChannelId = m_pendingChannelSelect;
|
||||
m_pendingChannelSelect.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user