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

4
src/model/chatroom/friendchatroom.h

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

6
src/widget/widget.cpp

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

Loading…
Cancel
Save