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: make a single MessageBuilder #5548

Merged
merged 16 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
7 changes: 4 additions & 3 deletions benchmarks/src/Highlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/highlights/HighlightPhrase.hpp"
#include "messages/Message.hpp"
#include "messages/SharedMessageBuilder.hpp"
#include "messages/MessageBuilder.hpp"
#include "mocks/BaseApplication.hpp"
#include "singletons/Settings.hpp"
#include "util/Helpers.hpp"
Expand All @@ -16,15 +16,16 @@

using namespace chatterino;

class BenchmarkMessageBuilder : public SharedMessageBuilder
class BenchmarkMessageBuilder : public MessageBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: destructor of 'BenchmarkMessageBuilder' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class BenchmarkMessageBuilder : public MessageBuilder
      ^
Additional context

benchmarks/src/Highlights.cpp:18: make it public and virtual

class BenchmarkMessageBuilder : public MessageBuilder
      ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: destructor of 'BenchmarkMessageBuilder' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class BenchmarkMessageBuilder : public MessageBuilder
      ^
Additional context

benchmarks/src/Highlights.cpp:18: make it public and virtual

class BenchmarkMessageBuilder : public MessageBuilder
      ^

{
public:
explicit BenchmarkMessageBuilder(
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args)
: SharedMessageBuilder(_channel, _ircMessage, _args)
: MessageBuilder(_channel, _ircMessage, _args)
{
}

virtual MessagePtr build()
{
// PARSE
Expand Down
27 changes: 10 additions & 17 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "providers/twitch/PubSubMessages.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/CrashHandler.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Fonts.hpp"
Expand Down Expand Up @@ -738,11 +737,9 @@ void Application::initPubSub()
return;
}

MessageBuilder msg;
TwitchMessageBuilder::deletionMessage(action, &msg);
msg->flags.set(MessageFlag::PubSub);
auto msg = MessageBuilder::makeDeletionMessageFromPubSub(action);

postToThread([chan, msg = msg.release()] {
postToThread([chan, msg] {
auto replaced = false;
LimitedQueueSnapshot<MessagePtr> snapshot =
chan->getMessageSnapshot();
Expand Down Expand Up @@ -827,10 +824,8 @@ void Application::initPubSub()
}

postToThread([twitchChannel, action] {
const auto p =
TwitchMessageBuilder::makeLowTrustUserMessage(
action, twitchChannel->getName(),
twitchChannel.get());
const auto p = MessageBuilder::makeLowTrustUserMessage(
action, twitchChannel->getName(), twitchChannel.get());
twitchChannel->addMessage(p.first,
MessageContext::Original);
twitchChannel->addMessage(p.second,
Expand Down Expand Up @@ -871,7 +866,7 @@ void Application::initPubSub()

postToThread([chan, action] {
auto msg =
TwitchMessageBuilder::makeLowTrustUpdateMessage(action);
MessageBuilder::makeLowTrustUpdateMessage(action);
chan->addMessage(msg, MessageContext::Original);
});
});
Expand Down Expand Up @@ -951,9 +946,8 @@ void Application::initPubSub()
ActionUser{msg.senderUserID, msg.senderUserLogin,
senderDisplayName, senderColor};
postToThread([chan, action] {
const auto p =
TwitchMessageBuilder::makeAutomodMessage(
action, chan->getName());
const auto p = MessageBuilder::makeAutomodMessage(
action, chan->getName());
chan->addMessage(p.first, MessageContext::Original);
chan->addMessage(p.second,
MessageContext::Original);
Expand Down Expand Up @@ -1004,8 +998,8 @@ void Application::initPubSub()
}

postToThread([chan, action] {
const auto p = TwitchMessageBuilder::makeAutomodMessage(
action, chan->getName());
const auto p =
MessageBuilder::makeAutomodMessage(action, chan->getName());
chan->addMessage(p.first, MessageContext::Original);
chan->addMessage(p.second, MessageContext::Original);
});
Expand Down Expand Up @@ -1043,8 +1037,7 @@ void Application::initPubSub()
}

postToThread([chan, action] {
const auto p =
TwitchMessageBuilder::makeAutomodInfoMessage(action);
const auto p = MessageBuilder::makeAutomodInfoMessage(action);
chan->addMessage(p, MessageContext::Original);
});
});
Expand Down
5 changes: 0 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ set(SOURCE_FILES
messages/MessageThread.cpp
messages/MessageThread.hpp

messages/SharedMessageBuilder.cpp
messages/SharedMessageBuilder.hpp

messages/layouts/MessageLayout.cpp
messages/layouts/MessageLayout.hpp
messages/layouts/MessageLayoutContainer.cpp
Expand Down Expand Up @@ -405,8 +402,6 @@ set(SOURCE_FILES
providers/twitch/TwitchHelpers.hpp
providers/twitch/TwitchIrcServer.cpp
providers/twitch/TwitchIrcServer.hpp
providers/twitch/TwitchMessageBuilder.cpp
providers/twitch/TwitchMessageBuilder.hpp
providers/twitch/TwitchUser.cpp
providers/twitch/TwitchUser.hpp

Expand Down
23 changes: 10 additions & 13 deletions src/common/ChannelChatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

#include <QColor>

Expand Down Expand Up @@ -39,12 +38,11 @@ void ChannelChatters::addJoinedUser(const QString &user)
auto joinedUsers = this->joinedUsers_.access();
joinedUsers->sort();

MessageBuilder builder;
TwitchMessageBuilder::listOfUsersSystemMessage(
"Users joined:", *joinedUsers, &this->channel_, &builder);
builder->flags.set(MessageFlag::Collapsed);
this->channel_.addMessage(builder.release(),
MessageContext::Original);
this->channel_.addMessage(
MessageBuilder::makeListOfUsersMessage(
"Users joined:", *joinedUsers, &this->channel_,
{MessageFlag::Collapsed}),
MessageContext::Original);

joinedUsers->clear();
this->joinedUsersMergeQueued_ = false;
Expand All @@ -65,12 +63,11 @@ void ChannelChatters::addPartedUser(const QString &user)
auto partedUsers = this->partedUsers_.access();
partedUsers->sort();

MessageBuilder builder;
TwitchMessageBuilder::listOfUsersSystemMessage(
"Users parted:", *partedUsers, &this->channel_, &builder);
builder->flags.set(MessageFlag::Collapsed);
this->channel_.addMessage(builder.release(),
MessageContext::Original);
this->channel_.addMessage(
MessageBuilder::makeListOfUsersMessage(
"Users parted:", *partedUsers, &this->channel_,
{MessageFlag::Collapsed}),
MessageContext::Original);

partedUsers->clear();
this->partedUsersMergeQueued_ = false;
Expand Down
1 change: 0 additions & 1 deletion src/controllers/commands/builtin/twitch/AddModerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/Twitch.hpp"

namespace chatterino::commands {
Expand Down
1 change: 0 additions & 1 deletion src/controllers/commands/builtin/twitch/AddVIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/Twitch.hpp"

namespace chatterino::commands {
Expand Down
9 changes: 3 additions & 6 deletions src/controllers/commands/builtin/twitch/Chatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Theme.hpp"

#include <QApplication>
Expand Down Expand Up @@ -125,11 +124,9 @@ QString testChatters(const CommandContext &ctx)
prefix += QString("(%1):").arg(result.total);
}

MessageBuilder builder;
TwitchMessageBuilder::listOfUsersSystemMessage(
prefix, entries, twitchChannel, &builder);

channel->addMessage(builder.release(), MessageContext::Original);
channel->addMessage(MessageBuilder::makeListOfUsersMessage(
prefix, entries, twitchChannel),
MessageContext::Original);
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatChattersError(error, message);
Expand Down
10 changes: 4 additions & 6 deletions src/controllers/commands/builtin/twitch/GetModerators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

namespace {

Expand Down Expand Up @@ -77,11 +76,10 @@ QString getModerators(const CommandContext &ctx)

// TODO: sort results?

MessageBuilder builder;
TwitchMessageBuilder::listOfUsersSystemMessage(
"The moderators of this channel are", result, twitchChannel,
&builder);
channel->addMessage(builder.release(), MessageContext::Original);
channel->addMessage(MessageBuilder::makeListOfUsersMessage(
"The moderators of this channel are",
result, twitchChannel),
MessageContext::Original);
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatModsError(error, message);
Expand Down
8 changes: 3 additions & 5 deletions src/controllers/commands/builtin/twitch/GetVIPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

namespace {

Expand Down Expand Up @@ -106,11 +105,10 @@ QString getVIPs(const CommandContext &ctx)
auto messagePrefix = QString("The VIPs of this channel are");

// TODO: sort results?
MessageBuilder builder;
TwitchMessageBuilder::listOfUsersSystemMessage(
messagePrefix, vipList, twitchChannel, &builder);

channel->addMessage(builder.release(), MessageContext::Original);
channel->addMessage(MessageBuilder::makeListOfUsersMessage(
messagePrefix, vipList, twitchChannel),
MessageContext::Original);
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatGetVIPsError(error, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/Twitch.hpp"

namespace chatterino::commands {
Expand Down
1 change: 0 additions & 1 deletion src/controllers/commands/builtin/twitch/RemoveVIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/Twitch.hpp"

namespace chatterino::commands {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

namespace {

Expand Down
5 changes: 2 additions & 3 deletions src/controllers/highlights/HighlightBadge.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "controllers/highlights/HighlightBadge.hpp"

#include "messages/SharedMessageBuilder.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "singletons/Resources.hpp"
#include "util/IrcHelpers.hpp"

namespace chatterino {

Expand Down Expand Up @@ -97,7 +96,7 @@ bool HighlightBadge::compare(const QString &id, const Badge &badge) const
{
if (this->hasVersions_)
{
auto parts = SharedMessageBuilder::slashKeyValue(id);
auto parts = slashKeyValue(id);
return parts.first.compare(badge.key_, Qt::CaseInsensitive) == 0 &&
parts.second.compare(badge.value_, Qt::CaseInsensitive) == 0;
}
Expand Down
8 changes: 3 additions & 5 deletions src/controllers/notifications/NotificationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "controllers/notifications/NotificationModel.hpp"
#include "controllers/sound/ISoundController.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Settings.hpp"
#include "singletons/StreamerMode.hpp"
#include "singletons/Toasts.hpp"
Expand Down Expand Up @@ -137,11 +137,9 @@ void NotificationController::notifyTwitchChannelLive(
}

// Message in /live channel
MessageBuilder builder;
TwitchMessageBuilder::liveMessage(payload.displayName, &builder);
builder.message().id = payload.channelId;
getApp()->getTwitch()->getLiveChannel()->addMessage(
builder.release(), MessageContext::Original);
MessageBuilder::makeLiveMessage(payload.displayName, payload.channelId),
MessageContext::Original);

// Notify on all channels with a ping sound
if (showNotification && !playedSound &&
Expand Down
Loading
Loading