Skip to content

Commit

Permalink
Handle ritual (new viewer announcement) messages (#2703)
Browse files Browse the repository at this point in the history
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
  • Loading branch information
zneix and pajlada authored May 1, 2021
1 parent 115d198 commit b614ce1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Bugfix: Added missing Copy/Open link context menu entries to emotes in Emote Picker. (#2670)
- Bugfix: Fixed visual glitch with smooth scrolling. (#2084)
- Bugfix: Clicking on split header focuses its split. (#2720)
- Bugfix: Handle new user messages ("rituals") properly. (#2703)

## 2.3.0

Expand Down
29 changes: 16 additions & 13 deletions src/providers/twitch/IrcMessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@

namespace {
using namespace chatterino;

// Message types below are the ones that might contain special user's message on USERNOTICE
static const QSet<QString> specialMessageTypes{
"sub", //
"subgift", //
"resub", // resub messages
"bitsbadgetier", // bits badge upgrade
"ritual", // new viewer ritual
};

MessagePtr generateBannedMessage(bool confirmedBan)
{
const auto linkColor = MessageColor(MessageColor::Link);
Expand Down Expand Up @@ -561,24 +571,19 @@ std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(
{
std::vector<MessagePtr> builtMessages;

auto data = message->toData();

auto tags = message->tags();
auto parameters = message->parameters();

auto target = parameters[0];
QString msgType = tags.value("msg-id", "").toString();
QString content;
if (parameters.size() >= 2)
{
content = parameters[1];
}

if (msgType == "sub" || msgType == "resub" || msgType == "subgift" ||
msgType == "bitsbadgetier")
if (specialMessageTypes.contains(msgType))
{
// Sub-specific and bits badge upgrade specific message.
// It's only allowed for "resub" messages.
// Messages are not required, so they might be empty
if (!content.isEmpty())
{
MessageParseArgs args;
Expand All @@ -596,6 +601,7 @@ std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(

if (it != tags.end())
{
// By default, we return value of system-msg tag
QString messageText = it.value().toString();

if (msgType == "bitsbadgetier")
Expand All @@ -620,8 +626,6 @@ std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
TwitchIrcServer &server)
{
auto data = message->toData();

auto tags = message->tags();
auto parameters = message->parameters();

Expand All @@ -633,11 +637,9 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
content = parameters[1];
}

if (msgType == "sub" || msgType == "resub" || msgType == "subgift" ||
msgType == "bitsbadgetier")
if (specialMessageTypes.contains(msgType))
{
// Sub-specific and bits badge upgrade specific message.
// It's only allowed for "resub" messages.
// Messages are not required, so they might be empty
if (!content.isEmpty())
{
this->addMessage(message, target, content, server, true, false);
Expand All @@ -648,6 +650,7 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,

if (it != tags.end())
{
// By default, we return value of system-msg tag
QString messageText = it.value().toString();

if (msgType == "bitsbadgetier")
Expand Down

0 comments on commit b614ce1

Please sign in to comment.