chatgui: propagate local nick changes to message authors via MsgAuthorNodeIdRole + reloadLocalNicks
This commit is contained in:
1 parent
d6103d358e
commit
ccf0fa15ff
6 files changed
+36
-3
No files matched your search
@@ -203,7 +203,10 @@ void AccountList::onMemberDoubleClicked(const QModelIndex& index) {
|
||||
if (!nodeId) return;
|
||||
QString name = m_model->data(index, Qt::DisplayRole).toString();
|
||||
MemberPropsDialog dlg(m_db, m_channelId, nodeId, name, this);
|
||||
dlg.exec();
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
m_model->refresh();
|
||||
emit memberRenamed();
|
||||
}
|
||||
}
|
||||
|
||||
void AccountList::onMemberContextMenu(const QPoint& pos) {
|
||||
@@ -223,11 +226,17 @@ void AccountList::onMemberContextMenu(const QPoint& pos) {
|
||||
|
||||
if (chosen == renameAction) {
|
||||
RenameDialog dlg(m_db, m_channelId, nodeId, name, this);
|
||||
if (dlg.exec() == QDialog::Accepted) m_model->refresh();
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
m_model->refresh();
|
||||
emit memberRenamed();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (chosen != editAction) return;
|
||||
|
||||
MemberPropsDialog dlg(m_db, m_channelId, nodeId, name, this);
|
||||
dlg.exec();
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
m_model->refresh();
|
||||
emit memberRenamed();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,9 @@ public:
|
||||
void setChannel(const QString& channelId);
|
||||
void refresh();
|
||||
|
||||
signals:
|
||||
void memberRenamed();
|
||||
|
||||
private slots:
|
||||
void onMemberClicked(const QModelIndex& index);
|
||||
void onMemberDoubleClicked(const QModelIndex& index);
|
||||
|
||||
@@ -233,6 +233,8 @@ void MainWindow::setupConnects() {
|
||||
connect(m_channelList, &ChannelList::joinRequested, this, &MainWindow::showJoinDialog);
|
||||
connect(m_channelList, &ChannelList::createGroupRequested, this, &MainWindow::onCreateGroupRequested);
|
||||
connect(m_channelList, &ChannelList::settingsRequested, this, &MainWindow::showSettings);
|
||||
connect(m_accountList, &AccountList::memberRenamed,
|
||||
m_messageList, &MessageList::reloadLocalNicks);
|
||||
connect(m_messageList, &MessageList::readPositionChanged,
|
||||
this, [this](const QString& channelId, qint64 lastReadMsgId) {
|
||||
Q_UNUSED(lastReadMsgId);
|
||||
|
||||
@@ -14,6 +14,7 @@ enum MessageDataRole {
|
||||
MsgReactionsRole = Qt::UserRole + 9,
|
||||
MsgIdRole = Qt::UserRole + 10,
|
||||
MsgIsOutgoingRole = Qt::UserRole + 11,
|
||||
MsgAuthorNodeIdRole = Qt::UserRole + 20,
|
||||
};
|
||||
|
||||
class MessageDelegate : public QStyledItemDelegate {
|
||||
|
||||
@@ -229,6 +229,7 @@ void MessageList::loadChannel(const QString& channelId) {
|
||||
setMsg(item, author, QString::fromUtf8(m.data), time, avatar, false,
|
||||
false, QString(), QString(), reacts);
|
||||
item->setData(m.id, MsgIdRole);
|
||||
item->setData(QVariant::fromValue(m.authorNodeId), MsgAuthorNodeIdRole);
|
||||
item->setData(m.isOutgoing ? 1 : 0, MsgIsOutgoingRole);
|
||||
m_model->appendRow(item);
|
||||
}
|
||||
@@ -291,6 +292,7 @@ void MessageList::refresh() {
|
||||
setMsg(item, author, QString::fromUtf8(m.data), time, avatar, false,
|
||||
false, QString(), QString(), QVariantList{});
|
||||
item->setData(m.id, MsgIdRole);
|
||||
item->setData(QVariant::fromValue(m.authorNodeId), MsgAuthorNodeIdRole);
|
||||
item->setData(m.isOutgoing ? 1 : 0, MsgIsOutgoingRole);
|
||||
m_model->appendRow(item);
|
||||
while (m_model->rowCount() > 100)
|
||||
@@ -323,6 +325,7 @@ void MessageList::addMessage(const QString& channelId, quint64 authorNodeId,
|
||||
setMsg(item, author, QString::fromUtf8(content), time, avatar, false,
|
||||
false, QString(), QString(), QVariantList{});
|
||||
bool isSelf = m_db && (authorNodeId == m_db->myNodeId());
|
||||
item->setData(QVariant::fromValue(authorNodeId), MsgAuthorNodeIdRole);
|
||||
item->setData(isSelf ? 1 : 0, MsgIsOutgoingRole);
|
||||
m_model->appendRow(item);
|
||||
|
||||
@@ -366,6 +369,20 @@ QString MessageList::authorName(quint64 nodeId) const {
|
||||
return m_db->getDisplayName(nodeId);
|
||||
}
|
||||
|
||||
void MessageList::reloadLocalNicks() {
|
||||
if (m_currentChannelId.isEmpty() || !m_db) return;
|
||||
m_localNicks = m_db->getLocalNicknames(m_currentChannelId);
|
||||
for (int r = 0; r < m_model->rowCount(); r++) {
|
||||
auto* item = m_model->item(r);
|
||||
if (!item) continue;
|
||||
QVariant v = item->data(MsgAuthorNodeIdRole);
|
||||
if (!v.isValid()) continue;
|
||||
quint64 nid = v.value<quint64>();
|
||||
item->setData(authorName(nid), MsgAuthorRole);
|
||||
}
|
||||
m_view->viewport()->update();
|
||||
}
|
||||
|
||||
void MessageList::restoreScrollPosition(const QString& channelId) {
|
||||
if (!m_db || m_model->rowCount() == 0) {
|
||||
return;
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
|
||||
void loadChannel(const QString& channelId);
|
||||
void refresh();
|
||||
void reloadLocalNicks();
|
||||
void saveChannelState();
|
||||
static void cleanupAnimations();
|
||||
void addMessage(const QString& channelId, quint64 authorNodeId,
|
||||
|
||||
Reference in new issue
Block a user