From 01f79b0d084176c4b6deaa289060f60652bf7428 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Wed, 26 Dec 2018 18:05:03 +0200 Subject: [PATCH] fix(core): update group peerLists on local changes --- src/model/friend.cpp | 8 ++++++++ src/model/group.cpp | 6 ++++++ src/model/group.h | 1 + src/nexus.cpp | 1 + src/widget/form/groupchatform.cpp | 7 ++++++- src/widget/widget.cpp | 7 +++++++ src/widget/widget.h | 1 + 7 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/model/friend.cpp b/src/model/friend.cpp index 1c0b43fc4..13481b158 100644 --- a/src/model/friend.cpp +++ b/src/model/friend.cpp @@ -84,6 +84,14 @@ void Friend::setAlias(const QString& alias) if (oldDisplayed != newDisplayed) { emit displayedNameChanged(newDisplayed); } + + for (Group* g : GroupList::getAllGroups()) { + if (userAlias.isEmpty()) { + g->updateUsername(friendPk, userName); + continue; + } + g->updateUsername(friendPk, userAlias); + } } void Friend::setStatusMessage(const QString& message) diff --git a/src/model/group.cpp b/src/model/group.cpp index e5c20f861..3803fa0f7 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -119,6 +119,12 @@ void Group::regeneratePeerList() emit userListChanged(groupId, toxpks); } +void Group::updateUsername(ToxPk pk, const QString newName) +{ + toxpks[pk] = newName; + emit userListChanged(groupId, toxpks); +} + bool Group::isAvGroupchat() const { return avGroupchat; diff --git a/src/model/group.h b/src/model/group.h index a30180940..22469ca95 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -47,6 +47,7 @@ public: bool getMentionedFlag() const; void updatePeer(int peerId, QString newName); + void updateUsername(ToxPk pk, const QString newName); void setName(const QString& newTitle) override; void setTitle(const QString& author, const QString& newTitle); QString getName() const; diff --git a/src/nexus.cpp b/src/nexus.cpp index 611189bf5..a94cf3249 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -213,6 +213,7 @@ void Nexus::showMainGUI() connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged); connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult); connect(core, &Core::groupSentFailed, widget, &Widget::onGroupSendFailed); + connect(core, &Core::usernameSet, widget, &Widget::refreshPeerListsLocal); connect(widget, &Widget::statusSet, core, &Core::setStatus); connect(widget, &Widget::friendRequested, core, &Core::requestFriendship); diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index 6323bd563..77636161c 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -337,7 +337,12 @@ void GroupChatForm::sendJoinLeaveMessages() addSystemInfoMessage(tr("%1 has joined the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime()); } else { - if (groupLast[peerPk] != name && peers.value(peerPk) == name) { + Friend *f = FriendList::findFriend(peerPk); + if (groupLast[peerPk] != name + && peers.value(peerPk) == name + && peerPk != Core::getInstance()->getSelfPublicKey() // ignore myself + && !(f != nullptr && f->hasAlias()) // ignore friends with aliases + ) { addSystemInfoMessage(tr("%1 is now known as %2").arg(groupLast[peerPk], name), ChatMessage::INFO, QDateTime::currentDateTime()); groupLast[peerPk] = name; } diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 1c8887101..e1fc0d774 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -2503,3 +2503,10 @@ void Widget::focusChatInput() } } } + +void Widget::refreshPeerListsLocal(const QString &username) +{ + for (Group* g : GroupList::getAllGroups()) { + g->updateUsername(Core::getInstance()->getSelfPublicKey(), username); + } +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 06d5877bc..2daa4525b 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -182,6 +182,7 @@ public slots: void onFriendDialogShown(const Friend* f); void onGroupDialogShown(Group* g); void toggleFullscreen(); + void refreshPeerListsLocal(const QString &username); signals: void friendRequestAccepted(const ToxPk& friendPk);