Browse Source

chatgui: propagate local nick changes to message authors via MsgAuthorNodeIdRole + reloadLocalNicks

topo_upd
Evgeny 2 months ago
parent
commit
332df381d1
  1. 15
      tools/chatgui/src/accountlist.cpp
  2. 3
      tools/chatgui/src/accountlist.h
  3. 2
      tools/chatgui/src/mainwindow.cpp
  4. 1
      tools/chatgui/src/messagedelegate.h
  5. 17
      tools/chatgui/src/messagelist.cpp
  6. 1
      tools/chatgui/src/messagelist.h

15
tools/chatgui/src/accountlist.cpp

@ -203,7 +203,10 @@ void AccountList::onMemberDoubleClicked(const QModelIndex& index) {
if (!nodeId) return; if (!nodeId) return;
QString name = m_model->data(index, Qt::DisplayRole).toString(); QString name = m_model->data(index, Qt::DisplayRole).toString();
MemberPropsDialog dlg(m_db, m_channelId, nodeId, name, this); 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) { void AccountList::onMemberContextMenu(const QPoint& pos) {
@ -223,11 +226,17 @@ void AccountList::onMemberContextMenu(const QPoint& pos) {
if (chosen == renameAction) { if (chosen == renameAction) {
RenameDialog dlg(m_db, m_channelId, nodeId, name, this); 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; return;
} }
if (chosen != editAction) return; if (chosen != editAction) return;
MemberPropsDialog dlg(m_db, m_channelId, nodeId, name, this); MemberPropsDialog dlg(m_db, m_channelId, nodeId, name, this);
dlg.exec(); if (dlg.exec() == QDialog::Accepted) {
m_model->refresh();
emit memberRenamed();
}
} }

3
tools/chatgui/src/accountlist.h

@ -25,6 +25,9 @@ public:
void setChannel(const QString& channelId); void setChannel(const QString& channelId);
void refresh(); void refresh();
signals:
void memberRenamed();
private slots: private slots:
void onMemberClicked(const QModelIndex& index); void onMemberClicked(const QModelIndex& index);
void onMemberDoubleClicked(const QModelIndex& index); void onMemberDoubleClicked(const QModelIndex& index);

2
tools/chatgui/src/mainwindow.cpp

@ -233,6 +233,8 @@ void MainWindow::setupConnects() {
connect(m_channelList, &ChannelList::joinRequested, this, &MainWindow::showJoinDialog); connect(m_channelList, &ChannelList::joinRequested, this, &MainWindow::showJoinDialog);
connect(m_channelList, &ChannelList::createGroupRequested, this, &MainWindow::onCreateGroupRequested); connect(m_channelList, &ChannelList::createGroupRequested, this, &MainWindow::onCreateGroupRequested);
connect(m_channelList, &ChannelList::settingsRequested, this, &MainWindow::showSettings); connect(m_channelList, &ChannelList::settingsRequested, this, &MainWindow::showSettings);
connect(m_accountList, &AccountList::memberRenamed,
m_messageList, &MessageList::reloadLocalNicks);
connect(m_messageList, &MessageList::readPositionChanged, connect(m_messageList, &MessageList::readPositionChanged,
this, [this](const QString& channelId, qint64 lastReadMsgId) { this, [this](const QString& channelId, qint64 lastReadMsgId) {
Q_UNUSED(lastReadMsgId); Q_UNUSED(lastReadMsgId);

1
tools/chatgui/src/messagedelegate.h

@ -14,6 +14,7 @@ enum MessageDataRole {
MsgReactionsRole = Qt::UserRole + 9, MsgReactionsRole = Qt::UserRole + 9,
MsgIdRole = Qt::UserRole + 10, MsgIdRole = Qt::UserRole + 10,
MsgIsOutgoingRole = Qt::UserRole + 11, MsgIsOutgoingRole = Qt::UserRole + 11,
MsgAuthorNodeIdRole = Qt::UserRole + 20,
}; };
class MessageDelegate : public QStyledItemDelegate { class MessageDelegate : public QStyledItemDelegate {

17
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, setMsg(item, author, QString::fromUtf8(m.data), time, avatar, false,
false, QString(), QString(), reacts); false, QString(), QString(), reacts);
item->setData(m.id, MsgIdRole); item->setData(m.id, MsgIdRole);
item->setData(QVariant::fromValue(m.authorNodeId), MsgAuthorNodeIdRole);
item->setData(m.isOutgoing ? 1 : 0, MsgIsOutgoingRole); item->setData(m.isOutgoing ? 1 : 0, MsgIsOutgoingRole);
m_model->appendRow(item); m_model->appendRow(item);
} }
@ -291,6 +292,7 @@ void MessageList::refresh() {
setMsg(item, author, QString::fromUtf8(m.data), time, avatar, false, setMsg(item, author, QString::fromUtf8(m.data), time, avatar, false,
false, QString(), QString(), QVariantList{}); false, QString(), QString(), QVariantList{});
item->setData(m.id, MsgIdRole); item->setData(m.id, MsgIdRole);
item->setData(QVariant::fromValue(m.authorNodeId), MsgAuthorNodeIdRole);
item->setData(m.isOutgoing ? 1 : 0, MsgIsOutgoingRole); item->setData(m.isOutgoing ? 1 : 0, MsgIsOutgoingRole);
m_model->appendRow(item); m_model->appendRow(item);
while (m_model->rowCount() > 100) 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, setMsg(item, author, QString::fromUtf8(content), time, avatar, false,
false, QString(), QString(), QVariantList{}); false, QString(), QString(), QVariantList{});
bool isSelf = m_db && (authorNodeId == m_db->myNodeId()); bool isSelf = m_db && (authorNodeId == m_db->myNodeId());
item->setData(QVariant::fromValue(authorNodeId), MsgAuthorNodeIdRole);
item->setData(isSelf ? 1 : 0, MsgIsOutgoingRole); item->setData(isSelf ? 1 : 0, MsgIsOutgoingRole);
m_model->appendRow(item); m_model->appendRow(item);
@ -366,6 +369,20 @@ QString MessageList::authorName(quint64 nodeId) const {
return m_db->getDisplayName(nodeId); 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) { void MessageList::restoreScrollPosition(const QString& channelId) {
if (!m_db || m_model->rowCount() == 0) { if (!m_db || m_model->rowCount() == 0) {
return; return;

1
tools/chatgui/src/messagelist.h

@ -18,6 +18,7 @@ public:
void loadChannel(const QString& channelId); void loadChannel(const QString& channelId);
void refresh(); void refresh();
void reloadLocalNicks();
void saveChannelState(); void saveChannelState();
static void cleanupAnimations(); static void cleanupAnimations();
void addMessage(const QString& channelId, quint64 authorNodeId, void addMessage(const QString& channelId, quint64 authorNodeId,

Loading…
Cancel
Save