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:
parent
08839b7052
commit
04f1ccda35
@ -81,12 +81,14 @@ QList<Friend*> FriendList::getAllFriends()
|
|||||||
return friendList.values();
|
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);
|
Friend* f = FriendList::findFriend(friendPk);
|
||||||
if (f != nullptr && f->hasAlias()) {
|
if (f != nullptr) {
|
||||||
return f->getDisplayedName();
|
return f->getDisplayedName();
|
||||||
} else {
|
} else if (!origName.isEmpty()) {
|
||||||
return origName;
|
return origName;
|
||||||
|
} else {
|
||||||
|
return friendPk.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
static QList<Friend*> getAllFriends();
|
static QList<Friend*> getAllFriends();
|
||||||
static void removeFriend(const ToxPk& friendPk, bool fake = false);
|
static void removeFriend(const ToxPk& friendPk, bool fake = false);
|
||||||
static void clear();
|
static void clear();
|
||||||
static QString decideNickname(const ToxPk& friendPk, const QString origName);
|
static QString decideNickname(const ToxPk& friendPk, const QString& origName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QHash<ToxPk, Friend*> friendList;
|
static QHash<ToxPk, Friend*> friendList;
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "friend.h"
|
#include "friend.h"
|
||||||
#include "src/model/group.h"
|
|
||||||
#include "src/model/status.h"
|
#include "src/model/status.h"
|
||||||
#include "src/grouplist.h"
|
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/widget/form/chatform.h"
|
#include "src/widget/form/chatform.h"
|
||||||
|
|
||||||
@ -66,6 +64,7 @@ void Friend::setName(const QString& _name)
|
|||||||
emit displayedNameChanged(newDisplayed);
|
emit displayedNameChanged(newDisplayed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Friend::setAlias sets the alias for the friend
|
* @brief Friend::setAlias sets the alias for the friend
|
||||||
* @param alias new alias, removes it if set to an empty string
|
* @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) {
|
if (oldDisplayed != newDisplayed) {
|
||||||
emit displayedNameChanged(newDisplayed);
|
emit displayedNameChanged(newDisplayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Group* g : GroupList::getAllGroups()) {
|
|
||||||
if (g->getPeerList().contains(friendPk)) {
|
|
||||||
g->updateUsername(friendPk, newDisplayed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Friend::setStatusMessage(const QString& message)
|
void Friend::setStatusMessage(const QString& message)
|
||||||
@ -126,6 +119,11 @@ bool Friend::hasAlias() const
|
|||||||
return !userAlias.isEmpty();
|
return !userAlias.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Friend::getUserName() const
|
||||||
|
{
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
const ToxPk& Friend::getPublicKey() const
|
const ToxPk& Friend::getPublicKey() const
|
||||||
{
|
{
|
||||||
return friendPk;
|
return friendPk;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
void setAlias(const QString& name);
|
void setAlias(const QString& name);
|
||||||
QString getDisplayedName() const override;
|
QString getDisplayedName() const override;
|
||||||
bool hasAlias() const;
|
bool hasAlias() const;
|
||||||
|
QString getUserName() const;
|
||||||
void setStatusMessage(const QString& message);
|
void setStatusMessage(const QString& message);
|
||||||
QString getStatusMessage() const;
|
QString getStatusMessage() const;
|
||||||
|
|
||||||
|
@ -97,11 +97,7 @@ void Group::regeneratePeerList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
empty_nick[pk] = peers[i].isEmpty();
|
empty_nick[pk] = peers[i].isEmpty();
|
||||||
if (empty_nick[pk]) {
|
toxpks[pk] = FriendList::decideNickname(pk, peers[i]);
|
||||||
toxpks[pk] = tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
|
|
||||||
} else {
|
|
||||||
toxpks[pk] = peers[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (avGroupchat) {
|
if (avGroupchat) {
|
||||||
stopAudioOfDepartedPeers(oldPeers, toxpks);
|
stopAudioOfDepartedPeers(oldPeers, toxpks);
|
||||||
|
@ -1100,8 +1100,14 @@ void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
|||||||
void Widget::onFriendDisplayedNameChanged(const QString& displayed)
|
void Widget::onFriendDisplayedNameChanged(const QString& displayed)
|
||||||
{
|
{
|
||||||
Friend* f = qobject_cast<Friend*>(sender());
|
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()) {
|
if (friendWidget->isActive()) {
|
||||||
GUI::setWindowTitle(displayed);
|
GUI::setWindowTitle(displayed);
|
||||||
}
|
}
|
||||||
@ -1533,6 +1539,12 @@ void Widget::removeFriend(Friend* f, bool fake)
|
|||||||
FriendList::removeFriend(friendPk, fake);
|
FriendList::removeFriend(friendPk, fake);
|
||||||
if (!fake) {
|
if (!fake) {
|
||||||
core->removeFriend(f->getId());
|
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);
|
friendWidgets.remove(friendPk);
|
||||||
@ -1778,11 +1790,7 @@ void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, c
|
|||||||
Group* g = GroupList::findGroup(groupId);
|
Group* g = GroupList::findGroup(groupId);
|
||||||
assert(g);
|
assert(g);
|
||||||
|
|
||||||
QString setName = newName;
|
const QString setName = FriendList::decideNickname(peerPk, newName);
|
||||||
if (newName.isEmpty()) {
|
|
||||||
setName = tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
g->updateUsername(peerPk, newName);
|
g->updateUsername(peerPk, newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user