diff --git a/tools/chatgui/src/accountlist.cpp b/tools/chatgui/src/accountlist.cpp index 9af53667..48158239 100644 --- a/tools/chatgui/src/accountlist.cpp +++ b/tools/chatgui/src/accountlist.cpp @@ -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(); + } } diff --git a/tools/chatgui/src/accountlist.h b/tools/chatgui/src/accountlist.h index 26eb56ca..422ba9c0 100644 --- a/tools/chatgui/src/accountlist.h +++ b/tools/chatgui/src/accountlist.h @@ -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); diff --git a/tools/chatgui/src/mainwindow.cpp b/tools/chatgui/src/mainwindow.cpp index f6f81695..ebc3fdb1 100644 --- a/tools/chatgui/src/mainwindow.cpp +++ b/tools/chatgui/src/mainwindow.cpp @@ -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); diff --git a/tools/chatgui/src/messagedelegate.h b/tools/chatgui/src/messagedelegate.h index f77dd073..719348fd 100644 --- a/tools/chatgui/src/messagedelegate.h +++ b/tools/chatgui/src/messagedelegate.h @@ -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 { diff --git a/tools/chatgui/src/messagelist.cpp b/tools/chatgui/src/messagelist.cpp index 30e4010d..44d38225 100644 --- a/tools/chatgui/src/messagelist.cpp +++ b/tools/chatgui/src/messagelist.cpp @@ -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(); + item->setData(authorName(nid), MsgAuthorRole); + } + m_view->viewport()->update(); +} + void MessageList::restoreScrollPosition(const QString& channelId) { if (!m_db || m_model->rowCount() == 0) { return; diff --git a/tools/chatgui/src/messagelist.h b/tools/chatgui/src/messagelist.h index 711eec8c..619ea0c7 100644 --- a/tools/chatgui/src/messagelist.h +++ b/tools/chatgui/src/messagelist.h @@ -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,