|
|
|
@ -21,7 +21,6 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
setMinimumWidth(340); |
|
|
|
setMinimumWidth(340); |
|
|
|
setModal(true); |
|
|
|
setModal(true); |
|
|
|
|
|
|
|
|
|
|
|
// читаем ed25519_privkey канала
|
|
|
|
|
|
|
|
auto chs = m_db->getChannels(); |
|
|
|
auto chs = m_db->getChannels(); |
|
|
|
for (const auto& ch : chs) { |
|
|
|
for (const auto& ch : chs) { |
|
|
|
if (ch.channelId == channelId) { |
|
|
|
if (ch.channelId == channelId) { |
|
|
|
@ -30,13 +29,14 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
bool haveKey = (m_edPrivkey.size() == 32); |
|
|
|
bool haveKey = (m_edPrivkey.size() == 32); |
|
|
|
|
|
|
|
bool isOwn = (m_nodeId == m_db->myNodeId()); |
|
|
|
|
|
|
|
|
|
|
|
// читаем текущий adm_tags
|
|
|
|
|
|
|
|
bool isAdmin = false, isSuper = false; |
|
|
|
bool isAdmin = false, isSuper = false; |
|
|
|
|
|
|
|
QString curNick; |
|
|
|
if (m_db->m_db) { |
|
|
|
if (m_db->m_db) { |
|
|
|
QString tbl = m_db->peersTableName(channelId); |
|
|
|
QString tbl = m_db->peersTableName(channelId); |
|
|
|
QByteArray sql = QString( |
|
|
|
QByteArray sql = QString( |
|
|
|
"SELECT adm_tags FROM \"%1\" WHERE node_id=?" |
|
|
|
"SELECT adm_tags, local_nick FROM \"%1\" WHERE node_id=?" |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
sqlite3_stmt* st = nullptr; |
|
|
|
sqlite3_stmt* st = nullptr; |
|
|
|
if (sqlite3_prepare_v2(m_db->m_db, sql.constData(), -1, &st, nullptr) == SQLITE_OK) { |
|
|
|
if (sqlite3_prepare_v2(m_db->m_db, sql.constData(), -1, &st, nullptr) == SQLITE_OK) { |
|
|
|
@ -47,10 +47,10 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
if (strstr(tags, "admin=yes")) isAdmin = true; |
|
|
|
if (strstr(tags, "admin=yes")) isAdmin = true; |
|
|
|
if (strstr(tags, "supernode=yes")) isSuper = true; |
|
|
|
if (strstr(tags, "supernode=yes")) isSuper = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
curNick = DbManager::colText(st, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
sqlite3_finalize(st); |
|
|
|
sqlite3_finalize(st); |
|
|
|
} |
|
|
|
} |
|
|
|
// страховка: добавить колонки если нет
|
|
|
|
|
|
|
|
QByteArray alt = QString( |
|
|
|
QByteArray alt = QString( |
|
|
|
"ALTER TABLE \"%1\" ADD COLUMN adm_tags TEXT" |
|
|
|
"ALTER TABLE \"%1\" ADD COLUMN adm_tags TEXT" |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
@ -59,6 +59,10 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
"ALTER TABLE \"%1\" ADD COLUMN adm_tags_sig BLOB" |
|
|
|
"ALTER TABLE \"%1\" ADD COLUMN adm_tags_sig BLOB" |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
sqlite3_exec(m_db->m_db, alt.constData(), nullptr, nullptr, nullptr); |
|
|
|
sqlite3_exec(m_db->m_db, alt.constData(), nullptr, nullptr, nullptr); |
|
|
|
|
|
|
|
alt = QString( |
|
|
|
|
|
|
|
"ALTER TABLE \"%1\" ADD COLUMN local_nick TEXT" |
|
|
|
|
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
|
|
|
|
sqlite3_exec(m_db->m_db, alt.constData(), nullptr, nullptr, nullptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto* layout = new QVBoxLayout(this); |
|
|
|
auto* layout = new QVBoxLayout(this); |
|
|
|
@ -72,6 +76,12 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
title->setStyleSheet("font-weight: bold; font-size: 13px;"); |
|
|
|
title->setStyleSheet("font-weight: bold; font-size: 13px;"); |
|
|
|
layout->addWidget(title); |
|
|
|
layout->addWidget(title); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_nickEdit = new QLineEdit(this); |
|
|
|
|
|
|
|
m_nickEdit->setPlaceholderText("Local nickname..."); |
|
|
|
|
|
|
|
m_nickEdit->setText(curNick); |
|
|
|
|
|
|
|
m_nickEdit->setEnabled(!isOwn); |
|
|
|
|
|
|
|
layout->addWidget(m_nickEdit); |
|
|
|
|
|
|
|
|
|
|
|
m_adminCb = new QCheckBox("Admin", this); |
|
|
|
m_adminCb = new QCheckBox("Admin", this); |
|
|
|
m_adminCb->setChecked(isAdmin); |
|
|
|
m_adminCb->setChecked(isAdmin); |
|
|
|
m_adminCb->setEnabled(haveKey); |
|
|
|
m_adminCb->setEnabled(haveKey); |
|
|
|
@ -83,7 +93,7 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
layout->addWidget(m_superCb); |
|
|
|
layout->addWidget(m_superCb); |
|
|
|
|
|
|
|
|
|
|
|
if (!haveKey) { |
|
|
|
if (!haveKey) { |
|
|
|
auto* hint = new QLabel("(requires channel private key)", this); |
|
|
|
auto* hint = new QLabel("(Admin/Super require channel private key)", this); |
|
|
|
hint->setStyleSheet("color: gray; font-size: 11px;"); |
|
|
|
hint->setStyleSheet("color: gray; font-size: 11px;"); |
|
|
|
layout->addWidget(hint); |
|
|
|
layout->addWidget(hint); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -105,7 +115,6 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
auto* saveBtn = new QPushButton("Save", this); |
|
|
|
auto* saveBtn = new QPushButton("Save", this); |
|
|
|
saveBtn->setFixedWidth(90); |
|
|
|
saveBtn->setFixedWidth(90); |
|
|
|
saveBtn->setDefault(true); |
|
|
|
saveBtn->setDefault(true); |
|
|
|
saveBtn->setEnabled(haveKey); |
|
|
|
|
|
|
|
saveBtn->setStyleSheet( |
|
|
|
saveBtn->setStyleSheet( |
|
|
|
"QPushButton { border: none; border-radius: 4px;" |
|
|
|
"QPushButton { border: none; border-radius: 4px;" |
|
|
|
" padding: 6px 16px; font-size: 13px; font-weight: bold;" |
|
|
|
" padding: 6px 16px; font-size: 13px; font-weight: bold;" |
|
|
|
@ -119,9 +128,26 @@ MemberPropsDialog::MemberPropsDialog(DbManager* db, const QString& channelId, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MemberPropsDialog::onSave() { |
|
|
|
void MemberPropsDialog::onSave() { |
|
|
|
if (m_edPrivkey.size() != 32 || !m_db->m_db) return; |
|
|
|
if (!m_db->m_db) return; |
|
|
|
|
|
|
|
QString tbl = m_db->peersTableName(m_channelId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* local_nick — always save (unsigned, local only) */ |
|
|
|
|
|
|
|
QString nick = m_nickEdit->text().trimmed(); |
|
|
|
|
|
|
|
QByteArray nickSql = QString( |
|
|
|
|
|
|
|
"UPDATE \"%1\" SET local_nick=? WHERE node_id=?" |
|
|
|
|
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
|
|
|
|
sqlite3_stmt* ns = nullptr; |
|
|
|
|
|
|
|
if (sqlite3_prepare_v2(m_db->m_db, nickSql.constData(), -1, &ns, nullptr) == SQLITE_OK) { |
|
|
|
|
|
|
|
sqlite3_bind_text(ns, 1, nick.isEmpty() ? nullptr : nick.toUtf8().constData(), |
|
|
|
|
|
|
|
-1, nick.isEmpty() ? SQLITE_STATIC : SQLITE_TRANSIENT); |
|
|
|
|
|
|
|
sqlite3_bind_int64(ns, 2, (sqlite3_int64)m_nodeId); |
|
|
|
|
|
|
|
sqlite3_step(ns); |
|
|
|
|
|
|
|
sqlite3_finalize(ns); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* signed fields — only if key available */ |
|
|
|
|
|
|
|
if (m_edPrivkey.size() != 32) { accept(); return; } |
|
|
|
|
|
|
|
|
|
|
|
// собираем adm_tags
|
|
|
|
|
|
|
|
QString tags; |
|
|
|
QString tags; |
|
|
|
if (m_adminCb->isChecked()) tags += "admin=yes"; |
|
|
|
if (m_adminCb->isChecked()) tags += "admin=yes"; |
|
|
|
if (m_superCb->isChecked()) { |
|
|
|
if (m_superCb->isChecked()) { |
|
|
|
@ -129,7 +155,6 @@ void MemberPropsDialog::onSave() { |
|
|
|
tags += "supernode=yes"; |
|
|
|
tags += "supernode=yes"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// подписываем: tags || node_id(8 LE)
|
|
|
|
|
|
|
|
QByteArray msg = tags.toUtf8(); |
|
|
|
QByteArray msg = tags.toUtf8(); |
|
|
|
uint64_t le = htole64(m_nodeId); |
|
|
|
uint64_t le = htole64(m_nodeId); |
|
|
|
msg.append((const char*)&le, 8); |
|
|
|
msg.append((const char*)&le, 8); |
|
|
|
@ -148,8 +173,6 @@ void MemberPropsDialog::onSave() { |
|
|
|
EVP_PKEY_free(pkey); |
|
|
|
EVP_PKEY_free(pkey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// пишем в БД
|
|
|
|
|
|
|
|
QString tbl = m_db->peersTableName(m_channelId); |
|
|
|
|
|
|
|
QByteArray sql = QString( |
|
|
|
QByteArray sql = QString( |
|
|
|
"UPDATE \"%1\" SET adm_tags=?, adm_tags_sig=?, node_type=? WHERE node_id=?" |
|
|
|
"UPDATE \"%1\" SET adm_tags=?, adm_tags_sig=?, node_type=? WHERE node_id=?" |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
).arg(tbl).toUtf8(); |
|
|
|
|