Browse Source

refactor: remove Core dependency from Group

Replace the direct call with a signal connection in Widget, this keeps
Group clean.
reviewable/pr6157/r3
sudden6 5 years ago
parent
commit
0f4dc940ce
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 4
      src/core/coreav.cpp
  2. 2
      src/core/coreav.h
  3. 17
      src/model/group.cpp
  4. 3
      src/model/group.h
  5. 9
      src/widget/widget.cpp

4
src/core/coreav.cpp

@ -503,11 +503,11 @@ void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const i @@ -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;
}

2
src/core/coreav.h

@ -81,7 +81,7 @@ public: @@ -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);

17
src/model/group.cpp

@ -20,14 +20,12 @@ @@ -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() @@ -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 @@ -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);
}
}

3
src/model/group.h

@ -70,9 +70,6 @@ signals: @@ -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;

9
src/widget/widget.cpp

@ -2079,6 +2079,15 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) @@ -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);

Loading…
Cancel
Save