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

refactor(group): store peer list in a more intelligent way

This commit is contained in:
sudden6 2018-03-04 19:59:35 +01:00
parent 0d74134dc1
commit 498c04ba50
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 10 additions and 11 deletions

View File

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

View File

@ -65,8 +65,6 @@ signals:
private:
QString selfName;
QString title;
GroupChatForm* chatForm;
QStringList peers;
QMap<QByteArray, QString> toxids;
bool hasNewMessages;
bool userWasMentioned;