refactor: make a single MessageBuilder (#5548)

This commit is contained in:
pajlada 2024-08-24 12:18:27 +02:00 committed by GitHub
parent 5170085d7c
commit 175afa8b16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 2819 additions and 3014 deletions

View file

@ -72,6 +72,7 @@
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
- Dev: Added `FlagsEnum::isEmpty`. (#5550)
- Dev: Prepared for Qt 6.8 by addressing some deprecations. (#5529)
- Dev: Refactored `MessageBuilder` to be a single class. (#5548)
- Dev: Recent changes are now shown in the nightly release description. (#5553, #5554)
## 2.5.1

View file

@ -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"
@ -16,15 +16,16 @@
using namespace chatterino;
class BenchmarkMessageBuilder : public SharedMessageBuilder
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

View file

@ -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"
@ -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();
@ -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,
@ -871,7 +866,7 @@ void Application::initPubSub()
postToThread([chan, action] {
auto msg =
TwitchMessageBuilder::makeLowTrustUpdateMessage(action);
MessageBuilder::makeLowTrustUpdateMessage(action);
chan->addMessage(msg, MessageContext::Original);
});
});
@ -951,8 +946,7 @@ void Application::initPubSub()
ActionUser{msg.senderUserID, msg.senderUserLogin,
senderDisplayName, senderColor};
postToThread([chan, action] {
const auto p =
TwitchMessageBuilder::makeAutomodMessage(
const auto p = MessageBuilder::makeAutomodMessage(
action, chan->getName());
chan->addMessage(p.first, MessageContext::Original);
chan->addMessage(p.second,
@ -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);
});
@ -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);
});
});

View file

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

View file

@ -3,7 +3,6 @@
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include <QColor>
@ -39,11 +38,10 @@ 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(),
this->channel_.addMessage(
MessageBuilder::makeListOfUsersMessage(
"Users joined:", *joinedUsers, &this->channel_,
{MessageFlag::Collapsed}),
MessageContext::Original);
joinedUsers->clear();
@ -65,11 +63,10 @@ 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(),
this->channel_.addMessage(
MessageBuilder::makeListOfUsersMessage(
"Users parted:", *partedUsers, &this->channel_,
{MessageFlag::Collapsed}),
MessageContext::Original);
partedUsers->clear();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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"
@ -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 &&

File diff suppressed because it is too large Load diff

View file

@ -1,15 +1,25 @@
#pragma once
#include "common/Aliases.hpp"
#include "common/Outcome.hpp"
#include "messages/MessageColor.hpp"
#include "messages/MessageFlag.hpp"
#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp"
#include <IrcMessage>
#include <QRegularExpression>
#include <QString>
#include <QTime>
#include <QVariant>
#include <ctime>
#include <memory>
#include <optional>
#include <unordered_map>
#include <utility>
namespace chatterino {
struct BanAction;
struct UnbanAction;
struct WarnAction;
@ -24,6 +34,15 @@ class TextElement;
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class Channel;
class TwitchChannel;
class MessageThread;
class IgnorePhrase;
struct HelixVip;
using HelixModerator = HelixVip;
struct ChannelPointReward;
struct DeleteAction;
namespace linkparser {
struct Parsed;
} // namespace linkparser
@ -67,10 +86,36 @@ struct MessageParseArgs {
QString channelPointRewardId = "";
};
struct TwitchEmoteOccurrence {
int start;
int end;
EmotePtr ptr;
EmoteName name;
bool operator==(const TwitchEmoteOccurrence &other) const
{
return std::tie(this->start, this->end, this->ptr, this->name) ==
std::tie(other.start, other.end, other.ptr, other.name);
}
};
class MessageBuilder
{
public:
/// Build a message without a base IRC message.
MessageBuilder();
/// Build a message based on an incoming IRC PRIVMSG
explicit MessageBuilder(Channel *_channel,
const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args);
/// Build a message based on an incoming IRC message (e.g. notice)
explicit MessageBuilder(Channel *_channel,
const Communi::IrcMessage *_ircMessage,
const MessageParseArgs &_args, QString content,
bool isAction);
MessageBuilder(SystemMessageTag, const QString &text,
const QTime &time = QTime::currentTime());
MessageBuilder(TimeoutMessageTag, const QString &timeoutUser,
@ -106,7 +151,16 @@ public:
const QString &deletionLink, size_t imagesStillQueued = 0,
size_t secondsLeft = 0);
virtual ~MessageBuilder() = default;
MessageBuilder(const MessageBuilder &) = delete;
MessageBuilder(MessageBuilder &&) = delete;
MessageBuilder &operator=(const MessageBuilder &) = delete;
MessageBuilder &operator=(MessageBuilder &&) = delete;
~MessageBuilder() = default;
QString userName;
TwitchChannel *twitchChannel = nullptr;
Message *operator->();
Message &message();
@ -117,10 +171,7 @@ public:
void addLink(const linkparser::Parsed &parsedLink, const QString &source);
template <typename T, typename... Args>
// clang-format off
// clang-format can be enabled once clang-format v11+ has been installed in CI
T *emplace(Args &&...args)
// clang-format on
{
static_assert(std::is_base_of<MessageElement, T>::value,
"T must extend MessageElement");
@ -131,9 +182,70 @@ public:
return pointer;
}
[[nodiscard]] bool isIgnored() const;
bool isIgnoredReply() const;
void triggerHighlights();
MessagePtr build();
void setThread(std::shared_ptr<MessageThread> thread);
void setParent(MessagePtr parent);
void setMessageOffset(int offset);
void appendChannelPointRewardMessage(const ChannelPointReward &reward,
bool isMod, bool isBroadcaster);
static MessagePtr makeChannelPointRewardMessage(
const ChannelPointReward &reward, bool isMod, bool isBroadcaster);
/// Make a "CHANNEL_NAME has gone live!" message
static MessagePtr makeLiveMessage(const QString &channelName,
const QString &channelID,
MessageFlags extraFlags = {});
// Messages in normal chat for channel stuff
static MessagePtr makeOfflineSystemMessage(const QString &channelName,
const QString &channelID);
static MessagePtr makeHostingSystemMessage(const QString &channelName,
bool hostOn);
static MessagePtr makeDeletionMessageFromIRC(
const MessagePtr &originalMessage);
static MessagePtr makeDeletionMessageFromPubSub(const DeleteAction &action);
static MessagePtr makeListOfUsersMessage(QString prefix, QStringList users,
Channel *channel,
MessageFlags extraFlags = {});
static MessagePtr makeListOfUsersMessage(
QString prefix, const std::vector<HelixModerator> &users,
Channel *channel, MessageFlags extraFlags = {});
static MessagePtr buildHypeChatMessage(Communi::IrcPrivateMessage *message);
static std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
const AutomodAction &action, const QString &channelName);
static MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action);
static std::pair<MessagePtr, MessagePtr> makeLowTrustUserMessage(
const PubSubLowTrustUsersMessage &action, const QString &channelName,
const TwitchChannel *twitchChannel);
static MessagePtr makeLowTrustUpdateMessage(
const PubSubLowTrustUsersMessage &action);
static std::unordered_map<QString, QString> parseBadgeInfoTag(
const QVariantMap &tags);
// Parses "badges" tag which contains a comma separated list of key-value elements
static std::vector<Badge> parseBadgeTag(const QVariantMap &tags);
static std::vector<TwitchEmoteOccurrence> parseTwitchEmotes(
const QVariantMap &tags, const QString &originalMessage,
int messageOffset);
static void processIgnorePhrases(
const std::vector<IgnorePhrase> &phrases, QString &originalMessage,
std::vector<TwitchEmoteOccurrence> &twitchEmotes);
protected:
virtual void addTextOrEmoji(EmotePtr emote);
virtual void addTextOrEmoji(const QString &value);
void addTextOrEmoji(EmotePtr emote);
void addTextOrEmoji(const QString &string_);
bool isEmpty() const;
MessageElement &back();
@ -141,7 +253,6 @@ protected:
MessageColor textColor_ = MessageColor::Text;
private:
// Helper method that emplaces some text stylized as system text
// and then appends that text to the QString parameter "toUpdate".
// Returns the TextElement that was emplaced.
@ -149,6 +260,70 @@ private:
QString &toUpdate);
std::shared_ptr<Message> message_;
void parse();
void parseUsernameColor();
void parseUsername();
void parseMessageID();
void parseRoomID();
// Parse & build thread information into the message
// Will read information from thread_ or from IRC tags
void parseThread();
// parseHighlights only updates the visual state of the message, but leaves the playing of alerts and sounds to the triggerHighlights function
void parseHighlights();
void appendChannelName();
void appendUsername();
Outcome tryAppendEmote(const EmoteName &name);
void addWords(const QStringList &words,
const std::vector<TwitchEmoteOccurrence> &twitchEmotes);
void appendTwitchBadges();
void appendChatterinoBadges();
void appendFfzBadges();
void appendSeventvBadges();
Outcome tryParseCheermote(const QString &string);
bool shouldAddModerationElements() const;
QString roomID_;
bool hasBits_ = false;
QString bits;
int bitsLeft{};
bool bitsStacked = false;
bool historicalMessage_ = false;
std::shared_ptr<MessageThread> thread_;
MessagePtr parent_;
/**
* Starting offset to be used on index-based operations on `originalMessage_`.
*
* For example:
* originalMessage_ = "there"
* messageOffset_ = 4
* (the irc message is "hey there")
*
* then the index 6 would resolve to 6 - 4 = 2 => 'e'
*/
int messageOffset_ = 0;
QString userId_;
bool senderIsBroadcaster{};
Channel *channel = nullptr;
const Communi::IrcMessage *ircMessage;
MessageParseArgs args;
const QVariantMap tags;
QString originalMessage_;
const bool action_{};
QColor usernameColor_ = {153, 153, 153};
bool highlightAlert_ = false;
bool highlightSound_ = false;
std::optional<QUrl> highlightSoundCustomUrl_{};
};
} // namespace chatterino

View file

@ -1,294 +0,0 @@
#include "messages/SharedMessageBuilder.hpp"
#include "Application.hpp"
#include "common/QLogging.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "controllers/nicknames/Nickname.hpp"
#include "controllers/sound/ISoundController.hpp"
#include "messages/Message.hpp"
#include "messages/MessageElement.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "singletons/Settings.hpp"
#include "singletons/StreamerMode.hpp"
#include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp"
#include <QFileInfo>
#include <optional>
namespace {
using namespace chatterino;
/**
* Gets the default sound url if the user set one,
* or the chatterino default ping sound if no url is set.
*/
QUrl getFallbackHighlightSound()
{
QString path = getSettings()->pathHighlightSound;
bool fileExists =
!path.isEmpty() && QFileInfo::exists(path) && QFileInfo(path).isFile();
if (fileExists)
{
return QUrl::fromLocalFile(path);
}
return QUrl("qrc:/sounds/ping2.wav");
}
} // namespace
namespace chatterino {
SharedMessageBuilder::SharedMessageBuilder(
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args)
: channel(_channel)
, ircMessage(_ircMessage)
, args(_args)
, tags(this->ircMessage->tags())
, originalMessage_(_ircMessage->content())
, action_(_ircMessage->isAction())
{
}
SharedMessageBuilder::SharedMessageBuilder(
Channel *_channel, const Communi::IrcMessage *_ircMessage,
const MessageParseArgs &_args, QString content, bool isAction)
: channel(_channel)
, ircMessage(_ircMessage)
, args(_args)
, tags(this->ircMessage->tags())
, originalMessage_(content)
, action_(isAction)
{
}
void SharedMessageBuilder::parse()
{
this->parseUsernameColor();
if (this->action_)
{
this->textColor_ = this->usernameColor_;
this->message().flags.set(MessageFlag::Action);
}
this->parseUsername();
this->message().flags.set(MessageFlag::Collapsed);
}
// "foo/bar/baz,tri/hard" can be a valid badge-info tag
// In that case, valid map content should be 'split by slash' only once:
// {"foo": "bar/baz", "tri": "hard"}
std::pair<QString, QString> SharedMessageBuilder::slashKeyValue(
const QString &kvStr)
{
return {
// part before first slash (index 0 of section)
kvStr.section('/', 0, 0),
// part after first slash (index 1 of section)
kvStr.section('/', 1, -1),
};
}
std::vector<Badge> SharedMessageBuilder::parseBadgeTag(const QVariantMap &tags)
{
std::vector<Badge> b;
auto badgesIt = tags.constFind("badges");
if (badgesIt == tags.end())
{
return b;
}
auto badges = badgesIt.value().toString().split(',', Qt::SkipEmptyParts);
for (const QString &badge : badges)
{
if (!badge.contains('/'))
{
continue;
}
auto pair = SharedMessageBuilder::slashKeyValue(badge);
b.emplace_back(Badge{pair.first, pair.second});
}
return b;
}
bool SharedMessageBuilder::isIgnored() const
{
return isIgnoredMessage({
/*.message = */ this->originalMessage_,
});
}
void SharedMessageBuilder::parseUsernameColor()
{
if (getSettings()->colorizeNicknames)
{
this->usernameColor_ = getRandomColor(this->ircMessage->nick());
}
}
void SharedMessageBuilder::parseUsername()
{
// username
this->userName = this->ircMessage->nick();
this->message().loginName = this->userName;
}
void SharedMessageBuilder::parseHighlights()
{
if (getSettings()->isBlacklistedUser(this->message().loginName))
{
// Do nothing. We ignore highlights from this user.
return;
}
auto badges = SharedMessageBuilder::parseBadgeTag(this->tags);
auto [highlighted, highlightResult] = getApp()->getHighlights()->check(
this->args, badges, this->message().loginName, this->originalMessage_,
this->message().flags);
if (!highlighted)
{
return;
}
// This message triggered one or more highlights, act upon the highlight result
this->message().flags.set(MessageFlag::Highlighted);
this->highlightAlert_ = highlightResult.alert;
this->highlightSound_ = highlightResult.playSound;
this->highlightSoundCustomUrl_ = highlightResult.customSoundUrl;
this->message().highlightColor = highlightResult.color;
if (highlightResult.showInMentions)
{
this->message().flags.set(MessageFlag::ShowInMentions);
}
}
void SharedMessageBuilder::appendChannelName()
{
QString channelName("#" + this->channel->getName());
Link link(Link::JumpToChannel, this->channel->getName());
this->emplace<TextElement>(channelName, MessageElementFlag::ChannelName,
MessageColor::System)
->setLink(link);
}
void SharedMessageBuilder::triggerHighlights()
{
SharedMessageBuilder::triggerHighlights(
this->channel->getName(), this->highlightSound_,
this->highlightSoundCustomUrl_, this->highlightAlert_);
}
void SharedMessageBuilder::triggerHighlights(
const QString &channelName, bool playSound,
const std::optional<QUrl> &customSoundUrl, bool windowAlert)
{
if (getApp()->getStreamerMode()->isEnabled() &&
getSettings()->streamerModeMuteMentions)
{
// We are in streamer mode with muting mention sounds enabled. Do nothing.
return;
}
if (getSettings()->isMutedChannel(channelName))
{
// Do nothing. Pings are muted in this channel.
return;
}
const bool hasFocus = (QApplication::focusWidget() != nullptr);
const bool resolveFocus =
!hasFocus || getSettings()->highlightAlwaysPlaySound;
if (playSound && resolveFocus)
{
// TODO(C++23): optional or_else
QUrl soundUrl;
if (customSoundUrl)
{
soundUrl = *customSoundUrl;
}
else
{
soundUrl = getFallbackHighlightSound();
}
getApp()->getSound()->play(soundUrl);
}
if (windowAlert)
{
getApp()->getWindows()->sendAlert();
}
}
QString SharedMessageBuilder::stylizeUsername(const QString &username,
const Message &message)
{
const QString &localizedName = message.localizedName;
bool hasLocalizedName = !localizedName.isEmpty();
// The full string that will be rendered in the chat widget
QString usernameText;
switch (getSettings()->usernameDisplayMode.getValue())
{
case UsernameDisplayMode::Username: {
usernameText = username;
}
break;
case UsernameDisplayMode::LocalizedName: {
if (hasLocalizedName)
{
usernameText = localizedName;
}
else
{
usernameText = username;
}
}
break;
default:
case UsernameDisplayMode::UsernameAndLocalizedName: {
if (hasLocalizedName)
{
usernameText = username + "(" + localizedName + ")";
}
else
{
usernameText = username;
}
}
break;
}
if (auto nicknameText = getSettings()->matchNickname(usernameText))
{
usernameText = *nicknameText;
}
return usernameText;
}
} // namespace chatterino

View file

@ -1,84 +0,0 @@
#pragma once
#include "common/Aliases.hpp"
#include "common/Outcome.hpp"
#include "messages/MessageBuilder.hpp"
#include <IrcMessage>
#include <QColor>
#include <QUrl>
#include <optional>
namespace chatterino {
class Badge;
class Channel;
class SharedMessageBuilder : public MessageBuilder
{
public:
SharedMessageBuilder() = delete;
explicit SharedMessageBuilder(Channel *_channel,
const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args);
explicit SharedMessageBuilder(Channel *_channel,
const Communi::IrcMessage *_ircMessage,
const MessageParseArgs &_args,
QString content, bool isAction);
QString userName;
[[nodiscard]] virtual bool isIgnored() const;
// triggerHighlights triggers any alerts or sounds parsed by parseHighlights
virtual void triggerHighlights();
virtual MessagePtr build() = 0;
static std::pair<QString, QString> slashKeyValue(const QString &kvStr);
// Parses "badges" tag which contains a comma separated list of key-value elements
static std::vector<Badge> parseBadgeTag(const QVariantMap &tags);
static QString stylizeUsername(const QString &username,
const Message &message);
protected:
virtual void parse();
virtual void parseUsernameColor();
virtual void parseUsername();
virtual Outcome tryAppendEmote(const EmoteName &name)
{
(void)name;
return Failure;
}
// parseHighlights only updates the visual state of the message, but leaves the playing of alerts and sounds to the triggerHighlights function
virtual void parseHighlights();
static void triggerHighlights(const QString &channelName, bool playSound,
const std::optional<QUrl> &customSoundUrl,
bool windowAlert);
void appendChannelName();
Channel *channel;
const Communi::IrcMessage *ircMessage;
MessageParseArgs args;
const QVariantMap tags;
QString originalMessage_;
const bool action_{};
QColor usernameColor_ = {153, 153, 153};
bool highlightAlert_ = false;
bool highlightSound_ = false;
std::optional<QUrl> highlightSoundCustomUrl_{};
};
} // namespace chatterino

View file

@ -4,7 +4,6 @@
#include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp"
#include "providers/recentmessages/Impl.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/PostToThread.hpp"
namespace {

View file

@ -2,9 +2,9 @@
#include "common/Env.hpp"
#include "common/QLogging.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/FormatTime.hpp"
#include <QJsonArray>

View file

@ -20,7 +20,6 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchHelpers.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Resources.hpp"
#include "singletons/Settings.hpp"
#include "singletons/StreamerMode.hpp"
@ -126,7 +125,7 @@ int stripLeadingReplyMention(const QVariantMap &tags, QString &content)
void updateReplyParticipatedStatus(const QVariantMap &tags,
const QString &senderLogin,
TwitchMessageBuilder &builder,
MessageBuilder &builder,
std::shared_ptr<MessageThread> &thread,
bool isNew)
{
@ -245,7 +244,7 @@ QMap<QString, QString> parseBadges(const QString &badgesString)
void populateReply(TwitchChannel *channel, Communi::IrcMessage *message,
const std::vector<MessagePtr> &otherLoaded,
TwitchMessageBuilder &builder)
MessageBuilder &builder)
{
const auto &tags = message->tags();
if (const auto it = tags.find("reply-thread-parent-msg-id");
@ -481,8 +480,7 @@ std::vector<MessagePtr> parseUserNoticeMessage(Channel *channel,
MessageParseArgs args;
args.trimSubscriberUsername = true;
TwitchMessageBuilder builder(channel, message, args, content,
false);
MessageBuilder builder(channel, message, args, content, false);
builder->flags.set(MessageFlag::Subscription);
builder->flags.unset(MessageFlag::Highlighted);
builtMessages.emplace_back(builder.build());
@ -566,7 +564,7 @@ std::vector<MessagePtr> parsePrivMessage(Channel *channel,
std::vector<MessagePtr> builtMessages;
MessageParseArgs args;
TwitchMessageBuilder builder(channel, message, args, message->content(),
MessageBuilder builder(channel, message, args, message->content(),
message->isAction());
if (!builder.isIgnored())
{
@ -576,7 +574,7 @@ std::vector<MessagePtr> parsePrivMessage(Channel *channel,
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
{
auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message);
auto ptr = MessageBuilder::buildHypeChatMessage(message);
if (ptr)
{
builtMessages.emplace_back(std::move(ptr));
@ -618,7 +616,7 @@ std::vector<MessagePtr> IrcMessageHandler::parseMessageWithReply(
QString content = privMsg->content();
int messageOffset = stripLeadingReplyMention(privMsg->tags(), content);
MessageParseArgs args;
TwitchMessageBuilder builder(channel, message, args, content,
MessageBuilder builder(channel, message, args, content,
privMsg->isAction());
builder.setMessageOffset(messageOffset);
@ -716,7 +714,7 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
{
auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message);
auto ptr = MessageBuilder::buildHypeChatMessage(message);
if (ptr)
{
chan->addMessage(ptr, MessageContext::Original);
@ -865,9 +863,8 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
msg->flags.set(MessageFlag::Disabled);
if (!getSettings()->hideDeletionActions)
{
MessageBuilder builder;
TwitchMessageBuilder::deletionMessage(msg, &builder);
chan->addMessage(builder.release(), MessageContext::Original);
chan->addMessage(MessageBuilder::makeDeletionMessageFromIRC(msg),
MessageContext::Original);
}
}
@ -947,7 +944,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage)
auto *c = getApp()->getTwitch()->getWhispersChannel().get();
TwitchMessageBuilder builder(
MessageBuilder builder(
c, ircMessage, args,
ircMessage->parameter(1).replace(COMBINED_FIXER, ZERO_WIDTH_JOINER),
false);
@ -1163,10 +1160,9 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
{
hostedChannelName.chop(1);
}
MessageBuilder builder;
TwitchMessageBuilder::hostingSystemMessage(hostedChannelName,
&builder, hostOn);
channel->addMessage(builder.release(), MessageContext::Original);
channel->addMessage(MessageBuilder::makeHostingSystemMessage(
hostedChannelName, hostOn),
MessageContext::Original);
}
else if (tags == "room_mods" || tags == "vips_success")
{
@ -1193,9 +1189,9 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
.mid(1) // there is a space before the first user
.split(", ");
users.sort(Qt::CaseInsensitive);
TwitchMessageBuilder::listOfUsersSystemMessage(msgParts.at(0),
users, tc, &builder);
channel->addMessage(builder.release(), MessageContext::Original);
channel->addMessage(MessageBuilder::makeListOfUsersMessage(
msgParts.at(0), users, tc),
MessageContext::Original);
}
else
{
@ -1367,7 +1363,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
QString content = originalContent;
int messageOffset = stripLeadingReplyMention(tags, content);
TwitchMessageBuilder builder(channel, message, args, content, isAction);
MessageBuilder builder(channel, message, args, content, isAction);
builder.setMessageOffset(messageOffset);
if (const auto it = tags.find("reply-thread-parent-msg-id");

View file

@ -12,6 +12,7 @@
#include "messages/Image.hpp"
#include "messages/Link.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp"
#include "messages/MessageThread.hpp"
#include "providers/bttv/BttvEmotes.hpp"
@ -31,7 +32,6 @@
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Settings.hpp"
#include "singletons/StreamerMode.hpp"
@ -311,10 +311,9 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
if (!reward.isUserInputRequired)
{
MessageBuilder builder;
TwitchMessageBuilder::appendChannelPointRewardMessage(
reward, &builder, this->isMod(), this->isBroadcaster());
this->addMessage(builder.release(), MessageContext::Original);
this->addMessage(MessageBuilder::makeChannelPointRewardMessage(
reward, this->isMod(), this->isBroadcaster()),
MessageContext::Original);
return;
}
@ -434,11 +433,11 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
});
// Channel live message
MessageBuilder builder;
TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(),
&builder);
builder.message().id = this->roomId();
this->addMessage(builder.release(), MessageContext::Original);
this->addMessage(
MessageBuilder::makeLiveMessage(
this->getDisplayName(), this->roomId(),
{MessageFlag::System, MessageFlag::DoNotTriggerNotification}),
MessageContext::Original);
}
else
{
@ -446,10 +445,9 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
<< "[TwitchChannel " << this->getName() << "] Offline";
// Channel offline message
MessageBuilder builder;
TwitchMessageBuilder::offlineSystemMessage(this->getDisplayName(),
&builder);
this->addMessage(builder.release(), MessageContext::Original);
this->addMessage(MessageBuilder::makeOfflineSystemMessage(
this->getDisplayName(), this->roomId()),
MessageContext::Original);
getApp()->getNotifications()->notifyTwitchChannelOffline(
this->roomId());
@ -1077,20 +1075,28 @@ bool TwitchChannel::tryReplaceLastLiveUpdateAddOrRemove(
// Update the message
this->lastLiveUpdateEmoteNames_.push_back(emoteName);
MessageBuilder replacement;
auto makeReplacement = [&](MessageFlag op) -> MessageBuilder {
if (op == MessageFlag::LiveUpdatesAdd)
{
replacement =
MessageBuilder(liveUpdatesAddEmoteMessage, platform,
last->loginName, this->lastLiveUpdateEmoteNames_);
}
else // op == RemoveEmoteMessage
{
replacement =
MessageBuilder(liveUpdatesRemoveEmoteMessage, platform,
last->loginName, this->lastLiveUpdateEmoteNames_);
return {
liveUpdatesAddEmoteMessage,
platform,
last->loginName,
this->lastLiveUpdateEmoteNames_,
};
}
// op == RemoveEmoteMessage
return {
liveUpdatesRemoveEmoteMessage,
platform,
last->loginName,
this->lastLiveUpdateEmoteNames_,
};
};
auto replacement = makeReplacement(op);
replacement->flags = last->flags;
auto msg = replacement.release();

View file

@ -458,7 +458,7 @@ private:
std::vector<boost::signals2::scoped_connection> bSignals_;
friend class TwitchIrcServer;
friend class TwitchMessageBuilder;
friend class MessageBuilder;
friend class IrcMessageHandler;
friend class Commands_E2E_Test;
};

File diff suppressed because it is too large Load diff

View file

@ -1,166 +0,0 @@
#pragma once
#include "common/Aliases.hpp"
#include "common/Outcome.hpp"
#include "messages/SharedMessageBuilder.hpp"
#include "pubsubmessages/LowTrustUsers.hpp"
#include <IrcMessage>
#include <QString>
#include <QVariant>
#include <optional>
#include <unordered_map>
namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class Channel;
class TwitchChannel;
class MessageThread;
class IgnorePhrase;
struct HelixVip;
using HelixModerator = HelixVip;
struct ChannelPointReward;
struct DeleteAction;
struct TwitchEmoteOccurrence {
int start;
int end;
EmotePtr ptr;
EmoteName name;
bool operator==(const TwitchEmoteOccurrence &other) const
{
return std::tie(this->start, this->end, this->ptr, this->name) ==
std::tie(other.start, other.end, other.ptr, other.name);
}
};
class TwitchMessageBuilder : public SharedMessageBuilder
{
public:
TwitchMessageBuilder() = delete;
explicit TwitchMessageBuilder(Channel *_channel,
const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args);
explicit TwitchMessageBuilder(Channel *_channel,
const Communi::IrcMessage *_ircMessage,
const MessageParseArgs &_args,
QString content, bool isAction);
TwitchChannel *twitchChannel;
[[nodiscard]] bool isIgnored() const override;
bool isIgnoredReply() const;
void triggerHighlights() override;
MessagePtr build() override;
void setThread(std::shared_ptr<MessageThread> thread);
void setParent(MessagePtr parent);
void setMessageOffset(int offset);
static void appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster);
// Message in the /live chat for channel going live
static void liveMessage(const QString &channelName,
MessageBuilder *builder);
// Messages in normal chat for channel stuff
static void liveSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void offlineSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void hostingSystemMessage(const QString &channelName,
MessageBuilder *builder, bool hostOn);
static void deletionMessage(const MessagePtr originalMessage,
MessageBuilder *builder);
static void deletionMessage(const DeleteAction &action,
MessageBuilder *builder);
static void listOfUsersSystemMessage(QString prefix, QStringList users,
Channel *channel,
MessageBuilder *builder);
static void listOfUsersSystemMessage(
QString prefix, const std::vector<HelixModerator> &users,
Channel *channel, MessageBuilder *builder);
static MessagePtr buildHypeChatMessage(Communi::IrcPrivateMessage *message);
static std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
const AutomodAction &action, const QString &channelName);
static MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action);
static std::pair<MessagePtr, MessagePtr> makeLowTrustUserMessage(
const PubSubLowTrustUsersMessage &action, const QString &channelName,
const TwitchChannel *twitchChannel);
static MessagePtr makeLowTrustUpdateMessage(
const PubSubLowTrustUsersMessage &action);
// Shares some common logic from SharedMessageBuilder::parseBadgeTag
static std::unordered_map<QString, QString> parseBadgeInfoTag(
const QVariantMap &tags);
static std::vector<TwitchEmoteOccurrence> parseTwitchEmotes(
const QVariantMap &tags, const QString &originalMessage,
int messageOffset);
static void processIgnorePhrases(
const std::vector<IgnorePhrase> &phrases, QString &originalMessage,
std::vector<TwitchEmoteOccurrence> &twitchEmotes);
private:
void parseUsernameColor() override;
void parseUsername() override;
void parseMessageID();
void parseRoomID();
// Parse & build thread information into the message
// Will read information from thread_ or from IRC tags
void parseThread();
void appendUsername();
Outcome tryAppendEmote(const EmoteName &name) override;
void addWords(const QStringList &words,
const std::vector<TwitchEmoteOccurrence> &twitchEmotes);
void addTextOrEmoji(EmotePtr emote) override;
void addTextOrEmoji(const QString &value) override;
void appendTwitchBadges();
void appendChatterinoBadges();
void appendFfzBadges();
void appendSeventvBadges();
Outcome tryParseCheermote(const QString &string);
bool shouldAddModerationElements() const;
QString roomID_;
bool hasBits_ = false;
QString bits;
int bitsLeft{};
bool bitsStacked = false;
bool historicalMessage_ = false;
std::shared_ptr<MessageThread> thread_;
MessagePtr parent_;
/**
* Starting offset to be used on index-based operations on `originalMessage_`.
*
* For example:
* originalMessage_ = "there"
* messageOffset_ = 4
* (the irc message is "hey there")
*
* then the index 6 would resolve to 6 - 4 = 2 => 'e'
*/
int messageOffset_ = 0;
QString userId_;
bool senderIsBroadcaster{};
};
} // namespace chatterino

View file

@ -7,7 +7,6 @@
#include "common/QLogging.hpp"
#include "debug/Benchmark.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "util/CombinePath.hpp"

View file

@ -6,6 +6,7 @@
#include <cmath>
#include <optional>
#include <utility>
#include <vector>
namespace chatterino {

View file

@ -97,4 +97,17 @@ inline QDateTime calculateMessageTime(const Communi::IrcMessage *message)
return QDateTime::currentDateTime();
}
// "foo/bar/baz,tri/hard" can be a valid badge-info tag
// In that case, valid map content should be 'split by slash' only once:
// {"foo": "bar/baz", "tri": "hard"}
inline std::pair<QString, QString> slashKeyValue(const QString &kvStr)
{
return {
// part before first slash (index 0 of section)
kvStr.section('/', 0, 0),
// part after first slash (index 1 of section)
kvStr.section('/', 1, -1),
};
}
} // namespace chatterino

View file

@ -15,7 +15,6 @@
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/ImageUploader.hpp"
#include "singletons/Settings.hpp"

View file

@ -22,7 +22,7 @@ set(test_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/UtilTwitch.cpp
${CMAKE_CURRENT_LIST_DIR}/src/IrcHelpers.cpp
${CMAKE_CURRENT_LIST_DIR}/src/TwitchPubSubClient.cpp
${CMAKE_CURRENT_LIST_DIR}/src/TwitchMessageBuilder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/MessageBuilder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/HighlightController.cpp
${CMAKE_CURRENT_LIST_DIR}/src/FormatTime.cpp
${CMAKE_CURRENT_LIST_DIR}/src/LimitedQueue.cpp

View file

@ -3,6 +3,7 @@
#include "controllers/filters/lang/Filter.hpp"
#include "controllers/filters/lang/Types.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "messages/MessageBuilder.hpp"
#include "mocks/Channel.hpp"
#include "mocks/ChatterinoBadges.hpp"
#include "mocks/EmptyApplication.hpp"
@ -11,7 +12,6 @@
#include "providers/ffz/FfzBadges.hpp"
#include "providers/seventv/SeventvBadges.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/Emotes.hpp"
#include "Test.hpp"
@ -280,7 +280,7 @@ TEST_F(FiltersF, TypingContextChecks)
QString originalMessage = privmsg->content();
TwitchMessageBuilder builder(&channel, privmsg, MessageParseArgs{});
MessageBuilder builder(&channel, privmsg, MessageParseArgs{});
auto msg = builder.build();
EXPECT_NE(msg.get(), nullptr);

View file

@ -1,10 +1,8 @@
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "messages/MessageBuilder.hpp"
#include "common/Channel.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "messages/MessageBuilder.hpp"
#include "mocks/Channel.hpp"
#include "mocks/ChatterinoBadges.hpp"
#include "mocks/DisabledStreamerMode.hpp"
@ -16,6 +14,7 @@
#include "providers/twitch/TwitchBadge.hpp"
#include "singletons/Emotes.hpp"
#include "Test.hpp"
#include "util/IrcHelpers.hpp"
#include <IrcConnection>
#include <QDebug>
@ -115,7 +114,7 @@ public:
} // namespace
TEST(TwitchMessageBuilder, CommaSeparatedListTagParsing)
TEST(MessageBuilder, CommaSeparatedListTagParsing)
{
struct TestCase {
QString input;
@ -151,14 +150,14 @@ TEST(TwitchMessageBuilder, CommaSeparatedListTagParsing)
for (const auto &test : testCases)
{
auto output = TwitchMessageBuilder::slashKeyValue(test.input);
auto output = slashKeyValue(test.input);
EXPECT_EQ(output, test.expectedOutput)
<< "Input " << test.input << " failed";
}
}
class TestTwitchMessageBuilder : public ::testing::Test
class TestMessageBuilder : public ::testing::Test
{
protected:
void SetUp() override
@ -174,7 +173,7 @@ protected:
std::unique_ptr<MockApplication> mockApplication;
};
TEST(TwitchMessageBuilder, BadgeInfoParsing)
TEST(MessageBuilder, BadgeInfoParsing)
{
struct TestCase {
QByteArray input;
@ -235,12 +234,11 @@ TEST(TwitchMessageBuilder, BadgeInfoParsing)
Communi::IrcPrivateMessage::fromData(test.input, nullptr);
auto outputBadgeInfo =
TwitchMessageBuilder::parseBadgeInfoTag(privmsg->tags());
MessageBuilder::parseBadgeInfoTag(privmsg->tags());
EXPECT_EQ(outputBadgeInfo, test.expectedBadgeInfo)
<< "Input for badgeInfo " << test.input << " failed";
auto outputBadges =
SharedMessageBuilder::parseBadgeTag(privmsg->tags());
auto outputBadges = MessageBuilder::parseBadgeTag(privmsg->tags());
EXPECT_EQ(outputBadges, test.expectedBadges)
<< "Input for badges " << test.input << " failed";
@ -248,7 +246,7 @@ TEST(TwitchMessageBuilder, BadgeInfoParsing)
}
}
TEST_F(TestTwitchMessageBuilder, ParseTwitchEmotes)
TEST_F(TestMessageBuilder, ParseTwitchEmotes)
{
struct TestCase {
QByteArray input;
@ -416,7 +414,7 @@ TEST_F(TestTwitchMessageBuilder, ParseTwitchEmotes)
QString originalMessage = privmsg->content();
// TODO: Add tests with replies
auto actualTwitchEmotes = TwitchMessageBuilder::parseTwitchEmotes(
auto actualTwitchEmotes = MessageBuilder::parseTwitchEmotes(
privmsg->tags(), originalMessage, 0);
EXPECT_EQ(actualTwitchEmotes, test.expectedTwitchEmotes)
@ -426,7 +424,7 @@ TEST_F(TestTwitchMessageBuilder, ParseTwitchEmotes)
}
}
TEST_F(TestTwitchMessageBuilder, ParseMessage)
TEST_F(TestMessageBuilder, ParseMessage)
{
MockChannel channel("pajlada");
@ -484,7 +482,7 @@ TEST_F(TestTwitchMessageBuilder, ParseMessage)
QString originalMessage = privmsg->content();
TwitchMessageBuilder builder(&channel, privmsg, MessageParseArgs{});
MessageBuilder builder(&channel, privmsg, MessageParseArgs{});
auto msg = builder.build();
EXPECT_NE(msg.get(), nullptr);
@ -493,7 +491,7 @@ TEST_F(TestTwitchMessageBuilder, ParseMessage)
}
}
TEST_F(TestTwitchMessageBuilder, IgnoresReplace)
TEST_F(TestMessageBuilder, IgnoresReplace)
{
struct TestCase {
std::vector<IgnorePhrase> phrases;
@ -619,8 +617,7 @@ TEST_F(TestTwitchMessageBuilder, IgnoresReplace)
{
auto message = test.input;
auto emotes = test.twitchEmotes;
TwitchMessageBuilder::processIgnorePhrases(test.phrases, message,
emotes);
MessageBuilder::processIgnorePhrases(test.phrases, message, emotes);
EXPECT_EQ(message, test.expectedMessage)
<< "Message not equal for input '" << test.input