Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add Channel::addSystemMessage function #5500

Merged
merged 5 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Dev: Refactor `TwitchIrcServer`, making it abstracted. (#5421, #5435)
- Dev: Reduced the amount of scale events. (#5404, #5406)
- Dev: Removed unused timegate settings. (#5361)
- Dev: Add `Channel::addSystemMessage` helper function, allowing us to avoid the common `channel->addMessage(makeSystemMessage(...));` pattern. (#5500)
- Dev: Unsingletonize `Resources2`. (#5460)
- Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385)
- Dev: Images are now loaded in worker threads. (#5431)
Expand Down
20 changes: 9 additions & 11 deletions src/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Application.hpp"

#include "common/Args.hpp"
#include "common/Channel.hpp"
#include "common/QLogging.hpp"
#include "common/Version.hpp"
#include "controllers/accounts/AccountController.hpp"
Expand Down Expand Up @@ -233,10 +234,10 @@ void Application::initialize(Settings &settings, const Paths &paths)
{
if (auto channel = split->getChannel(); !channel->isEmpty())
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"Chatterino unexpectedly crashed and restarted. "
"You can disable automatic restarts in the "
"settings."));
"settings.");
}
}
}
Expand Down Expand Up @@ -584,9 +585,8 @@ void Application::initPubSub()
QString text =
QString("%1 cleared the chat.").arg(action.source.login);

auto msg = makeSystemMessage(text);
postToThread([chan, msg] {
chan->addMessage(msg);
postToThread([chan, text] {
chan->addSystemMessage(text);
});
});

Expand All @@ -610,9 +610,8 @@ void Application::initPubSub()
text += QString(" (%1 seconds)").arg(action.duration);
}

auto msg = makeSystemMessage(text);
postToThread([chan, msg] {
chan->addMessage(msg);
postToThread([chan, text] {
chan->addSystemMessage(text);
});
});

Expand All @@ -631,9 +630,8 @@ void Application::initPubSub()
(action.modded ? "modded" : "unmodded"),
action.target.login);

auto msg = makeSystemMessage(text);
postToThread([chan, msg] {
chan->addMessage(msg);
postToThread([chan, text] {
chan->addSystemMessage(text);
});
});

Expand Down
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,6 @@ set(SOURCE_FILES
widgets/dialogs/LastRunCrashDialog.hpp
widgets/dialogs/LoginDialog.cpp
widgets/dialogs/LoginDialog.hpp
widgets/dialogs/NotificationPopup.cpp
widgets/dialogs/NotificationPopup.hpp
widgets/dialogs/QualityPopup.cpp
widgets/dialogs/QualityPopup.hpp
widgets/dialogs/ReplyThreadPopup.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ void Channel::addMessage(MessagePtr message,
this->messageAppended.invoke(message, overridingFlags);
}

void Channel::addSystemMessage(const QString &contents)
{
auto msg = makeSystemMessage(contents);
this->addMessage(msg);
}

void Channel::addOrReplaceTimeout(MessagePtr message)
{
addOrReplaceChannelTimeout(
Expand Down
2 changes: 2 additions & 0 deletions src/common/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Channel : public std::enable_shared_from_this<Channel>
std::optional<MessageFlags> overridingFlags = std::nullopt);
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);

void addSystemMessage(const QString &contents);

/// Inserts the given messages in order by Message::serverReceivedTime.
void fillInMissingMessages(const std::vector<MessagePtr> &messages);

Expand Down
3 changes: 1 addition & 2 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ QString CommandController::execCommand(const QString &textNoEmoji,

if (!dryRun && channel->getType() == Channel::Type::TwitchWhispers)
{
channel->addMessage(
makeSystemMessage("Use /w <username> <message> to whisper"));
channel->addSystemMessage("Use /w <username> <message> to whisper");
return "";
}

Expand Down
Loading
Loading