diff --git a/src/model/group.cpp b/src/model/group.cpp index 3803fa0f7..7e2e811ce 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -104,21 +104,29 @@ void Group::regeneratePeerList() for (int i = 0; i < nPeers; ++i) { const auto pk = core->getGroupPeerPk(groupId, i); - toxpks[pk] = peers[i]; - if (toxpks[pk].isEmpty()) { - toxpks[pk] = - tr("", "Placeholder when someone's name in a group chat is empty"); - } - Friend* f = FriendList::findFriend(pk); if (f != nullptr && f->hasAlias()) { toxpks[pk] = f->getDisplayedName(); + empty_nick[pk] = false; + continue; + } + + empty_nick[pk] = peers[i].isEmpty(); + if (empty_nick[pk]) { + toxpks[pk] = tr("", "Placeholder when someone's name in a group chat is empty"); + } else { + toxpks[pk] = peers[i]; } } emit userListChanged(groupId, toxpks); } +bool Group::peerHasNickname(ToxPk pk) +{ + return !empty_nick[pk]; +} + void Group::updateUsername(ToxPk pk, const QString newName) { toxpks[pk] = newName; diff --git a/src/model/group.h b/src/model/group.h index 22469ca95..b8cc23bc7 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -39,6 +39,7 @@ public: int getPeersCount() const; void regeneratePeerList(); const QMap& getPeerList() const; + bool peerHasNickname(ToxPk pk); void setEventFlag(bool f) override; bool getEventFlag() const override; @@ -67,6 +68,7 @@ private: QString selfName; QString title; QMap toxpks; + QMap empty_nick; bool hasNewMessages; bool userWasMentioned; int groupId; diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index 6b2e0ce88..a61f10901 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -325,14 +325,20 @@ void GroupChatForm::sendJoinLeaveMessages() // user joins for (const auto& peerPk : peers.keys()) { + const QString name = FriendList::decideNickname(peerPk, peers.value(peerPk)); if (!firstTime.value(peerPk, false)) { if (!groupLast.contains(peerPk)) { + if (group->peerHasNickname(peerPk)) { + firstTime[peerPk] = true; + groupLast.insert(peerPk, name); + addSystemInfoMessage(tr("%1 is online").arg(name), ChatMessage::INFO, QDateTime::currentDateTime()); + continue; + } addSystemInfoMessage(tr("A new user has connected to the group"), ChatMessage::INFO, QDateTime::currentDateTime()); } firstTime[peerPk] = true; continue; } - const QString name = FriendList::decideNickname(peerPk, peers.value(peerPk)); if (!groupLast.contains(peerPk)) { groupLast.insert(peerPk, name); addSystemInfoMessage(tr("%1 has joined the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());