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

Commit

Permalink
fix(core): support user aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Dec 26, 2018
1 parent 9b261fd commit feee0e7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/friendlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ QList<Friend*> FriendList::getAllFriends()
{
return friendList.values();
}

QString FriendList::decideNickname(ToxPk peerPk, const QString origName)
{
Friend* f = FriendList::findFriend(peerPk);
if (f != nullptr && f->hasAlias()) {
return f->getDisplayedName();
} else {
return origName;
}
}
2 changes: 2 additions & 0 deletions src/friendlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template <class A, class B>
class QHash;
class Friend;
class QByteArray;
class QString;
class ToxPk;

class FriendList
Expand All @@ -39,6 +40,7 @@ class FriendList
static QList<Friend*> getAllFriends();
static void removeFriend(uint32_t friendId, bool fake = false);
static void clear();
static QString decideNickname(ToxPk peerPk, const QString origName);

private:
static QHash<uint32_t, Friend*> friendList;
Expand Down
12 changes: 9 additions & 3 deletions src/widget/form/groupchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void GroupChatForm::updateUserNames()
* and then sort them by their text and add them to the layout in that order */
const auto selfPk = Core::getInstance()->getSelfPublicKey();
for (const auto& peerPk : peers.keys()) {
const QString fullName = peers.value(peerPk);
const QString fullName = FriendList::decideNickname(peerPk, peers.value(peerPk));
const QString editedName = editName(fullName).append(QLatin1String(", "));
QLabel* const label = new QLabel(editedName);
if (editedName != fullName) {
Expand Down Expand Up @@ -325,21 +325,27 @@ void GroupChatForm::sendJoinLeaveMessages()

// user joins
for (const auto& peerPk : peers.keys()) {
const QString name = peers.value(peerPk);
// ignore weird issue: when user joins the group, the name is empty, then it's renamed to normal nickname (why?)
// so, just ignore the first insertion
if (!firstTime.value(peerPk, false)) {
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());
}
else {
if (groupLast[peerPk] != name && peers.value(peerPk) == name) {
addSystemInfoMessage(tr("%1 is now known as %2").arg(groupLast[peerPk], name), ChatMessage::INFO, QDateTime::currentDateTime());
groupLast[peerPk] = name;
}
}
}
// user leaves
for (const auto& peerPk : groupLast.keys()) {
const QString name = groupLast.value(peerPk);
const QString name = FriendList::decideNickname(peerPk, groupLast.value(peerPk));
if (!peers.contains(peerPk)) {
groupLast.remove(peerPk);
firstTime.remove(peerPk);
Expand Down

0 comments on commit feee0e7

Please sign in to comment.