Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(group): treat empty peer names like empty friend names, by showin…
Browse files Browse the repository at this point in the history
…g pk

Fix #5660
  • Loading branch information
anthonybilinski committed May 15, 2019
1 parent 08839b7 commit 04f1ccd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
8 changes: 5 additions & 3 deletions src/friendlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ QList<Friend*> FriendList::getAllFriends()
return friendList.values();
}

QString FriendList::decideNickname(const ToxPk& friendPk, const QString origName)
QString FriendList::decideNickname(const ToxPk& friendPk, const QString& origName)
{
Friend* f = FriendList::findFriend(friendPk);
if (f != nullptr && f->hasAlias()) {
if (f != nullptr) {
return f->getDisplayedName();
} else {
} else if (!origName.isEmpty()) {
return origName;
} else {
return friendPk.toString();
}
}
2 changes: 1 addition & 1 deletion src/friendlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FriendList
static QList<Friend*> getAllFriends();
static void removeFriend(const ToxPk& friendPk, bool fake = false);
static void clear();
static QString decideNickname(const ToxPk& friendPk, const QString origName);
static QString decideNickname(const ToxPk& friendPk, const QString& origName);

private:
static QHash<ToxPk, Friend*> friendList;
Expand Down
14 changes: 6 additions & 8 deletions src/model/friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@


#include "friend.h"
#include "src/model/group.h"
#include "src/model/status.h"
#include "src/grouplist.h"
#include "src/persistence/profile.h"
#include "src/widget/form/chatform.h"

Expand Down Expand Up @@ -66,6 +64,7 @@ void Friend::setName(const QString& _name)
emit displayedNameChanged(newDisplayed);
}
}

/**
* @brief Friend::setAlias sets the alias for the friend
* @param alias new alias, removes it if set to an empty string
Expand All @@ -85,12 +84,6 @@ void Friend::setAlias(const QString& alias)
if (oldDisplayed != newDisplayed) {
emit displayedNameChanged(newDisplayed);
}

for (Group* g : GroupList::getAllGroups()) {
if (g->getPeerList().contains(friendPk)) {
g->updateUsername(friendPk, newDisplayed);
}
}
}

void Friend::setStatusMessage(const QString& message)
Expand Down Expand Up @@ -126,6 +119,11 @@ bool Friend::hasAlias() const
return !userAlias.isEmpty();
}

QString Friend::getUserName() const
{
return userName;
}

const ToxPk& Friend::getPublicKey() const
{
return friendPk;
Expand Down
2 changes: 1 addition & 1 deletion src/model/friend.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Friend : public Contact
void setAlias(const QString& name);
QString getDisplayedName() const override;
bool hasAlias() const;

QString getUserName() const;
void setStatusMessage(const QString& message);
QString getStatusMessage() const;

Expand Down
6 changes: 1 addition & 5 deletions src/model/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ void Group::regeneratePeerList()
}

empty_nick[pk] = peers[i].isEmpty();
if (empty_nick[pk]) {
toxpks[pk] = tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
} else {
toxpks[pk] = peers[i];
}
toxpks[pk] = FriendList::decideNickname(pk, peers[i]);
}
if (avGroupchat) {
stopAudioOfDepartedPeers(oldPeers, toxpks);
Expand Down
20 changes: 14 additions & 6 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,14 @@ void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
void Widget::onFriendDisplayedNameChanged(const QString& displayed)
{
Friend* f = qobject_cast<Friend*>(sender());
FriendWidget* friendWidget = friendWidgets[f->getPublicKey()];
const auto& friendPk = f->getPublicKey();
for (Group* g : GroupList::getAllGroups()) {
if (g->getPeerList().contains(friendPk)) {
g->updateUsername(friendPk, displayed);
}
}

FriendWidget* friendWidget = friendWidgets[f->getPublicKey()];
if (friendWidget->isActive()) {
GUI::setWindowTitle(displayed);
}
Expand Down Expand Up @@ -1533,6 +1539,12 @@ void Widget::removeFriend(Friend* f, bool fake)
FriendList::removeFriend(friendPk, fake);
if (!fake) {
core->removeFriend(f->getId());
// aliases aren't supported for non-friend peers in groups, revert to basic username
for (Group* g : GroupList::getAllGroups()) {
if (g->getPeerList().contains(friendPk)) {
g->updateUsername(friendPk, f->getUserName());
}
}
}

friendWidgets.remove(friendPk);
Expand Down Expand Up @@ -1778,11 +1790,7 @@ void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, c
Group* g = GroupList::findGroup(groupId);
assert(g);

QString setName = newName;
if (newName.isEmpty()) {
setName = tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
}

const QString setName = FriendList::decideNickname(peerPk, newName);
g->updateUsername(peerPk, newName);
}

Expand Down

0 comments on commit 04f1ccd

Please sign in to comment.