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
- Minor: Hosting messages are now clickable. (#2655)
- Minor: Messages held by automod are now shown to the user. (#2626)
- Bugfix: Automod messages now work properly again. (#2682)
- 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 "
"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
{
channel->addMessage(msg);

View file

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

View file

@ -1302,4 +1302,46 @@ void TwitchMessageBuilder::appendChannelPointRewardMessage(
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

View file

@ -52,6 +52,12 @@ public:
static void appendChannelPointRewardMessage(
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:
void parseUsernameColor() override;