diff --git a/src/grouplist.cpp b/src/grouplist.cpp index 6d2117e38..84718177f 100644 --- a/src/grouplist.cpp +++ b/src/grouplist.cpp @@ -23,8 +23,6 @@ #include #include -QHash GroupList::groupList; -QHash GroupList::id2key; Group* GroupList::addGroup(Core& core, int groupNum, const GroupId& groupId, const QString& name, bool isAvGroupchat, const QString& selfName, FriendList& friendList) { diff --git a/src/grouplist.h b/src/grouplist.h index a0bd28980..fb1841145 100644 --- a/src/grouplist.h +++ b/src/grouplist.h @@ -33,15 +33,15 @@ class FriendList; class GroupList { public: - static Group* addGroup(Core& core, int groupNum, const GroupId& persistentGroupId, + Group* addGroup(Core& core, int groupNum, const GroupId& persistentGroupId, const QString& name, bool isAvGroupchat, const QString& selfName, FriendList& friendList); - static Group* findGroup(const GroupId& groupId); - static const GroupId& id2Key(uint32_t groupNum); - static void removeGroup(const GroupId& groupId, bool fake = false); - static QList getAllGroups(); - static void clear(); + Group* findGroup(const GroupId& groupId); + const GroupId& id2Key(uint32_t groupNum); + void removeGroup(const GroupId& groupId, bool fake = false); + QList getAllGroups(); + void clear(); private: - static QHash groupList; - static QHash id2key; + QHash groupList; + QHash id2key; }; diff --git a/src/model/chathistory.cpp b/src/model/chathistory.cpp index 9ee97bc15..7f7567894 100644 --- a/src/model/chathistory.cpp +++ b/src/model/chathistory.cpp @@ -73,12 +73,12 @@ bool handleActionPrefix(QString& content) ChatHistory::ChatHistory(Chat& chat_, History* history_, const ICoreIdHandler& coreIdHandler_, const Settings& settings_, IMessageDispatcher& messageDispatcher, - FriendList& friendList) + FriendList& friendList, GroupList& groupList) : chat(chat_) , history(history_) , settings(settings_) , coreIdHandler(coreIdHandler_) - , sessionChatLog(getInitialChatLogIdx(), coreIdHandler_, friendList) + , sessionChatLog(getInitialChatLogIdx(), coreIdHandler_, friendList, groupList) { connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this, &ChatHistory::onMessageComplete); diff --git a/src/model/chathistory.h b/src/model/chathistory.h index 85754e599..a04474e15 100644 --- a/src/model/chathistory.h +++ b/src/model/chathistory.h @@ -28,6 +28,7 @@ class Settings; class FriendList; +class GroupList; class ChatHistory : public IChatLog { @@ -35,7 +36,7 @@ class ChatHistory : public IChatLog public: ChatHistory(Chat& chat_, History* history_, const ICoreIdHandler& coreIdHandler_, const Settings& settings_, IMessageDispatcher& messageDispatcher, - FriendList& friendList); + FriendList& friendList, GroupList& groupList); const ChatLogItem& at(ChatLogIdx idx) const override; SearchResult searchForward(SearchPos startIdx, const QString& phrase, const ParameterSearch& parameter) const override; diff --git a/src/model/chatroom/friendchatroom.cpp b/src/model/chatroom/friendchatroom.cpp index 30a214002..1f9cba698 100644 --- a/src/model/chatroom/friendchatroom.cpp +++ b/src/model/chatroom/friendchatroom.cpp @@ -42,11 +42,13 @@ QString getShortName(const QString& name) } -FriendChatroom::FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_, Settings& settings_) +FriendChatroom::FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, + Core& core_, Settings& settings_, GroupList& groupList_) : frnd{frnd_} , dialogsManager{dialogsManager_} , core{core_} , settings{settings_} + , groupList{groupList_} { } @@ -123,7 +125,7 @@ void FriendChatroom::inviteFriend(const Group* group) QVector FriendChatroom::getGroups() const { QVector groups; - for (const auto group : GroupList::getAllGroups()) { + for (const auto group : groupList.getAllGroups()) { const auto name = getShortName(group->getName()); const GroupToDisplay groupToDisplay = { name, group }; groups.push_back(groupToDisplay); diff --git a/src/model/chatroom/friendchatroom.h b/src/model/chatroom/friendchatroom.h index 11e5bafc1..ce6ea1ced 100644 --- a/src/model/chatroom/friendchatroom.h +++ b/src/model/chatroom/friendchatroom.h @@ -30,6 +30,7 @@ class IDialogsManager; class Friend; class Group; class Settings; +class GroupList; struct GroupToDisplay { @@ -48,7 +49,7 @@ class FriendChatroom : public QObject, public Chatroom Q_OBJECT public: FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_, - Settings& settings_); + Settings& settings_, GroupList& groupList); Chat* getChat() override; @@ -90,4 +91,5 @@ private: IDialogsManager* dialogsManager{nullptr}; Core& core; Settings& settings; + GroupList& groupList; }; diff --git a/src/model/sessionchatlog.cpp b/src/model/sessionchatlog.cpp index 75f8df127..e31b20bcd 100644 --- a/src/model/sessionchatlog.cpp +++ b/src/model/sessionchatlog.cpp @@ -107,14 +107,14 @@ firstItemAfterDate(QDate date, const std::map& items) }); } -QString resolveToxPk(FriendList& friendList, const ToxPk& pk) +QString resolveToxPk(FriendList& friendList, GroupList& groupList, const ToxPk& pk) { Friend* f = friendList.findFriend(pk); if (f) { return f->getDisplayedName(); } - for (Group* it : GroupList::getAllGroups()) { + for (Group* it : groupList.getAllGroups()) { QString res = it->resolveToxPk(pk); if (!res.isEmpty()) { return res; @@ -125,19 +125,22 @@ QString resolveToxPk(FriendList& friendList, const ToxPk& pk) } } // namespace -SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList_) +SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList_, + GroupList& groupList_) : coreIdHandler(coreIdHandler_) , friendList{friendList_} + , groupList{groupList_} {} /** * @brief Alternate constructor that allows for an initial index to be set */ SessionChatLog::SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_, - FriendList& friendList_) + FriendList& friendList_, GroupList& groupList_) : coreIdHandler(coreIdHandler_) , nextIdx(initialIdx) , friendList{friendList_} + , groupList{groupList_} {} SessionChatLog::~SessionChatLog() = default; @@ -147,7 +150,7 @@ QString SessionChatLog::resolveSenderNameFromSender(const ToxPk& sender) bool isSelf = sender == coreIdHandler.getSelfPublicKey(); QString myNickName = coreIdHandler.getUsername().isEmpty() ? sender.toString() : coreIdHandler.getUsername(); - return isSelf ? myNickName : resolveToxPk(friendList, sender); + return isSelf ? myNickName : resolveToxPk(friendList, groupList, sender); } const ChatLogItem& SessionChatLog::at(ChatLogIdx idx) const diff --git a/src/model/sessionchatlog.h b/src/model/sessionchatlog.h index 116c21e2e..7dc09df3e 100644 --- a/src/model/sessionchatlog.h +++ b/src/model/sessionchatlog.h @@ -27,14 +27,16 @@ struct SessionChatLogMetadata; class FriendList; +class GroupList; class SessionChatLog : public IChatLog { Q_OBJECT public: - SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList); + SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList, + GroupList& groupList); SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_, - FriendList& friendList); + FriendList& friendList, GroupList& groupList); ~SessionChatLog(); const ChatLogItem& at(ChatLogIdx idx) const override; @@ -97,4 +99,5 @@ private: */ QMap outgoingMessages; FriendList& friendList; + GroupList& groupList; }; diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index 309526e95..7c1cb3bff 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -42,7 +42,7 @@ QHash CircleWidget::circleList; CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_, - FriendList& friendList_, Profile& profile_) + FriendList& friendList_, GroupList& groupList_, Profile& profile_) : CategoryWidget(isCompact(), settings_, style_, parent) , id(id_) , core{core_} @@ -50,6 +50,7 @@ CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_, , style{style_} , messageBoxManager{messageBoxManager_} , friendList{friendList_} + , groupList{groupList_} , profile{profile_} { setName(settings.getCircleName(id), false); @@ -122,7 +123,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) circleList.remove(replacedCircle); } else if (selectedItem == openAction) { ContentDialog* dialog = new ContentDialog(core, settings, style, messageBoxManager, - friendList, profile); + friendList, groupList, profile); emit newContentDialog(*dialog); for (int i = 0; i < friendOnlineLayout()->count(); ++i) { QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget(); diff --git a/src/widget/circlewidget.h b/src/widget/circlewidget.h index 4711c7c33..5d8b78381 100644 --- a/src/widget/circlewidget.h +++ b/src/widget/circlewidget.h @@ -27,6 +27,7 @@ class Settings; class Style; class IMessageBoxManager; class FriendList; +class GroupList; class Profile; class CircleWidget final : public CategoryWidget @@ -35,7 +36,7 @@ class CircleWidget final : public CategoryWidget public: CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings& settings, Style& style, IMessageBoxManager& messageboxManager, FriendList& friendList, - Profile& profile); + GroupList& groupList, Profile& profile); ~CircleWidget(); void editName(); @@ -65,5 +66,6 @@ private: Style& style; IMessageBoxManager& messageBoxManager; FriendList& friendList; + GroupList& groupList; Profile& profile; }; diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index 1b5e7c0d5..e611cb3c2 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -55,7 +55,7 @@ const QSize defaultSize(720, 400); ContentDialog::ContentDialog(const Core &core, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_, FriendList& friendList_, - Profile& profile_, QWidget* parent) + GroupList& groupList_, Profile& profile_, QWidget* parent) : ActivateDialog(style_, parent, Qt::Window) , splitter{new QSplitter(this)} , friendLayout{new FriendListLayout(this)} @@ -66,6 +66,7 @@ ContentDialog::ContentDialog(const Core &core, Settings& settings_, , style{style_} , messageBoxManager{messageBoxManager_} , friendList{friendList_} + , groupList{groupList_} , profile{profile_} { friendLayout->setMargin(0); @@ -499,7 +500,7 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event) } else if (group) { assert(event->mimeData()->hasFormat("groupId")); GroupId groupId = GroupId{event->mimeData()->data("groupId")}; - Group* contact = GroupList::findGroup(groupId); + Group* contact = groupList.findGroup(groupId); if (!contact) { return; } @@ -528,7 +529,7 @@ void ContentDialog::dropEvent(QDropEvent* event) } else if (group) { assert(event->mimeData()->hasFormat("groupId")); const GroupId groupId(event->mimeData()->data("groupId")); - Group* contact = GroupList::findGroup(groupId); + Group* contact = groupList.findGroup(groupId); if (!contact) { return; } diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 9c492f0e0..ba303258c 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -49,6 +49,7 @@ class Settings; class Style; class IMessageBoxManager; class FriendList; +class GroupList; class Profile; class ContentDialog : public ActivateDialog, public IDialogs @@ -57,7 +58,7 @@ class ContentDialog : public ActivateDialog, public IDialogs public: ContentDialog(const Core& core, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager, FriendList& friendList, - Profile& profile, QWidget* parent = nullptr); + GroupList& groupList, Profile& profile, QWidget* parent = nullptr); ~ContentDialog() override; FriendWidget* addFriend(std::shared_ptr chatroom, GenericChatForm* form); @@ -146,5 +147,6 @@ private: Style& style; IMessageBoxManager& messageBoxManager; FriendList& friendList; + GroupList& groupList; Profile& profile; }; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 47f30cf8d..50143f4ee 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -110,9 +110,11 @@ ChatForm::ChatForm(Profile& profile_, Friend* chatFriend, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_, SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager, - ContentDialogManager& contentDialogManager_, FriendList& friendList_) + ContentDialogManager& contentDialogManager_, FriendList& friendList_, + GroupList& groupList_) : GenericChatForm(profile_.getCore(), chatFriend, chatLog_, messageDispatcher_, - documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_) + documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_, + groupList_) , core{profile_.getCore()} , f(chatFriend) , isTyping{false} diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index dd81b81c5..fce66b044 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -50,6 +50,7 @@ class Profile; class IMessageBoxManager; class ContentDialogManager; class FriendList; +class GroupList; class ChatForm : public GenericChatForm { @@ -58,7 +59,7 @@ public: ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack, CameraSource& cameraSource, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager, - ContentDialogManager& contentDialogManager, FriendList& friendList); + ContentDialogManager& contentDialogManager, FriendList& friendList, GroupList& groupList); ~ChatForm() override; void setStatusMessage(const QString& newMessage); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 944d13a19..89cd43bdc 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -101,7 +101,7 @@ QString GenericChatForm::resolveToxPk(const ToxPk& pk) return f->getDisplayedName(); } - for (Group* it : GroupList::getAllGroups()) { + for (Group* it : groupList.getAllGroups()) { QString res = it->resolveToxPk(pk); if (!res.isEmpty()) { return res; @@ -140,7 +140,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog& IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack_, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager, FriendList& friendList_, - QWidget* parent_) + GroupList& groupList_, QWidget* parent_) : QWidget(parent_, Qt::Window) , core{core_} , audioInputFlag(false) @@ -151,6 +151,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog& , settings{settings_} , style{style_} , friendList{friendList_} + , groupList{groupList_} { curRow = 0; headWidget = new ChatFormHeader(settings, style); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 3c8c0d8f6..0f1456336 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -78,7 +78,7 @@ public: IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack, Settings& settings, Style& style, IMessageBoxManager& messageBoxmanager, FriendList& friendList, - QWidget* parent_ = nullptr); + GroupList& groupList, QWidget* parent_ = nullptr); ~GenericChatForm() override; void setName(const QString& newName); @@ -178,4 +178,5 @@ protected: Settings& settings; Style& style; FriendList& friendList; + GroupList& groupList; }; diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index d7b87a62b..c39097e00 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -86,9 +86,10 @@ QString editName(const QString& name) GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache_, SmileyPack& smileyPack_, Style& style_, IMessageBoxManager& messageBoxManager, - FriendList& friendList_) + FriendList& friendList_, GroupList& groupList_) : GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_, - documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_) + documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_, + groupList_) , core{core_} , group(chatGroup) , inCall(false) diff --git a/src/widget/form/groupchatform.h b/src/widget/form/groupchatform.h index 0ccd68e7a..251f441f9 100644 --- a/src/widget/form/groupchatform.h +++ b/src/widget/form/groupchatform.h @@ -40,6 +40,7 @@ class SmileyPack; class Style; class IMessageBoxManager; class FriendList; +class GroupList; class GroupChatForm : public GenericChatForm { @@ -48,7 +49,8 @@ public: GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache, SmileyPack& smileyPack, Style& style, - IMessageBoxManager& messageBoxManager, FriendList& friendList); + IMessageBoxManager& messageBoxManager, FriendList& friendList, + GroupList& groupList); ~GroupChatForm(); void peerAudioPlaying(ToxPk peerPk); diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index b9fdba108..76bd73b70 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -101,13 +101,14 @@ qint64 timeUntilTomorrow() FriendListWidget::FriendListWidget(const Core &core_, Widget* parent, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_, - FriendList& friendList_, Profile& profile_, bool groupsOnTop) + FriendList& friendList_, GroupList& groupList_, Profile& profile_, bool groupsOnTop) : QWidget(parent) , core{core_} , settings{settings_} , style{style_} , messageBoxManager{messageBoxManager_} , friendList{friendList_} + , groupList{groupList_} , profile{profile_} { int countContacts = core.getFriendList().size(); @@ -621,7 +622,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id) } CircleWidget* circleWidget = new CircleWidget(core, this, id, settings, style, - messageBoxManager, friendList, profile); + messageBoxManager, friendList, groupList, profile); emit connectCircleWidget(*circleWidget); connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged); connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget); diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index 95b43713b..c15f28608 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -42,6 +42,7 @@ class Settings; class Style; class IMessageBoxManager; class FriendList; +class GroupList; class Profile; class FriendListWidget : public QWidget @@ -50,8 +51,8 @@ class FriendListWidget : public QWidget public: using SortingMode = Settings::FriendListSortingMode; FriendListWidget(const Core& core, Widget* parent, Settings& settings, Style& style, - IMessageBoxManager& messageBoxManager, FriendList& friendList, Profile& profile, - bool groupsOnTop = true); + IMessageBoxManager& messageBoxManager, FriendList& friendList, GroupList& groupList, + Profile& profile, bool groupsOnTop = true); ~FriendListWidget(); void setMode(SortingMode mode); SortingMode getMode() const; @@ -108,5 +109,6 @@ private: Style& style; IMessageBoxManager& messageBoxManager; FriendList& friendList; + GroupList& groupList; Profile& profile; }; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 64bc142d0..6171443e3 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -161,6 +161,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou , style{style_} , messageBoxManager(new MessageBoxManager(this)) , friendList(new FriendList()) + , groupList(new GroupList()) , contentDialogManager(new ContentDialogManager(*friendList)) { installEventFilter(this); @@ -268,7 +269,7 @@ void Widget::init() sharedMessageProcessorParams.reset(new MessageProcessor::SharedParams(core->getMaxMessageSize(), coreExt->getMaxExtendedMessageSize())); chatListWidget = new FriendListWidget(*core, this, settings, style, - *messageBoxManager, *friendList, profile, settings.getGroupchatPosition()); + *messageBoxManager, *friendList, *groupList, profile, settings.getGroupchatPosition()); connect(chatListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle); connect(chatListWidget, &FriendListWidget::connectCircleWidget, this, &Widget::connectCircleWidget); @@ -620,7 +621,7 @@ Widget::~Widget() icon->hide(); } - for (Group* g : GroupList::getAllGroups()) { + for (Group* g : groupList->getAllGroups()) { removeGroup(g, true); } @@ -642,7 +643,7 @@ Widget::~Widget() delete settingsWidget; friendList->clear(); - GroupList::clear(); + groupList->clear(); delete trayMenu; delete ui; instance = nullptr; @@ -1156,7 +1157,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) settings.updateFriendAddress(friendPk.toString()); Friend* newfriend = friendList->addFriend(friendId, friendPk, settings); - auto rawChatroom = new FriendChatroom(newfriend, contentDialogManager.get(), *core, settings); + auto rawChatroom = new FriendChatroom(newfriend, contentDialogManager.get(), *core, settings, *groupList); std::shared_ptr chatroom(rawChatroom); const auto compact = settings.getCompactLayout(); auto widget = new FriendWidget(chatroom, compact, settings, style, *messageBoxManager, profile); @@ -1171,10 +1172,12 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) // ChatHistory hooks them up in a very specific order auto chatHistory = std::make_shared(*newfriend, history, *core, settings, - *friendMessageDispatcher, *friendList); + *friendMessageDispatcher, *friendList, + *groupList); auto friendForm = new ChatForm(profile, newfriend, *chatHistory, *friendMessageDispatcher, *documentCache, *smileyPack, cameraSource, - settings, style, *messageBoxManager, *contentDialogManager, *friendList); + settings, style, *messageBoxManager, *contentDialogManager, *friendList, + *groupList); connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity); friendMessageDispatchers[friendPk] = friendMessageDispatcher; @@ -1307,7 +1310,7 @@ void Widget::onFriendDisplayedNameChanged(const QString& displayed) { Friend* f = qobject_cast(sender()); const auto& friendPk = f->getPublicKey(); - for (Group* g : GroupList::getAllGroups()) { + for (Group* g : groupList->getAllGroups()) { if (g->getPeerList().contains(friendPk)) { g->updateUsername(friendPk, displayed); } @@ -1619,7 +1622,7 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, bool hasActive; QWidget* currentWindow; ContentDialog* contentDialog = contentDialogManager->getGroupDialog(groupId); - Group* g = GroupList::findGroup(groupId); + Group* g = groupList->findGroup(groupId); GroupWidget* widget = groupWidgets[groupId]; if (contentDialog != nullptr) { @@ -1768,7 +1771,7 @@ void Widget::removeFriend(Friend* f, bool fake) if (!fake) { core->removeFriend(f->getId()); // aliases aren't supported for non-friend peers in groups, revert to basic username - for (Group* g : GroupList::getAllGroups()) { + for (Group* g : groupList->getAllGroups()) { if (g->getPeerList().contains(friendPk)) { g->updateUsername(friendPk, f->getUserName()); } @@ -1831,7 +1834,7 @@ void Widget::onUpdateAvailable() ContentDialog* Widget::createContentDialog() const { ContentDialog* contentDialog = new ContentDialog(*core, settings, style, - *messageBoxManager, *friendList, profile); + *messageBoxManager, *friendList, *groupList, profile); registerContentDialog(*contentDialog); return contentDialog; @@ -1991,8 +1994,8 @@ void Widget::onGroupInviteAccepted(const GroupInvite& inviteInfo) void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction) { - const GroupId& groupId = GroupList::id2Key(groupnumber); - assert(GroupList::findGroup(groupId)); + const GroupId& groupId = groupList->id2Key(groupnumber); + assert(groupList->findGroup(groupId)); ToxPk author = core->getGroupPeerPk(groupnumber, peernumber); @@ -2001,16 +2004,16 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri void Widget::onGroupPeerlistChanged(uint32_t groupnumber) { - const GroupId& groupId = GroupList::id2Key(groupnumber); - Group* g = GroupList::findGroup(groupId); + const GroupId& groupId = groupList->id2Key(groupnumber); + Group* g = groupList->findGroup(groupId); assert(g); g->regeneratePeerList(); } void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, const QString& newName) { - const GroupId& groupId = GroupList::id2Key(groupnumber); - Group* g = GroupList::findGroup(groupId); + const GroupId& groupId = groupList->id2Key(groupnumber); + Group* g = groupList->findGroup(groupId); assert(g); const QString setName = friendList->decideNickname(peerPk, newName); @@ -2019,8 +2022,8 @@ void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, c void Widget::onGroupTitleChanged(uint32_t groupnumber, const QString& author, const QString& title) { - const GroupId& groupId = GroupList::id2Key(groupnumber); - Group* g = GroupList::findGroup(groupId); + const GroupId& groupId = groupList->id2Key(groupnumber); + Group* g = groupList->findGroup(groupId); assert(g); GroupWidget* widget = groupWidgets[groupId]; @@ -2041,8 +2044,8 @@ void Widget::titleChangedByUser(const QString& title) void Widget::onGroupPeerAudioPlaying(int groupnumber, ToxPk peerPk) { - const GroupId& groupId = GroupList::id2Key(groupnumber); - assert(GroupList::findGroup(groupId)); + const GroupId& groupId = groupList->id2Key(groupnumber); + assert(groupList->findGroup(groupId)); auto form = groupChatForms[groupId].data(); form->peerAudioPlaying(peerPk); @@ -2069,7 +2072,7 @@ void Widget::removeGroup(Group* g, bool fake) onAddClicked(); } - GroupList::removeGroup(groupId, fake); + groupList->removeGroup(groupId, fake); ContentDialog* contentDialog = contentDialogManager->getGroupDialog(groupId); if (contentDialog != nullptr) { contentDialog->removeGroup(groupId); @@ -2098,14 +2101,14 @@ void Widget::removeGroup(Group* g, bool fake) void Widget::removeGroup(const GroupId& groupId) { - removeGroup(GroupList::findGroup(groupId)); + removeGroup(groupList->findGroup(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) { qWarning() << "Group already exists"; return g; @@ -2114,7 +2117,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) const auto groupName = tr("Groupchat #%1").arg(groupnumber); const bool enabled = core->getGroupAvEnabled(groupnumber); Group* newgroup = - GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername(), + groupList->addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername(), *friendList); assert(newgroup); @@ -2141,7 +2144,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) // ChatHistory hooks them up in a very specific order auto chatHistory = std::make_shared(*newgroup, history, *core, settings, - *messageDispatcher, *friendList); + *messageDispatcher, *friendList, *groupList); auto notifyReceivedCallback = [this, groupId](const ToxPk& author, const Message& message) { auto isTargeted = std::any_of(message.metadata.begin(), message.metadata.end(), @@ -2157,7 +2160,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) groupAlertConnections.insert(groupId, notifyReceivedConnection); auto form = new GroupChatForm(*core, newgroup, *chatHistory, *messageDispatcher, - settings, *documentCache, *smileyPack, style, *messageBoxManager, *friendList); + settings, *documentCache, *smileyPack, style, *messageBoxManager, *friendList, *groupList); connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames); form->setColorizedNames(settings.getEnableGroupChatsColor()); groupMessageDispatchers[groupId] = messageDispatcher; @@ -2355,8 +2358,8 @@ void Widget::setStatusBusy() void Widget::onGroupSendFailed(uint32_t groupnumber) { - const auto& groupId = GroupList::id2Key(groupnumber); - assert(GroupList::findGroup(groupId)); + const auto& groupId = groupList->id2Key(groupnumber); + assert(groupList->findGroup(groupId)); const auto curTime = QDateTime::currentDateTime(); auto form = groupChatForms[groupId].data(); @@ -2706,7 +2709,7 @@ void Widget::focusChatInput() void Widget::refreshPeerListsLocal(const QString& username) { - for (Group* g : GroupList::getAllGroups()) { + for (Group* g : groupList->getAllGroups()) { g->updateUsername(core->getSelfPublicKey(), username); } } diff --git a/src/widget/widget.h b/src/widget/widget.h index 913fcfd33..6fcf64179 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -37,7 +37,6 @@ #include "src/core/toxpk.h" #include "src/model/friendmessagedispatcher.h" #include "src/model/groupmessagedispatcher.h" -#include "src/friendlist.h" #if DESKTOP_NOTIFICATIONS #include "src/model/notificationgenerator.h" #include "src/platform/desktop_notifications/desktopnotify.h" @@ -89,6 +88,8 @@ class CameraSource; class Style; class IMessageBoxManager; class ContentDialogManager; +class FriendList; +class GroupList; class Widget final : public QMainWindow { @@ -394,6 +395,7 @@ private: Style& style; IMessageBoxManager* messageBoxManager = nullptr; // freed by Qt on destruction std::unique_ptr friendList; + std::unique_ptr groupList; std::unique_ptr contentDialogManager; }; diff --git a/test/model/sessionchatlog_test.cpp b/test/model/sessionchatlog_test.cpp index a5354111b..54d46b144 100644 --- a/test/model/sessionchatlog_test.cpp +++ b/test/model/sessionchatlog_test.cpp @@ -73,6 +73,7 @@ private: MockCoreIdHandler idHandler; std::unique_ptr chatLog; std::unique_ptr friendList; + std::unique_ptr groupList; }; /** @@ -81,7 +82,9 @@ private: void TestSessionChatLog::init() { friendList = std::unique_ptr(new FriendList()); - chatLog = std::unique_ptr(new SessionChatLog(idHandler, *friendList)); + groupList = std::unique_ptr(new GroupList()); + chatLog = std::unique_ptr(new SessionChatLog(idHandler, *friendList, + *groupList)); } /**