chatgui: channel sorting by name or last message time with preview

- Add last_msg_at column to channels table
- Update last_msg_at on every message insert (send/receive)
- Parameterize getChannels() with ChannelSortMode enum (Alphabetical/Recent)
- Add getChannelLastMessage() for preview text in channel list
- Add sorting combo to Profile settings page (stored in ui_state)
- Reload channels on message receive when sort is recent
This commit is contained in:
Evgeny committed 2026-07-26 11:08:59 +03:00
1 parent 332df381d1
commit 49da899964
10 files changed
+105 -12

No files matched your search

+29
View File
@@ -18,6 +18,7 @@ extern "C" {
#include <QLabel>
#include <QFormLayout>
#include <QLineEdit>
#include <QComboBox>
#include <QFile>
#include <QTextStream>
@@ -69,6 +70,15 @@ SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, UtunNod
"QLineEdit { border: 1px solid palette(mid); border-radius: 4px;"
" padding: 6px 10px; font-size: 13px; background: palette(base); }");
profLayout->addRow(nameLabel, m_nicknameEdit);
auto* sortLabel = new QLabel("Channel sorting:", profilePage);
m_sortCombo = new QComboBox(profilePage);
m_sortCombo->addItem("Alphabetical (A-Z)");
m_sortCombo->addItem("Recent Activity");
m_sortCombo->setStyleSheet(
"QComboBox { border: 1px solid palette(mid); border-radius: 4px;"
" padding: 6px 10px; font-size: 13px; background: palette(base); }");
profLayout->addRow(sortLabel, m_sortCombo);
m_pages->addWidget(profilePage);
// Network page
@@ -124,6 +134,10 @@ SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, UtunNod
// Load current values
loadProfileFromConfig(m_configPath);
if (db) {
int sortMode = db->getUiStateInt("channel_sort", 0);
m_sortCombo->setCurrentIndex(sortMode == 1 ? 1 : 0);
}
m_networkPage->loadFromConfig(m_configPath);
m_soundPage->loadFromDb();
m_categoryList->setCurrentRow(0);
@@ -189,6 +203,21 @@ void SettingsDialog::onSave() {
f.close();
m_networkPage->saveToConfig(m_configPath);
/* save channel sort preference to ui_state */
{
const char* key = "channel_sort";
QByteArray val = QByteArray::number(m_sortCombo->currentIndex());
size_t klen = strlen(key), vlen = (size_t)val.size();
size_t total = klen + 1 + vlen + 1;
if (total <= 256) {
void* arg = u_malloc(total);
memcpy(arg, key, klen + 1);
memcpy((char*)arg + klen + 1, val.constData(), vlen + 1);
gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg);
}
}
m_soundPage->applyAndSave();
accept();
}