Skip to content

Commit

Permalink
Combine makeLiveMessage and makeLiveSystemMessage into one function
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Aug 18, 2024
1 parent 696d948 commit 03f7245
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
26 changes: 6 additions & 20 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,8 @@ MessagePtr MessageBuilder::makeChannelPointRewardMessage(
}

MessagePtr MessageBuilder::makeLiveMessage(const QString &channelName,
const QString &channelID)
const QString &channelID,
MessageFlags extraFlags)
{
MessageBuilder builder;

Expand All @@ -1491,26 +1492,11 @@ MessagePtr MessageBuilder::makeLiveMessage(const QString &channelName,
builder.message().searchText = text;
builder.message().id = channelID;

return builder.release();
}
if (!extraFlags.isEmpty())
{
builder.message().flags.set(extraFlags);
}

MessagePtr MessageBuilder::makeLiveSystemMessage(const QString &channelName,
const QString &channelID)
{
MessageBuilder builder;
builder.emplace<TimestampElement>();
builder.message().flags.set(MessageFlag::System);
builder.message().flags.set(MessageFlag::DoNotTriggerNotification);
builder
.emplace<TextElement>(channelName, MessageElementFlag::Username,
MessageColor::System, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, channelName});
builder.emplace<TextElement>("is live!", MessageElementFlag::Text,
MessageColor::System);
auto text = QString("%1 is live!").arg(channelName);
builder.message().messageText = text;
builder.message().searchText = text;
builder.message().id = channelID;
return builder.release();
}

Expand Down
8 changes: 4 additions & 4 deletions src/messages/MessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "common/Aliases.hpp"
#include "common/Outcome.hpp"
#include "messages/MessageColor.hpp"
#include "messages/MessageFlag.hpp"
#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp"

#include <IrcMessage>
Expand Down Expand Up @@ -199,13 +200,12 @@ class MessageBuilder
static MessagePtr makeChannelPointRewardMessage(
const ChannelPointReward &reward, bool isMod, bool isBroadcaster);

// Message in the /live chat for channel going live
/// Make a "CHANNEL_NAME has gone live!" message
static MessagePtr makeLiveMessage(const QString &channelName,
const QString &channelID);
const QString &channelID,
MessageFlags extraFlags = {});

// Messages in normal chat for channel stuff
static MessagePtr makeLiveSystemMessage(const QString &channelName,
const QString &channelID);
static MessagePtr makeOfflineSystemMessage(const QString &channelName,
const QString &channelID);
static MessagePtr makeHostingSystemMessage(const QString &channelName,
Expand Down
8 changes: 5 additions & 3 deletions src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,11 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
});

// Channel live message
this->addMessage(MessageBuilder::makeLiveSystemMessage(
this->getDisplayName(), this->roomId()),
MessageContext::Original);
this->addMessage(
MessageBuilder::makeLiveMessage(
this->getDisplayName(), this->roomId(),
{MessageFlag::System, MessageFlag::DoNotTriggerNotification}),
MessageContext::Original);
}
else
{
Expand Down

0 comments on commit 03f7245

Please sign in to comment.