Browse Source

refactor: Move GroupList global state into class

pull/6613/head
Anthony Bilinski 3 years ago
parent
commit
1e4eed76b5
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 2
      src/grouplist.cpp
  2. 16
      src/grouplist.h
  3. 4
      src/model/chathistory.cpp
  4. 3
      src/model/chathistory.h
  5. 6
      src/model/chatroom/friendchatroom.cpp
  6. 4
      src/model/chatroom/friendchatroom.h
  7. 13
      src/model/sessionchatlog.cpp
  8. 7
      src/model/sessionchatlog.h
  9. 5
      src/widget/circlewidget.cpp
  10. 4
      src/widget/circlewidget.h
  11. 7
      src/widget/contentdialog.cpp
  12. 4
      src/widget/contentdialog.h
  13. 6
      src/widget/form/chatform.cpp
  14. 3
      src/widget/form/chatform.h
  15. 5
      src/widget/form/genericchatform.cpp
  16. 3
      src/widget/form/genericchatform.h
  17. 5
      src/widget/form/groupchatform.cpp
  18. 4
      src/widget/form/groupchatform.h
  19. 5
      src/widget/friendlistwidget.cpp
  20. 6
      src/widget/friendlistwidget.h
  21. 61
      src/widget/widget.cpp
  22. 4
      src/widget/widget.h
  23. 5
      test/model/sessionchatlog_test.cpp

2
src/grouplist.cpp

@ -23,8 +23,6 @@
#include <QDebug> #include <QDebug>
#include <QHash> #include <QHash>
QHash<const GroupId, Group*> GroupList::groupList;
QHash<uint32_t, GroupId> GroupList::id2key;
Group* GroupList::addGroup(Core& core, int groupNum, const GroupId& groupId, const QString& name, bool isAvGroupchat, Group* GroupList::addGroup(Core& core, int groupNum, const GroupId& groupId, const QString& name, bool isAvGroupchat,
const QString& selfName, FriendList& friendList) const QString& selfName, FriendList& friendList)
{ {

16
src/grouplist.h

@ -33,15 +33,15 @@ class FriendList;
class GroupList class GroupList
{ {
public: 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); const QString& name, bool isAvGroupchat, const QString& selfName, FriendList& friendList);
static Group* findGroup(const GroupId& groupId); Group* findGroup(const GroupId& groupId);
static const GroupId& id2Key(uint32_t groupNum); const GroupId& id2Key(uint32_t groupNum);
static void removeGroup(const GroupId& groupId, bool fake = false); void removeGroup(const GroupId& groupId, bool fake = false);
static QList<Group*> getAllGroups(); QList<Group*> getAllGroups();
static void clear(); void clear();
private: private:
static QHash<const GroupId, Group*> groupList; QHash<const GroupId, Group*> groupList;
static QHash<uint32_t, GroupId> id2key; QHash<uint32_t, GroupId> id2key;
}; };

4
src/model/chathistory.cpp

@ -73,12 +73,12 @@ bool handleActionPrefix(QString& content)
ChatHistory::ChatHistory(Chat& chat_, History* history_, const ICoreIdHandler& coreIdHandler_, ChatHistory::ChatHistory(Chat& chat_, History* history_, const ICoreIdHandler& coreIdHandler_,
const Settings& settings_, IMessageDispatcher& messageDispatcher, const Settings& settings_, IMessageDispatcher& messageDispatcher,
FriendList& friendList) FriendList& friendList, GroupList& groupList)
: chat(chat_) : chat(chat_)
, history(history_) , history(history_)
, settings(settings_) , settings(settings_)
, coreIdHandler(coreIdHandler_) , coreIdHandler(coreIdHandler_)
, sessionChatLog(getInitialChatLogIdx(), coreIdHandler_, friendList) , sessionChatLog(getInitialChatLogIdx(), coreIdHandler_, friendList, groupList)
{ {
connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this, connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this,
&ChatHistory::onMessageComplete); &ChatHistory::onMessageComplete);

3
src/model/chathistory.h

@ -28,6 +28,7 @@
class Settings; class Settings;
class FriendList; class FriendList;
class GroupList;
class ChatHistory : public IChatLog class ChatHistory : public IChatLog
{ {
@ -35,7 +36,7 @@ class ChatHistory : public IChatLog
public: public:
ChatHistory(Chat& chat_, History* history_, const ICoreIdHandler& coreIdHandler_, ChatHistory(Chat& chat_, History* history_, const ICoreIdHandler& coreIdHandler_,
const Settings& settings_, IMessageDispatcher& messageDispatcher, const Settings& settings_, IMessageDispatcher& messageDispatcher,
FriendList& friendList); FriendList& friendList, GroupList& groupList);
const ChatLogItem& at(ChatLogIdx idx) const override; const ChatLogItem& at(ChatLogIdx idx) const override;
SearchResult searchForward(SearchPos startIdx, const QString& phrase, SearchResult searchForward(SearchPos startIdx, const QString& phrase,
const ParameterSearch& parameter) const override; const ParameterSearch& parameter) const override;

6
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_} : frnd{frnd_}
, dialogsManager{dialogsManager_} , dialogsManager{dialogsManager_}
, core{core_} , core{core_}
, settings{settings_} , settings{settings_}
, groupList{groupList_}
{ {
} }
@ -123,7 +125,7 @@ void FriendChatroom::inviteFriend(const Group* group)
QVector<GroupToDisplay> FriendChatroom::getGroups() const QVector<GroupToDisplay> FriendChatroom::getGroups() const
{ {
QVector<GroupToDisplay> groups; QVector<GroupToDisplay> groups;
for (const auto group : GroupList::getAllGroups()) { for (const auto group : groupList.getAllGroups()) {
const auto name = getShortName(group->getName()); const auto name = getShortName(group->getName());
const GroupToDisplay groupToDisplay = { name, group }; const GroupToDisplay groupToDisplay = { name, group };
groups.push_back(groupToDisplay); groups.push_back(groupToDisplay);

4
src/model/chatroom/friendchatroom.h

@ -30,6 +30,7 @@ class IDialogsManager;
class Friend; class Friend;
class Group; class Group;
class Settings; class Settings;
class GroupList;
struct GroupToDisplay struct GroupToDisplay
{ {
@ -48,7 +49,7 @@ class FriendChatroom : public QObject, public Chatroom
Q_OBJECT Q_OBJECT
public: public:
FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_, FriendChatroom(Friend* frnd_, IDialogsManager* dialogsManager_, Core& core_,
Settings& settings_); Settings& settings_, GroupList& groupList);
Chat* getChat() override; Chat* getChat() override;
@ -90,4 +91,5 @@ private:
IDialogsManager* dialogsManager{nullptr}; IDialogsManager* dialogsManager{nullptr};
Core& core; Core& core;
Settings& settings; Settings& settings;
GroupList& groupList;
}; };

13
src/model/sessionchatlog.cpp

@ -107,14 +107,14 @@ firstItemAfterDate(QDate date, const std::map<ChatLogIdx, ChatLogItem>& items)
}); });
} }
QString resolveToxPk(FriendList& friendList, const ToxPk& pk) QString resolveToxPk(FriendList& friendList, GroupList& groupList, const ToxPk& pk)
{ {
Friend* f = friendList.findFriend(pk); Friend* f = friendList.findFriend(pk);
if (f) { if (f) {
return f->getDisplayedName(); return f->getDisplayedName();
} }
for (Group* it : GroupList::getAllGroups()) { for (Group* it : groupList.getAllGroups()) {
QString res = it->resolveToxPk(pk); QString res = it->resolveToxPk(pk);
if (!res.isEmpty()) { if (!res.isEmpty()) {
return res; return res;
@ -125,19 +125,22 @@ QString resolveToxPk(FriendList& friendList, const ToxPk& pk)
} }
} // namespace } // namespace
SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList_) SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList_,
GroupList& groupList_)
: coreIdHandler(coreIdHandler_) : coreIdHandler(coreIdHandler_)
, friendList{friendList_} , friendList{friendList_}
, groupList{groupList_}
{} {}
/** /**
* @brief Alternate constructor that allows for an initial index to be set * @brief Alternate constructor that allows for an initial index to be set
*/ */
SessionChatLog::SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_, SessionChatLog::SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_,
FriendList& friendList_) FriendList& friendList_, GroupList& groupList_)
: coreIdHandler(coreIdHandler_) : coreIdHandler(coreIdHandler_)
, nextIdx(initialIdx) , nextIdx(initialIdx)
, friendList{friendList_} , friendList{friendList_}
, groupList{groupList_}
{} {}
SessionChatLog::~SessionChatLog() = default; SessionChatLog::~SessionChatLog() = default;
@ -147,7 +150,7 @@ QString SessionChatLog::resolveSenderNameFromSender(const ToxPk& sender)
bool isSelf = sender == coreIdHandler.getSelfPublicKey(); bool isSelf = sender == coreIdHandler.getSelfPublicKey();
QString myNickName = coreIdHandler.getUsername().isEmpty() ? sender.toString() : coreIdHandler.getUsername(); 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 const ChatLogItem& SessionChatLog::at(ChatLogIdx idx) const

7
src/model/sessionchatlog.h

@ -27,14 +27,16 @@
struct SessionChatLogMetadata; struct SessionChatLogMetadata;
class FriendList; class FriendList;
class GroupList;
class SessionChatLog : public IChatLog class SessionChatLog : public IChatLog
{ {
Q_OBJECT Q_OBJECT
public: public:
SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList); SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList,
GroupList& groupList);
SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_, SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_,
FriendList& friendList); FriendList& friendList, GroupList& groupList);
~SessionChatLog(); ~SessionChatLog();
const ChatLogItem& at(ChatLogIdx idx) const override; const ChatLogItem& at(ChatLogIdx idx) const override;
@ -97,4 +99,5 @@ private:
*/ */
QMap<DispatchedMessageId, ChatLogIdx> outgoingMessages; QMap<DispatchedMessageId, ChatLogIdx> outgoingMessages;
FriendList& friendList; FriendList& friendList;
GroupList& groupList;
}; };

5
src/widget/circlewidget.cpp

@ -42,7 +42,7 @@ QHash<int, CircleWidget*> CircleWidget::circleList;
CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_, CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_,
Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_,
FriendList& friendList_, Profile& profile_) FriendList& friendList_, GroupList& groupList_, Profile& profile_)
: CategoryWidget(isCompact(), settings_, style_, parent) : CategoryWidget(isCompact(), settings_, style_, parent)
, id(id_) , id(id_)
, core{core_} , core{core_}
@ -50,6 +50,7 @@ CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_,
, style{style_} , style{style_}
, messageBoxManager{messageBoxManager_} , messageBoxManager{messageBoxManager_}
, friendList{friendList_} , friendList{friendList_}
, groupList{groupList_}
, profile{profile_} , profile{profile_}
{ {
setName(settings.getCircleName(id), false); setName(settings.getCircleName(id), false);
@ -122,7 +123,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
circleList.remove(replacedCircle); circleList.remove(replacedCircle);
} else if (selectedItem == openAction) { } else if (selectedItem == openAction) {
ContentDialog* dialog = new ContentDialog(core, settings, style, messageBoxManager, ContentDialog* dialog = new ContentDialog(core, settings, style, messageBoxManager,
friendList, profile); friendList, groupList, profile);
emit newContentDialog(*dialog); emit newContentDialog(*dialog);
for (int i = 0; i < friendOnlineLayout()->count(); ++i) { for (int i = 0; i < friendOnlineLayout()->count(); ++i) {
QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget(); QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget();

4
src/widget/circlewidget.h

@ -27,6 +27,7 @@ class Settings;
class Style; class Style;
class IMessageBoxManager; class IMessageBoxManager;
class FriendList; class FriendList;
class GroupList;
class Profile; class Profile;
class CircleWidget final : public CategoryWidget class CircleWidget final : public CategoryWidget
@ -35,7 +36,7 @@ class CircleWidget final : public CategoryWidget
public: public:
CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings& settings, CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings& settings,
Style& style, IMessageBoxManager& messageboxManager, FriendList& friendList, Style& style, IMessageBoxManager& messageboxManager, FriendList& friendList,
Profile& profile); GroupList& groupList, Profile& profile);
~CircleWidget(); ~CircleWidget();
void editName(); void editName();
@ -65,5 +66,6 @@ private:
Style& style; Style& style;
IMessageBoxManager& messageBoxManager; IMessageBoxManager& messageBoxManager;
FriendList& friendList; FriendList& friendList;
GroupList& groupList;
Profile& profile; Profile& profile;
}; };

7
src/widget/contentdialog.cpp

@ -55,7 +55,7 @@ const QSize defaultSize(720, 400);
ContentDialog::ContentDialog(const Core &core, Settings& settings_, ContentDialog::ContentDialog(const Core &core, Settings& settings_,
Style& style_, IMessageBoxManager& messageBoxManager_, FriendList& friendList_, Style& style_, IMessageBoxManager& messageBoxManager_, FriendList& friendList_,
Profile& profile_, QWidget* parent) GroupList& groupList_, Profile& profile_, QWidget* parent)
: ActivateDialog(style_, parent, Qt::Window) : ActivateDialog(style_, parent, Qt::Window)
, splitter{new QSplitter(this)} , splitter{new QSplitter(this)}
, friendLayout{new FriendListLayout(this)} , friendLayout{new FriendListLayout(this)}
@ -66,6 +66,7 @@ ContentDialog::ContentDialog(const Core &core, Settings& settings_,
, style{style_} , style{style_}
, messageBoxManager{messageBoxManager_} , messageBoxManager{messageBoxManager_}
, friendList{friendList_} , friendList{friendList_}
, groupList{groupList_}
, profile{profile_} , profile{profile_}
{ {
friendLayout->setMargin(0); friendLayout->setMargin(0);
@ -499,7 +500,7 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event)
} else if (group) { } else if (group) {
assert(event->mimeData()->hasFormat("groupId")); assert(event->mimeData()->hasFormat("groupId"));
GroupId groupId = GroupId{event->mimeData()->data("groupId")}; GroupId groupId = GroupId{event->mimeData()->data("groupId")};
Group* contact = GroupList::findGroup(groupId); Group* contact = groupList.findGroup(groupId);
if (!contact) { if (!contact) {
return; return;
} }
@ -528,7 +529,7 @@ void ContentDialog::dropEvent(QDropEvent* event)
} else if (group) { } else if (group) {
assert(event->mimeData()->hasFormat("groupId")); assert(event->mimeData()->hasFormat("groupId"));
const GroupId groupId(event->mimeData()->data("groupId")); const GroupId groupId(event->mimeData()->data("groupId"));
Group* contact = GroupList::findGroup(groupId); Group* contact = groupList.findGroup(groupId);
if (!contact) { if (!contact) {
return; return;
} }

4
src/widget/contentdialog.h

@ -49,6 +49,7 @@ class Settings;
class Style; class Style;
class IMessageBoxManager; class IMessageBoxManager;
class FriendList; class FriendList;
class GroupList;
class Profile; class Profile;
class ContentDialog : public ActivateDialog, public IDialogs class ContentDialog : public ActivateDialog, public IDialogs
@ -57,7 +58,7 @@ class ContentDialog : public ActivateDialog, public IDialogs
public: public:
ContentDialog(const Core& core, Settings& settings, Style& style, ContentDialog(const Core& core, Settings& settings, Style& style,
IMessageBoxManager& messageBoxManager, FriendList& friendList, IMessageBoxManager& messageBoxManager, FriendList& friendList,
Profile& profile, QWidget* parent = nullptr); GroupList& groupList, Profile& profile, QWidget* parent = nullptr);
~ContentDialog() override; ~ContentDialog() override;
FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form); FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
@ -146,5 +147,6 @@ private:
Style& style; Style& style;
IMessageBoxManager& messageBoxManager; IMessageBoxManager& messageBoxManager;
FriendList& friendList; FriendList& friendList;
GroupList& groupList;
Profile& profile; Profile& profile;
}; };

6
src/widget/form/chatform.cpp

@ -110,9 +110,11 @@ ChatForm::ChatForm(Profile& profile_, Friend* chatFriend, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_, IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_,
SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_, SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_,
Style& style_, IMessageBoxManager& messageBoxManager, Style& style_, IMessageBoxManager& messageBoxManager,
ContentDialogManager& contentDialogManager_, FriendList& friendList_) ContentDialogManager& contentDialogManager_, FriendList& friendList_,
GroupList& groupList_)
: GenericChatForm(profile_.getCore(), chatFriend, chatLog_, messageDispatcher_, : GenericChatForm(profile_.getCore(), chatFriend, chatLog_, messageDispatcher_,
documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_) documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_,
groupList_)
, core{profile_.getCore()} , core{profile_.getCore()}
, f(chatFriend) , f(chatFriend)
, isTyping{false} , isTyping{false}

3
src/widget/form/chatform.h

@ -50,6 +50,7 @@ class Profile;
class IMessageBoxManager; class IMessageBoxManager;
class ContentDialogManager; class ContentDialogManager;
class FriendList; class FriendList;
class GroupList;
class ChatForm : public GenericChatForm class ChatForm : public GenericChatForm
{ {
@ -58,7 +59,7 @@ public:
ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_, ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack, IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack,
CameraSource& cameraSource, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager, CameraSource& cameraSource, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager,
ContentDialogManager& contentDialogManager, FriendList& friendList); ContentDialogManager& contentDialogManager, FriendList& friendList, GroupList& groupList);
~ChatForm() override; ~ChatForm() override;
void setStatusMessage(const QString& newMessage); void setStatusMessage(const QString& newMessage);

5
src/widget/form/genericchatform.cpp

@ -101,7 +101,7 @@ QString GenericChatForm::resolveToxPk(const ToxPk& pk)
return f->getDisplayedName(); return f->getDisplayedName();
} }
for (Group* it : GroupList::getAllGroups()) { for (Group* it : groupList.getAllGroups()) {
QString res = it->resolveToxPk(pk); QString res = it->resolveToxPk(pk);
if (!res.isEmpty()) { if (!res.isEmpty()) {
return res; return res;
@ -140,7 +140,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog&
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
SmileyPack& smileyPack_, Settings& settings_, Style& style_, SmileyPack& smileyPack_, Settings& settings_, Style& style_,
IMessageBoxManager& messageBoxManager, FriendList& friendList_, IMessageBoxManager& messageBoxManager, FriendList& friendList_,
QWidget* parent_) GroupList& groupList_, QWidget* parent_)
: QWidget(parent_, Qt::Window) : QWidget(parent_, Qt::Window)
, core{core_} , core{core_}
, audioInputFlag(false) , audioInputFlag(false)
@ -151,6 +151,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog&
, settings{settings_} , settings{settings_}
, style{style_} , style{style_}
, friendList{friendList_} , friendList{friendList_}
, groupList{groupList_}
{ {
curRow = 0; curRow = 0;
headWidget = new ChatFormHeader(settings, style); headWidget = new ChatFormHeader(settings, style);

3
src/widget/form/genericchatform.h

@ -78,7 +78,7 @@ public:
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
SmileyPack& smileyPack, Settings& settings, Style& style, SmileyPack& smileyPack, Settings& settings, Style& style,
IMessageBoxManager& messageBoxmanager, FriendList& friendList, IMessageBoxManager& messageBoxmanager, FriendList& friendList,
QWidget* parent_ = nullptr); GroupList& groupList, QWidget* parent_ = nullptr);
~GenericChatForm() override; ~GenericChatForm() override;
void setName(const QString& newName); void setName(const QString& newName);
@ -178,4 +178,5 @@ protected:
Settings& settings; Settings& settings;
Style& style; Style& style;
FriendList& friendList; FriendList& friendList;
GroupList& groupList;
}; };

5
src/widget/form/groupchatform.cpp

@ -86,9 +86,10 @@ QString editName(const QString& name)
GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_, GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache_, IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache_,
SmileyPack& smileyPack_, Style& style_, IMessageBoxManager& messageBoxManager, SmileyPack& smileyPack_, Style& style_, IMessageBoxManager& messageBoxManager,
FriendList& friendList_) FriendList& friendList_, GroupList& groupList_)
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_, : GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_,
documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_) documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_,
groupList_)
, core{core_} , core{core_}
, group(chatGroup) , group(chatGroup)
, inCall(false) , inCall(false)

4
src/widget/form/groupchatform.h

@ -40,6 +40,7 @@ class SmileyPack;
class Style; class Style;
class IMessageBoxManager; class IMessageBoxManager;
class FriendList; class FriendList;
class GroupList;
class GroupChatForm : public GenericChatForm class GroupChatForm : public GenericChatForm
{ {
@ -48,7 +49,8 @@ public:
GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_, GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, Settings& settings_, IMessageDispatcher& messageDispatcher_, Settings& settings_,
DocumentCache& documentCache, SmileyPack& smileyPack, Style& style, DocumentCache& documentCache, SmileyPack& smileyPack, Style& style,
IMessageBoxManager& messageBoxManager, FriendList& friendList); IMessageBoxManager& messageBoxManager, FriendList& friendList,
GroupList& groupList);
~GroupChatForm(); ~GroupChatForm();
void peerAudioPlaying(ToxPk peerPk); void peerAudioPlaying(ToxPk peerPk);

5
src/widget/friendlistwidget.cpp

@ -101,13 +101,14 @@ qint64 timeUntilTomorrow()
FriendListWidget::FriendListWidget(const Core &core_, Widget* parent, FriendListWidget::FriendListWidget(const Core &core_, Widget* parent,
Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_,
FriendList& friendList_, Profile& profile_, bool groupsOnTop) FriendList& friendList_, GroupList& groupList_, Profile& profile_, bool groupsOnTop)
: QWidget(parent) : QWidget(parent)
, core{core_} , core{core_}
, settings{settings_} , settings{settings_}
, style{style_} , style{style_}
, messageBoxManager{messageBoxManager_} , messageBoxManager{messageBoxManager_}
, friendList{friendList_} , friendList{friendList_}
, groupList{groupList_}
, profile{profile_} , profile{profile_}
{ {
int countContacts = core.getFriendList().size(); int countContacts = core.getFriendList().size();
@ -621,7 +622,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
} }
CircleWidget* circleWidget = new CircleWidget(core, this, id, settings, style, CircleWidget* circleWidget = new CircleWidget(core, this, id, settings, style,
messageBoxManager, friendList, profile); messageBoxManager, friendList, groupList, profile);
emit connectCircleWidget(*circleWidget); emit connectCircleWidget(*circleWidget);
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged); connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget); connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);

6
src/widget/friendlistwidget.h

@ -42,6 +42,7 @@ class Settings;
class Style; class Style;
class IMessageBoxManager; class IMessageBoxManager;
class FriendList; class FriendList;
class GroupList;
class Profile; class Profile;
class FriendListWidget : public QWidget class FriendListWidget : public QWidget
@ -50,8 +51,8 @@ class FriendListWidget : public QWidget
public: public:
using SortingMode = Settings::FriendListSortingMode; using SortingMode = Settings::FriendListSortingMode;
FriendListWidget(const Core& core, Widget* parent, Settings& settings, Style& style, FriendListWidget(const Core& core, Widget* parent, Settings& settings, Style& style,
IMessageBoxManager& messageBoxManager, FriendList& friendList, Profile& profile, IMessageBoxManager& messageBoxManager, FriendList& friendList, GroupList& groupList,
bool groupsOnTop = true); Profile& profile, bool groupsOnTop = true);
~FriendListWidget(); ~FriendListWidget();
void setMode(SortingMode mode); void setMode(SortingMode mode);
SortingMode getMode() const; SortingMode getMode() const;
@ -108,5 +109,6 @@ private:
Style& style; Style& style;
IMessageBoxManager& messageBoxManager; IMessageBoxManager& messageBoxManager;
FriendList& friendList; FriendList& friendList;
GroupList& groupList;
Profile& profile; Profile& profile;
}; };

61
src/widget/widget.cpp

@ -161,6 +161,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou
, style{style_} , style{style_}
, messageBoxManager(new MessageBoxManager(this)) , messageBoxManager(new MessageBoxManager(this))
, friendList(new FriendList()) , friendList(new FriendList())
, groupList(new GroupList())
, contentDialogManager(new ContentDialogManager(*friendList)) , contentDialogManager(new ContentDialogManager(*friendList))
{ {
installEventFilter(this); installEventFilter(this);
@ -268,7 +269,7 @@ void Widget::init()
sharedMessageProcessorParams.reset(new MessageProcessor::SharedParams(core->getMaxMessageSize(), coreExt->getMaxExtendedMessageSize())); sharedMessageProcessorParams.reset(new MessageProcessor::SharedParams(core->getMaxMessageSize(), coreExt->getMaxExtendedMessageSize()));
chatListWidget = new FriendListWidget(*core, this, settings, style, 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::searchCircle, this, &Widget::searchCircle);
connect(chatListWidget, &FriendListWidget::connectCircleWidget, this, connect(chatListWidget, &FriendListWidget::connectCircleWidget, this,
&Widget::connectCircleWidget); &Widget::connectCircleWidget);
@ -620,7 +621,7 @@ Widget::~Widget()
icon->hide(); icon->hide();
} }
for (Group* g : GroupList::getAllGroups()) { for (Group* g : groupList->getAllGroups()) {
removeGroup(g, true); removeGroup(g, true);
} }
@ -642,7 +643,7 @@ Widget::~Widget()
delete settingsWidget; delete settingsWidget;
friendList->clear(); friendList->clear();
GroupList::clear(); groupList->clear();
delete trayMenu; delete trayMenu;
delete ui; delete ui;
instance = nullptr; instance = nullptr;
@ -1156,7 +1157,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
settings.updateFriendAddress(friendPk.toString()); settings.updateFriendAddress(friendPk.toString());
Friend* newfriend = friendList->addFriend(friendId, friendPk, settings); 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<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, settings, style, *messageBoxManager, profile); 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 // ChatHistory hooks them up in a very specific order
auto chatHistory = auto chatHistory =
std::make_shared<ChatHistory>(*newfriend, history, *core, settings, std::make_shared<ChatHistory>(*newfriend, history, *core, settings,
*friendMessageDispatcher, *friendList); *friendMessageDispatcher, *friendList,
*groupList);
auto friendForm = new ChatForm(profile, newfriend, *chatHistory, auto friendForm = new ChatForm(profile, newfriend, *chatHistory,
*friendMessageDispatcher, *documentCache, *smileyPack, cameraSource, *friendMessageDispatcher, *documentCache, *smileyPack, cameraSource,
settings, style, *messageBoxManager, *contentDialogManager, *friendList); settings, style, *messageBoxManager, *contentDialogManager, *friendList,
*groupList);
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity); connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
friendMessageDispatchers[friendPk] = friendMessageDispatcher; friendMessageDispatchers[friendPk] = friendMessageDispatcher;
@ -1307,7 +1310,7 @@ void Widget::onFriendDisplayedNameChanged(const QString& displayed)
{ {
Friend* f = qobject_cast<Friend*>(sender()); Friend* f = qobject_cast<Friend*>(sender());
const auto& friendPk = f->getPublicKey(); const auto& friendPk = f->getPublicKey();
for (Group* g : GroupList::getAllGroups()) { for (Group* g : groupList->getAllGroups()) {
if (g->getPeerList().contains(friendPk)) { if (g->getPeerList().contains(friendPk)) {
g->updateUsername(friendPk, displayed); g->updateUsername(friendPk, displayed);
} }
@ -1619,7 +1622,7 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk,
bool hasActive; bool hasActive;
QWidget* currentWindow; QWidget* currentWindow;
ContentDialog* contentDialog = contentDialogManager->getGroupDialog(groupId); ContentDialog* contentDialog = contentDialogManager->getGroupDialog(groupId);
Group* g = GroupList::findGroup(groupId); Group* g = groupList->findGroup(groupId);
GroupWidget* widget = groupWidgets[groupId]; GroupWidget* widget = groupWidgets[groupId];
if (contentDialog != nullptr) { if (contentDialog != nullptr) {
@ -1768,7 +1771,7 @@ void Widget::removeFriend(Friend* f, bool fake)
if (!fake) { if (!fake) {
core->removeFriend(f->getId()); core->removeFriend(f->getId());
// aliases aren't supported for non-friend peers in groups, revert to basic username // 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)) { if (g->getPeerList().contains(friendPk)) {
g->updateUsername(friendPk, f->getUserName()); g->updateUsername(friendPk, f->getUserName());
} }
@ -1831,7 +1834,7 @@ void Widget::onUpdateAvailable()
ContentDialog* Widget::createContentDialog() const ContentDialog* Widget::createContentDialog() const
{ {
ContentDialog* contentDialog = new ContentDialog(*core, settings, style, ContentDialog* contentDialog = new ContentDialog(*core, settings, style,
*messageBoxManager, *friendList, profile); *messageBoxManager, *friendList, *groupList, profile);
registerContentDialog(*contentDialog); registerContentDialog(*contentDialog);
return contentDialog; return contentDialog;
@ -1991,8 +1994,8 @@ void Widget::onGroupInviteAccepted(const GroupInvite& inviteInfo)
void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QString& message,
bool isAction) bool isAction)
{ {
const GroupId& groupId = GroupList::id2Key(groupnumber); const GroupId& groupId = groupList->id2Key(groupnumber);
assert(GroupList::findGroup(groupId)); assert(groupList->findGroup(groupId));
ToxPk author = core->getGroupPeerPk(groupnumber, peernumber); 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) void Widget::onGroupPeerlistChanged(uint32_t groupnumber)
{ {
const GroupId& groupId = GroupList::id2Key(groupnumber); const GroupId& groupId = groupList->id2Key(groupnumber);
Group* g = GroupList::findGroup(groupId); Group* g = groupList->findGroup(groupId);
assert(g); assert(g);
g->regeneratePeerList(); g->regeneratePeerList();
} }
void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, const QString& newName) void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, const QString& newName)
{ {
const GroupId& groupId = GroupList::id2Key(groupnumber); const GroupId& groupId = groupList->id2Key(groupnumber);
Group* g = GroupList::findGroup(groupId); Group* g = groupList->findGroup(groupId);
assert(g); assert(g);
const QString setName = friendList->decideNickname(peerPk, newName); 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) void Widget::onGroupTitleChanged(uint32_t groupnumber, const QString& author, const QString& title)
{ {
const GroupId& groupId = GroupList::id2Key(groupnumber); const GroupId& groupId = groupList->id2Key(groupnumber);
Group* g = GroupList::findGroup(groupId); Group* g = groupList->findGroup(groupId);
assert(g); assert(g);
GroupWidget* widget = groupWidgets[groupId]; GroupWidget* widget = groupWidgets[groupId];
@ -2041,8 +2044,8 @@ void Widget::titleChangedByUser(const QString& title)
void Widget::onGroupPeerAudioPlaying(int groupnumber, ToxPk peerPk) void Widget::onGroupPeerAudioPlaying(int groupnumber, ToxPk peerPk)
{ {
const GroupId& groupId = GroupList::id2Key(groupnumber); const GroupId& groupId = groupList->id2Key(groupnumber);
assert(GroupList::findGroup(groupId)); assert(groupList->findGroup(groupId));
auto form = groupChatForms[groupId].data(); auto form = groupChatForms[groupId].data();
form->peerAudioPlaying(peerPk); form->peerAudioPlaying(peerPk);
@ -2069,7 +2072,7 @@ void Widget::removeGroup(Group* g, bool fake)
onAddClicked(); onAddClicked();
} }
GroupList::removeGroup(groupId, fake); groupList->removeGroup(groupId, fake);
ContentDialog* contentDialog = contentDialogManager->getGroupDialog(groupId); ContentDialog* contentDialog = contentDialogManager->getGroupDialog(groupId);
if (contentDialog != nullptr) { if (contentDialog != nullptr) {
contentDialog->removeGroup(groupId); contentDialog->removeGroup(groupId);
@ -2098,14 +2101,14 @@ void Widget::removeGroup(Group* g, bool fake)
void Widget::removeGroup(const GroupId& groupId) void Widget::removeGroup(const GroupId& groupId)
{ {
removeGroup(GroupList::findGroup(groupId)); removeGroup(groupList->findGroup(groupId));
} }
Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
{ {
assert(core != nullptr); 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";
return g; return g;
@ -2114,7 +2117,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
const auto groupName = tr("Groupchat #%1").arg(groupnumber); const auto groupName = tr("Groupchat #%1").arg(groupnumber);
const bool enabled = core->getGroupAvEnabled(groupnumber); const bool enabled = core->getGroupAvEnabled(groupnumber);
Group* newgroup = Group* newgroup =
GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername(), groupList->addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername(),
*friendList); *friendList);
assert(newgroup); assert(newgroup);
@ -2141,7 +2144,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
// ChatHistory hooks them up in a very specific order // ChatHistory hooks them up in a very specific order
auto chatHistory = auto chatHistory =
std::make_shared<ChatHistory>(*newgroup, history, *core, settings, std::make_shared<ChatHistory>(*newgroup, history, *core, settings,
*messageDispatcher, *friendList); *messageDispatcher, *friendList, *groupList);
auto notifyReceivedCallback = [this, groupId](const ToxPk& author, const Message& message) { auto notifyReceivedCallback = [this, groupId](const ToxPk& author, const Message& message) {
auto isTargeted = std::any_of(message.metadata.begin(), message.metadata.end(), 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); groupAlertConnections.insert(groupId, notifyReceivedConnection);
auto form = new GroupChatForm(*core, newgroup, *chatHistory, *messageDispatcher, 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); connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
form->setColorizedNames(settings.getEnableGroupChatsColor()); form->setColorizedNames(settings.getEnableGroupChatsColor());
groupMessageDispatchers[groupId] = messageDispatcher; groupMessageDispatchers[groupId] = messageDispatcher;
@ -2355,8 +2358,8 @@ void Widget::setStatusBusy()
void Widget::onGroupSendFailed(uint32_t groupnumber) void Widget::onGroupSendFailed(uint32_t groupnumber)
{ {
const auto& groupId = GroupList::id2Key(groupnumber); const auto& groupId = groupList->id2Key(groupnumber);
assert(GroupList::findGroup(groupId)); assert(groupList->findGroup(groupId));
const auto curTime = QDateTime::currentDateTime(); const auto curTime = QDateTime::currentDateTime();
auto form = groupChatForms[groupId].data(); auto form = groupChatForms[groupId].data();
@ -2706,7 +2709,7 @@ void Widget::focusChatInput()
void Widget::refreshPeerListsLocal(const QString& username) void Widget::refreshPeerListsLocal(const QString& username)
{ {
for (Group* g : GroupList::getAllGroups()) { for (Group* g : groupList->getAllGroups()) {
g->updateUsername(core->getSelfPublicKey(), username); g->updateUsername(core->getSelfPublicKey(), username);
} }
} }

4
src/widget/widget.h

@ -37,7 +37,6 @@
#include "src/core/toxpk.h" #include "src/core/toxpk.h"
#include "src/model/friendmessagedispatcher.h" #include "src/model/friendmessagedispatcher.h"
#include "src/model/groupmessagedispatcher.h" #include "src/model/groupmessagedispatcher.h"
#include "src/friendlist.h"
#if DESKTOP_NOTIFICATIONS #if DESKTOP_NOTIFICATIONS
#include "src/model/notificationgenerator.h" #include "src/model/notificationgenerator.h"
#include "src/platform/desktop_notifications/desktopnotify.h" #include "src/platform/desktop_notifications/desktopnotify.h"
@ -89,6 +88,8 @@ class CameraSource;
class Style; class Style;
class IMessageBoxManager; class IMessageBoxManager;
class ContentDialogManager; class ContentDialogManager;
class FriendList;
class GroupList;
class Widget final : public QMainWindow class Widget final : public QMainWindow
{ {
@ -394,6 +395,7 @@ private:
Style& style; Style& style;
IMessageBoxManager* messageBoxManager = nullptr; // freed by Qt on destruction IMessageBoxManager* messageBoxManager = nullptr; // freed by Qt on destruction
std::unique_ptr<FriendList> friendList; std::unique_ptr<FriendList> friendList;
std::unique_ptr<GroupList> groupList;
std::unique_ptr<ContentDialogManager> contentDialogManager; std::unique_ptr<ContentDialogManager> contentDialogManager;
}; };

5
test/model/sessionchatlog_test.cpp

@ -73,6 +73,7 @@ private:
MockCoreIdHandler idHandler; MockCoreIdHandler idHandler;
std::unique_ptr<SessionChatLog> chatLog; std::unique_ptr<SessionChatLog> chatLog;
std::unique_ptr<FriendList> friendList; std::unique_ptr<FriendList> friendList;
std::unique_ptr<GroupList> groupList;
}; };
/** /**
@ -81,7 +82,9 @@ private:
void TestSessionChatLog::init() void TestSessionChatLog::init()
{ {
friendList = std::unique_ptr<FriendList>(new FriendList()); friendList = std::unique_ptr<FriendList>(new FriendList());
chatLog = std::unique_ptr<SessionChatLog>(new SessionChatLog(idHandler, *friendList)); groupList = std::unique_ptr<GroupList>(new GroupList());
chatLog = std::unique_ptr<SessionChatLog>(new SessionChatLog(idHandler, *friendList,
*groupList));
} }
/** /**

Loading…
Cancel
Save