Added clickable hosting messages (#2752)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
apa420 2021-05-08 16:46:41 +02:00 committed by GitHub
parent 2f49b23875
commit 1568de6640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 6 deletions

View file

@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Minor: Hosting messages are now clickable. (#2655)
- Minor: Messages held by automod are now shown to the user. (#2626) - Minor: Messages held by automod are now shown to the user. (#2626)
- Bugfix: Automod messages now work properly again. (#2682) - Bugfix: Automod messages now work properly again. (#2682)
- Bugfix: `Login expired` message no longer highlights all tabs. (#2735) - Bugfix: `Login expired` message no longer highlights all tabs. (#2735)

View file

@ -804,6 +804,23 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
"Usage: \"/delete <msg-id>\" - can't take more " "Usage: \"/delete <msg-id>\" - can't take more "
"than one argument")); "than one argument"));
} }
else if (tags == "host_on")
{
QStringList parts = msg->messageText.split(QLatin1Char(' '));
if (parts.size() != 3)
{
return;
}
auto &channelName = parts[2];
if (channelName.size() < 2)
{
return;
}
channelName.chop(1);
MessageBuilder builder;
TwitchMessageBuilder::hostingSystemMessage(channelName, &builder);
channel->addMessage(builder.release());
}
else else
{ {
channel->addMessage(msg); channel->addMessage(msg);

View file

@ -563,15 +563,17 @@ void TwitchChannel::setLive(bool newLiveStatus)
getApp()->windows->sendAlert(); getApp()->windows->sendAlert();
} }
} }
auto live = MessageBuilder builder;
makeSystemMessage(this->getDisplayName() + " is live"); TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(),
this->addMessage(live); &builder);
this->addMessage(builder.release());
} }
else else
{ {
auto offline = MessageBuilder builder;
makeSystemMessage(this->getDisplayName() + " is offline"); TwitchMessageBuilder::offlineSystemMessage(
this->addMessage(offline); this->getDisplayName(), &builder);
this->addMessage(builder.release());
} }
guard->live = newLiveStatus; guard->live = newLiveStatus;
} }

View file

@ -1302,4 +1302,46 @@ void TwitchMessageBuilder::appendChannelPointRewardMessage(
builder->message().flags.set(MessageFlag::RedeemedChannelPointReward); builder->message().flags.set(MessageFlag::RedeemedChannelPointReward);
} }
void TwitchMessageBuilder::liveSystemMessage(const QString &channelName,
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);
}
void TwitchMessageBuilder::offlineSystemMessage(const QString &channelName,
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 now offline.", MessageElementFlag::Text,
MessageColor::System);
}
void TwitchMessageBuilder::hostingSystemMessage(const QString &channelName,
MessageBuilder *builder)
{
builder->emplace<TimestampElement>();
builder->message().flags.set(MessageFlag::System);
builder->message().flags.set(MessageFlag::DoNotTriggerNotification);
builder->emplace<TextElement>("Now hosting", MessageElementFlag::Text,
MessageColor::System);
builder
->emplace<TextElement>(channelName + ".", MessageElementFlag::Username,
MessageColor::System, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, channelName});
}
} // namespace chatterino } // namespace chatterino

View file

@ -52,6 +52,12 @@ public:
static void appendChannelPointRewardMessage( static void appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder); const ChannelPointReward &reward, MessageBuilder *builder);
static void liveSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void offlineSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void hostingSystemMessage(const QString &channelName,
MessageBuilder *builder);
private: private:
void parseUsernameColor() override; void parseUsernameColor() override;