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

refactor: remove Core dependency from Group

Replace the direct call with a signal connection in Widget, this keeps
Group clean.
This commit is contained in:
sudden6 2020-05-24 22:13:35 +02:00
parent 445340a0e9
commit 0f4dc940ce
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
5 changed files with 15 additions and 20 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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 <cassert>
#include <QDebug>
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);
}
}

View File

@ -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;

View File

@ -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<GroupChatroom> chatroom(rawChatroom);