From 08839b70526a6bb73003ad290594fa073aa7e626 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Tue, 14 May 2019 16:40:41 -0700 Subject: [PATCH] refactor(group): remove redundant updatePeer API --- src/core/core.cpp | 6 ++++-- src/core/core.h | 2 +- src/model/group.cpp | 8 -------- src/model/group.h | 1 - src/widget/widget.cpp | 4 ++-- src/widget/widget.h | 2 +- 6 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 05dec71ad..46cdec2b4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -576,11 +576,13 @@ void Core::onGroupPeerListChange(Tox*, uint32_t groupId, void* vCore) } void Core::onGroupPeerNameChange(Tox*, uint32_t groupId, uint32_t peerId, const uint8_t* name, - size_t length, void* core) + size_t length, void* vCore) { const auto newName = ToxString(name, length).getQString(); qDebug() << QString("Group %1, Peer %2, name changed to %3").arg(groupId).arg(peerId).arg(newName); - emit static_cast(core)->groupPeerNameChanged(groupId, peerId, newName); + auto* core = static_cast(vCore); + auto peerPk = core->getGroupPeerPk(groupId, peerId); + emit core->groupPeerNameChanged(groupId, peerPk, newName); } void Core::onGroupTitleChange(Tox*, uint32_t groupId, uint32_t peerId, const uint8_t* cTitle, diff --git a/src/core/core.h b/src/core/core.h index d16e1c581..9982d9d8e 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -169,7 +169,7 @@ signals: void groupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction); void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void groupPeerlistChanged(int groupnumber); - void groupPeerNameChanged(int groupnumber, int peernumber, const QString& newName); + void groupPeerNameChanged(int groupnumber, const ToxPk& peerPk, const QString& newName); void groupTitleChanged(int groupnumber, const QString& author, const QString& title); void groupPeerAudioPlaying(int groupnumber, ToxPk peerPk); void groupSentFailed(int groupId); diff --git a/src/model/group.cpp b/src/model/group.cpp index 27f583a95..995d28c6d 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -47,14 +47,6 @@ Group::Group(int groupId, const GroupId persistentGroupId, const QString& name, regeneratePeerList(); } -void Group::updatePeer(int peerId, QString name) -{ - ToxPk peerKey = Core::getInstance()->getGroupPeerPk(groupId, peerId); - toxpks[peerKey] = name; - qDebug() << "name change: " + name; - emit userListChanged(persistentGroupId, toxpks); -} - void Group::setName(const QString& newTitle) { const QString shortTitle = newTitle.left(MAX_GROUP_TITLE_LENGTH); diff --git a/src/model/group.h b/src/model/group.h index 1552b473f..f979596b4 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -49,7 +49,6 @@ public: void setMentionedFlag(bool f); bool getMentionedFlag() const; - void updatePeer(int peerId, QString newName); void updateUsername(ToxPk pk, const QString newName); void setName(const QString& newTitle) override; void setTitle(const QString& author, const QString& newTitle); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index c924cbc59..ad0ef757b 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1772,7 +1772,7 @@ void Widget::onGroupPeerlistChanged(uint32_t groupnumber) g->regeneratePeerList(); } -void Widget::onGroupPeerNameChanged(uint32_t groupnumber, int peernumber, const QString& newName) +void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, const QString& newName) { const GroupId& groupId = GroupList::id2Key(groupnumber); Group* g = GroupList::findGroup(groupId); @@ -1783,7 +1783,7 @@ void Widget::onGroupPeerNameChanged(uint32_t groupnumber, int peernumber, const setName = tr("", "Placeholder when someone's name in a group chat is empty"); } - g->updatePeer(peernumber, setName); + g->updateUsername(peerPk, newName); } void Widget::onGroupTitleChanged(uint32_t groupnumber, const QString& author, const QString& title) diff --git a/src/widget/widget.h b/src/widget/widget.h index 1b03ac848..d81f82e96 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -174,7 +174,7 @@ public slots: void onGroupInviteAccepted(const GroupInvite& inviteInfo); void onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction); void onGroupPeerlistChanged(uint32_t groupnumber); - void onGroupPeerNameChanged(uint32_t groupnumber, int peernumber, const QString& newName); + void onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, const QString& newName); void onGroupTitleChanged(uint32_t groupnumber, const QString& author, const QString& title); void titleChangedByUser(const GroupId& groupId, const QString& title); void onGroupPeerAudioPlaying(int groupnumber, ToxPk peerPk);