From 0f4dc940ce9f1f75f7341f33c7c5ac924198c422 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sun, 24 May 2020 22:13:35 +0200 Subject: [PATCH] refactor: remove Core dependency from Group Replace the direct call with a signal connection in Widget, this keeps Group clean. --- src/core/coreav.cpp | 4 ++-- src/core/coreav.h | 2 +- src/model/group.cpp | 17 +++-------------- src/model/group.h | 3 --- src/widget/widget.cpp | 9 +++++++++ 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 0290ddf8c..a9dd42e8a 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -503,11 +503,11 @@ void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const i * @param group Group Index * @param peer Peer Index */ -void CoreAV::invalidateGroupCallPeerSource(int group, ToxPk peerPk) +void CoreAV::invalidateGroupCallPeerSource(const Group& group, ToxPk peerPk) { QWriteLocker locker{&callsLock}; - auto it = groupCalls.find(group); + auto it = groupCalls.find(group.getId()); if (it == groupCalls.end()) { return; } diff --git a/src/core/coreav.h b/src/core/coreav.h index fb2845b0a..98860aa44 100644 --- a/src/core/coreav.h +++ b/src/core/coreav.h @@ -81,7 +81,7 @@ public: static void groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data, unsigned samples, uint8_t channels, uint32_t sample_rate, void* core); - void invalidateGroupCallPeerSource(int group, ToxPk peerPk); + void invalidateGroupCallPeerSource(const Group& group, ToxPk peerPk); public slots: bool startCall(uint32_t friendNum, bool video); diff --git a/src/model/group.cpp b/src/model/group.cpp index d7a715142..94a9fd1d5 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -20,14 +20,12 @@ #include "group.h" #include "friend.h" #include "src/core/contactid.h" -#include "src/core/core.h" -#include "src/core/coreav.h" #include "src/core/groupid.h" #include "src/core/toxpk.h" #include "src/friendlist.h" -#include "src/persistence/settings.h" -#include "src/widget/form/groupchatform.h" -#include "src/widget/groupwidget.h" + +#include + #include static const int MAX_GROUP_TITLE_LENGTH = 128; @@ -105,7 +103,6 @@ void Group::regeneratePeerList() for (const auto& pk : oldPeerNames.keys()) { if (!peerDisplayNames.contains(pk)) { emit userLeft(pk, oldPeerNames.value(pk)); - stopAudioOfDepartedPeers(pk); } } for (const auto& pk : peerDisplayNames.keys()) { @@ -209,11 +206,3 @@ bool Group::useHistory() const { return false; } - -void Group::stopAudioOfDepartedPeers(const ToxPk& peerPk) -{ - if (avGroupchat) { - Core* core = Core::getInstance(); - core->getAv()->invalidateGroupCallPeerSource(toxGroupNum, peerPk); - } -} diff --git a/src/model/group.h b/src/model/group.h index e72e684c6..78edd4952 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -70,9 +70,6 @@ signals: void numPeersChanged(int numPeers); void peerNameChanged(const ToxPk& peer, const QString& oldName, const QString& newName); -private: - void stopAudioOfDepartedPeers(const ToxPk& peerPk); - private: ICoreGroupQuery& groupQuery; ICoreIdHandler& idHandler; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 115f52d83..798a27905 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -2079,6 +2079,15 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) const bool enabled = core->getGroupAvEnabled(groupnumber); Group* newgroup = GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername()); + assert(newgroup); + + if (enabled) { + connect(newgroup, &Group::userLeft, [=](const ToxPk& user){ + CoreAV *av = core->getAv(); + assert(av); + av->invalidateGroupCallPeerSource(*newgroup, user); + }); + } auto dialogManager = ContentDialogManager::getInstance(); auto rawChatroom = new GroupChatroom(newgroup, dialogManager); std::shared_ptr chatroom(rawChatroom);