1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(group): treat empty peer names like empty friend names, by showing pk

Fix #5660
This commit is contained in:
Anthony Bilinski 2019-05-14 16:49:18 -07:00
parent 08839b7052
commit 04f1ccda35
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
6 changed files with 28 additions and 24 deletions

View File

@ -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();
}
}

View File

@ -40,7 +40,7 @@ public:
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;

View File

@ -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"
@ -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
@ -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)
@ -126,6 +119,11 @@ bool Friend::hasAlias() const
return !userAlias.isEmpty();
}
QString Friend::getUserName() const
{
return userName;
}
const ToxPk& Friend::getPublicKey() const
{
return friendPk;

View File

@ -40,7 +40,7 @@ public:
void setAlias(const QString& name);
QString getDisplayedName() const override;
bool hasAlias() const;
QString getUserName() const;
void setStatusMessage(const QString& message);
QString getStatusMessage() const;

View File

@ -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);

View File

@ -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);
}
@ -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);
@ -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);
}