From 498c04ba50e91ff183b593ec3cebe381bde215a4 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sun, 4 Mar 2018 19:59:35 +0100 Subject: [PATCH] refactor(group): store peer list in a more intelligent way --- src/model/group.cpp | 19 ++++++++++--------- src/model/group.h | 2 -- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/model/group.cpp b/src/model/group.cpp index 08a44aea4..d2ed122c5 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -47,13 +47,11 @@ void Group::updatePeer(int peerId, QString name) { ToxPk peerKey = Core::getInstance()->getGroupPeerPk(groupId, peerId); QByteArray peerPk = peerKey.getKey(); - peers[peerId] = name; toxids[peerPk] = name; Friend* f = FriendList::findFriend(peerKey); if (f != nullptr) { // use the displayed name from the friends list - peers[peerId] = f->getDisplayedName(); toxids[peerPk] = f->getDisplayedName(); } else { emit userListChanged(groupId, toxids); @@ -94,24 +92,26 @@ QString Group::getDisplayedName() const void Group::regeneratePeerList() { const Core* core = Core::getInstance(); - peers = core->getGroupPeerNames(groupId); + const ToxPk self = core->getSelfId().getPublicKey(); + + QStringList peers = core->getGroupPeerNames(groupId); toxids.clear(); nPeers = peers.size(); for (int i = 0; i < nPeers; ++i) { ToxPk id = core->getGroupPeerPk(groupId, i); - ToxPk self = core->getSelfId().getPublicKey(); - if (id == self) + if (id == self) { selfPeerNum = i; + } QByteArray peerPk = id.getKey(); toxids[peerPk] = peers[i]; - if (toxids[peerPk].isEmpty()) + if (toxids[peerPk].isEmpty()) { toxids[peerPk] = tr("", "Placeholder when someone's name in a group chat is empty"); + } Friend* f = FriendList::findFriend(id); if (f != nullptr && f->hasAlias()) { - peers[i] = f->getDisplayedName(); toxids[peerPk] = f->getDisplayedName(); } } @@ -136,7 +136,7 @@ int Group::getPeersCount() const QStringList Group::getPeerList() const { - return peers; + return toxids.values(); } bool Group::isSelfPeerNumber(int num) const @@ -169,8 +169,9 @@ QString Group::resolveToxId(const ToxPk& id) const QByteArray key = id.getKey(); auto it = toxids.find(key); - if (it != toxids.end()) + if (it != toxids.end()) { return *it; + } return QString(); } diff --git a/src/model/group.h b/src/model/group.h index 44bb3c430..34996b4c3 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -65,8 +65,6 @@ signals: private: QString selfName; QString title; - GroupChatForm* chatForm; - QStringList peers; QMap toxids; bool hasNewMessages; bool userWasMentioned;