mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Inject DialogsManager in chatrooms
This commit is contained in:
parent
ac36ed8180
commit
0b9b538601
|
@ -1,5 +1,6 @@
|
|||
#include "src/grouplist.h"
|
||||
#include "src/model/chatroom/friendchatroom.h"
|
||||
#include "src/model/dialogs/idialogsmanager.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/model/group.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
@ -21,8 +22,9 @@ QString getShortName(const QString& name)
|
|||
|
||||
}
|
||||
|
||||
FriendChatroom::FriendChatroom(Friend* frnd)
|
||||
FriendChatroom::FriendChatroom(Friend* frnd, IDialogsManager* dialogsManager)
|
||||
: frnd{frnd}
|
||||
, dialogsManager{dialogsManager}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -141,3 +143,31 @@ void FriendChatroom::resetEventFlags()
|
|||
{
|
||||
frnd->setEventFlag(false);
|
||||
}
|
||||
|
||||
bool FriendChatroom::possibleToOpenInNewWindow() const
|
||||
{
|
||||
const auto friendPk = frnd->getPublicKey();
|
||||
const auto dialogs = dialogsManager->getFriendDialogs(friendPk);
|
||||
return !dialogs || dialogs->chatroomCount() > 1;
|
||||
}
|
||||
|
||||
bool FriendChatroom::canBeRemovedFromWindow() const
|
||||
{
|
||||
const auto friendPk = frnd->getPublicKey();
|
||||
const auto dialogs = dialogsManager->getFriendDialogs(friendPk);
|
||||
return dialogs && dialogs->hasContact(friendPk);
|
||||
}
|
||||
|
||||
bool FriendChatroom::friendCanBeRemoved() const
|
||||
{
|
||||
const auto friendPk = frnd->getPublicKey();
|
||||
const auto dialogs = dialogsManager->getFriendDialogs(friendPk);
|
||||
return !dialogs || !dialogs->hasContact(friendPk);
|
||||
}
|
||||
|
||||
void FriendChatroom::removeFriendFromDialogs()
|
||||
{
|
||||
const auto friendPk = frnd->getPublicKey();
|
||||
auto dialogs = dialogsManager->getFriendDialogs(friendPk);
|
||||
dialogs->removeFriend(friendPk);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
class IDialogsManager;
|
||||
class Friend;
|
||||
class Group;
|
||||
|
||||
|
@ -45,7 +46,7 @@ class FriendChatroom : public QObject, public Chatroom
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FriendChatroom(Friend* frnd);
|
||||
FriendChatroom(Friend* frnd, IDialogsManager* dialogsManager);
|
||||
|
||||
Contact* getContact() override;
|
||||
|
||||
|
@ -73,12 +74,18 @@ public slots:
|
|||
|
||||
void resetEventFlags();
|
||||
|
||||
bool possibleToOpenInNewWindow() const;
|
||||
bool canBeRemovedFromWindow() const;
|
||||
bool friendCanBeRemoved() const;
|
||||
void removeFriendFromDialogs();
|
||||
|
||||
signals:
|
||||
void activeChanged(bool activated);
|
||||
|
||||
private:
|
||||
bool active{false};
|
||||
Friend* frnd{nullptr};
|
||||
IDialogsManager* dialogsManager{nullptr};
|
||||
};
|
||||
|
||||
#endif // FRIEND_H
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
#include "src/core/core.h"
|
||||
#include "src/core/toxpk.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/model/dialogs/idialogsmanager.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/model/group.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
||||
GroupChatroom::GroupChatroom(Group* group)
|
||||
GroupChatroom::GroupChatroom(Group* group, IDialogsManager* dialogsManager)
|
||||
: group{group}
|
||||
, dialogsManager{dialogsManager}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,3 +51,24 @@ void GroupChatroom::inviteFriend(const ToxPk& pk)
|
|||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
}
|
||||
}
|
||||
|
||||
bool GroupChatroom::possibleToOpenInNewWindow() const
|
||||
{
|
||||
const auto groupId = group->getPersistentId();
|
||||
const auto dialogs = dialogsManager->getGroupDialogs(groupId);
|
||||
return !dialogs || dialogs->chatroomCount() > 1;
|
||||
}
|
||||
|
||||
bool GroupChatroom::canBeRemovedFromWindow() const
|
||||
{
|
||||
const auto groupId = group->getPersistentId();
|
||||
const auto dialogs = dialogsManager->getGroupDialogs(groupId);
|
||||
return dialogs && dialogs->hasContact(groupId);
|
||||
}
|
||||
|
||||
void GroupChatroom::removeGroupFromDialogs()
|
||||
{
|
||||
const auto groupId = group->getPersistentId();
|
||||
auto dialogs = dialogsManager->getGroupDialogs(groupId);
|
||||
dialogs->removeGroup(groupId);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
class IDialogsManager;
|
||||
class Group;
|
||||
class ToxPk;
|
||||
|
||||
|
@ -31,7 +32,7 @@ class GroupChatroom : public QObject, public Chatroom
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GroupChatroom(Group* group);
|
||||
GroupChatroom(Group* group, IDialogsManager* dialogsManager);
|
||||
|
||||
Contact* getContact() override;
|
||||
|
||||
|
@ -42,8 +43,14 @@ public:
|
|||
|
||||
bool friendExists(const ToxPk& pk);
|
||||
void inviteFriend(const ToxPk& pk);
|
||||
|
||||
bool possibleToOpenInNewWindow() const;
|
||||
bool canBeRemovedFromWindow() const;
|
||||
void removeGroupFromDialogs();
|
||||
|
||||
private:
|
||||
Group* group{nullptr};
|
||||
IDialogsManager* dialogsManager{nullptr};
|
||||
};
|
||||
|
||||
#endif /* GROUP_CHATROOM_H */
|
||||
|
|
|
@ -1000,7 +1000,9 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
settings.updateFriendAddress(friendPk.toString());
|
||||
|
||||
Friend* newfriend = FriendList::addFriend(friendId, friendPk);
|
||||
std::shared_ptr<FriendChatroom> chatroom(new FriendChatroom(newfriend));
|
||||
auto dialogManager = ContentDialogManager::getInstance();
|
||||
auto rawChatroom = new FriendChatroom(newfriend, dialogManager);
|
||||
std::shared_ptr<FriendChatroom> chatroom(rawChatroom);
|
||||
const auto compact = settings.getCompactLayout();
|
||||
auto widget = new FriendWidget(chatroom, compact);
|
||||
auto history = Nexus::getProfile()->getHistory();
|
||||
|
@ -1917,10 +1919,13 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
|||
}
|
||||
|
||||
const auto groupName = tr("Groupchat #%1").arg(groupnumber);
|
||||
bool enabled = core->getGroupAvEnabled(groupnumber);
|
||||
const bool enabled = core->getGroupAvEnabled(groupnumber);
|
||||
Group* newgroup =
|
||||
GroupList::addGroup(groupnumber, groupId, groupName, enabled, core->getUsername());
|
||||
std::shared_ptr<GroupChatroom> chatroom(new GroupChatroom(newgroup));
|
||||
auto dialogManager = ContentDialogManager::getInstance();
|
||||
auto rawChatroom = new GroupChatroom(newgroup, dialogManager);
|
||||
std::shared_ptr<GroupChatroom> chatroom(rawChatroom);
|
||||
|
||||
const auto compact = settings.getCompactLayout();
|
||||
auto widget = new GroupWidget(chatroom, compact);
|
||||
auto form = new GroupChatForm(newgroup);
|
||||
|
|
Loading…
Reference in New Issue
Block a user