1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: Move GroupList global state into class

This commit is contained in:
Anthony Bilinski 2022-04-02 08:22:15 -07:00
parent e48c557387
commit 1e4eed76b5
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
23 changed files with 108 additions and 74 deletions

View File

@ -23,8 +23,6 @@
#include <QDebug>
#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,
const QString& selfName, FriendList& friendList)
{

View File

@ -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<Group*> getAllGroups();
static void clear();
Group* findGroup(const GroupId& groupId);
const GroupId& id2Key(uint32_t groupNum);
void removeGroup(const GroupId& groupId, bool fake = false);
QList<Group*> getAllGroups();
void clear();
private:
static QHash<const GroupId, Group*> groupList;
static QHash<uint32_t, GroupId> id2key;
QHash<const GroupId, Group*> groupList;
QHash<uint32_t, GroupId> id2key;
};

View File

@ -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);

View File

@ -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;

View File

@ -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<GroupToDisplay> FriendChatroom::getGroups() const
{
QVector<GroupToDisplay> 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);

View File

@ -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;
};

View File

@ -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);
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

View File

@ -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<DispatchedMessageId, ChatLogIdx> outgoingMessages;
FriendList& friendList;
GroupList& groupList;
};

View File

@ -42,7 +42,7 @@ QHash<int, CircleWidget*> 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();

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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<FriendChatroom> chatroom, GenericChatForm* form);
@ -146,5 +147,6 @@ private:
Style& style;
IMessageBoxManager& messageBoxManager;
FriendList& friendList;
GroupList& groupList;
Profile& profile;
};

View File

@ -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}

View File

@ -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);

View File

@ -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);

View File

@ -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;
};

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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;
};

View File

@ -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<FriendChatroom> 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<ChatHistory>(*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<Friend*>(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<ChatHistory>(*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);
}
}

View File

@ -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> friendList;
std::unique_ptr<GroupList> groupList;
std::unique_ptr<ContentDialogManager> contentDialogManager;
};

View File

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