Browse Source

fix(core): support user aliases

reviewable/pr5469/r2
Monsterovich 7 years ago
parent
commit
feee0e767f
  1. 10
      src/friendlist.cpp
  2. 2
      src/friendlist.h
  3. 12
      src/widget/form/groupchatform.cpp

10
src/friendlist.cpp

@ -87,3 +87,13 @@ QList<Friend*> FriendList::getAllFriends() @@ -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
src/friendlist.h

@ -28,6 +28,7 @@ template <class A, class B> @@ -28,6 +28,7 @@ template <class A, class B>
class QHash;
class Friend;
class QByteArray;
class QString;
class ToxPk;
class FriendList
@ -39,6 +40,7 @@ public: @@ -39,6 +40,7 @@ public:
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;

12
src/widget/form/groupchatform.cpp

@ -262,7 +262,7 @@ void GroupChatForm::updateUserNames() @@ -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) {
@ -325,21 +325,27 @@ void GroupChatForm::sendJoinLeaveMessages() @@ -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);

Loading…
Cancel
Save