Browse Source

refactor: remove getInstance() from friendchatroom.cpp

reviewable/pr6187/r5
sudden6 5 years ago
parent
commit
5fdadadfb5
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 10
      src/model/chatroom/friendchatroom.cpp
  2. 4
      src/model/chatroom/friendchatroom.h
  3. 6
      src/widget/widget.cpp

10
src/model/chatroom/friendchatroom.cpp

@ -42,9 +42,10 @@ QString getShortName(const QString& name)
} }
FriendChatroom::FriendChatroom(Friend* frnd, IDialogsManager* dialogsManager) FriendChatroom::FriendChatroom(Friend* frnd, IDialogsManager* dialogsManager, Core& _core)
: frnd{frnd} : frnd{frnd}
, dialogsManager{dialogsManager} , dialogsManager{dialogsManager}
, core{_core}
{ {
} }
@ -84,10 +85,9 @@ QString FriendChatroom::getCircleName() const
void FriendChatroom::inviteToNewGroup() void FriendChatroom::inviteToNewGroup()
{ {
auto core = Core::getInstance();
const auto friendId = frnd->getId(); const auto friendId = frnd->getId();
const auto groupId = core->createGroup(); const auto groupId = core.createGroup();
core->groupInviteFriend(friendId, groupId); core.groupInviteFriend(friendId, groupId);
} }
QString FriendChatroom::getAutoAcceptDir() const QString FriendChatroom::getAutoAcceptDir() const
@ -116,7 +116,7 @@ void FriendChatroom::inviteFriend(const Group* group)
{ {
const auto friendId = frnd->getId(); const auto friendId = frnd->getId();
const auto groupId = group->getId(); const auto groupId = group->getId();
Core::getInstance()->groupInviteFriend(friendId, groupId); core.groupInviteFriend(friendId, groupId);
} }
QVector<GroupToDisplay> FriendChatroom::getGroups() const QVector<GroupToDisplay> FriendChatroom::getGroups() const

4
src/model/chatroom/friendchatroom.h

@ -25,6 +25,7 @@
#include <QString> #include <QString>
#include <QVector> #include <QVector>
class Core;
class IDialogsManager; class IDialogsManager;
class Friend; class Friend;
class Group; class Group;
@ -45,7 +46,7 @@ class FriendChatroom : public QObject, public Chatroom
{ {
Q_OBJECT Q_OBJECT
public: public:
FriendChatroom(Friend* frnd, IDialogsManager* dialogsManager); FriendChatroom(Friend* frnd, IDialogsManager* dialogsManager, Core& _core);
Contact* getContact() override; Contact* getContact() override;
@ -85,4 +86,5 @@ private:
bool active{false}; bool active{false};
Friend* frnd{nullptr}; Friend* frnd{nullptr};
IDialogsManager* dialogsManager{nullptr}; IDialogsManager* dialogsManager{nullptr};
Core& core;
}; };

6
src/widget/widget.cpp

@ -1132,11 +1132,12 @@ void Widget::onRejectCall(uint32_t friendId)
void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
{ {
assert(core != nullptr);
settings.updateFriendAddress(friendPk.toString()); settings.updateFriendAddress(friendPk.toString());
Friend* newfriend = FriendList::addFriend(friendId, friendPk); Friend* newfriend = FriendList::addFriend(friendId, friendPk);
auto dialogManager = ContentDialogManager::getInstance(); auto dialogManager = ContentDialogManager::getInstance();
auto rawChatroom = new FriendChatroom(newfriend, dialogManager); auto rawChatroom = new FriendChatroom(newfriend, dialogManager, *core);
std::shared_ptr<FriendChatroom> chatroom(rawChatroom); std::shared_ptr<FriendChatroom> chatroom(rawChatroom);
const auto compact = settings.getCompactLayout(); const auto compact = settings.getCompactLayout();
auto widget = new FriendWidget(chatroom, compact); auto widget = new FriendWidget(chatroom, compact);
@ -2048,6 +2049,8 @@ void Widget::removeGroup(const GroupId& groupId)
Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
{ {
assert(core != nullptr);
Group* g = GroupList::findGroup(groupId); Group* g = GroupList::findGroup(groupId);
if (g) { if (g) {
qWarning() << "Group already exists"; qWarning() << "Group already exists";
@ -2099,7 +2102,6 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback); connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback);
groupAlertConnections.insert(groupId, notifyReceivedConnection); groupAlertConnections.insert(groupId, notifyReceivedConnection);
assert(core != nullptr);
auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher); auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher);
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames); connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
form->setColorizedNames(settings.getEnableGroupChatsColor()); form->setColorizedNames(settings.getEnableGroupChatsColor());

Loading…
Cancel
Save