From fb787b522645787478b79ed7021a935d0400e749 Mon Sep 17 00:00:00 2001 From: James Upjohn Date: Sat, 19 Oct 2024 11:01:22 +0000 Subject: [PATCH] feat: make raid entry username clickable (#5651) --- CHANGELOG.md | 1 + src/messages/MessageBuilder.cpp | 29 ++++++++ src/messages/MessageBuilder.hpp | 6 ++ src/providers/twitch/IrcMessageHandler.cpp | 78 +++++++++++++++++++++- 4 files changed, 113 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa0e5a5a..3c7212d43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - Minor: Added `--login ` CLI argument to specify which account to start logged in as. (#5626) - Minor: Indicate when subscriptions and resubscriptions are for multiple months. (#5642) - Minor: Proxy URL information is now included in the `/debug-env` command. (#5648) +- Minor: Make raid entry message usernames clickable. (#5651) - Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426, #5612) - Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378) - Bugfix: Fixed restricted users usernames not being clickable. (#5405) diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index e470b01ce..fca5753a8 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -461,6 +461,35 @@ MessageBuilder::MessageBuilder(SystemMessageTag, const QString &text, this->message().searchText = text; } +MessageBuilder::MessageBuilder(RaidEntryMessageTag, const QString &text, + const QString &loginName, + const QString &displayName, + const MessageColor &userColor, const QTime &time) + : MessageBuilder() +{ + this->emplace(time); + + const QStringList textFragments = + text.split(QRegularExpression("\\s"), Qt::SkipEmptyParts); + for (const auto &word : textFragments) + { + if (word == displayName) + { + this->emplace(displayName, loginName, + MessageColor::System, userColor); + continue; + } + + this->emplace(word, MessageElementFlag::Text, + MessageColor::System); + } + + this->message().flags.set(MessageFlag::System); + this->message().flags.set(MessageFlag::DoNotTriggerNotification); + this->message().messageText = text; + this->message().searchText = text; +} + MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &timeoutUser, const QString &sourceUser, const QString &systemMessageText, int times, diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index aa2933b64..b353a8bde 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -53,6 +53,8 @@ namespace linkparser { struct SystemMessageTag { }; +struct RaidEntryMessageTag { +}; struct TimeoutMessageTag { }; struct LiveUpdatesUpdateEmoteMessageTag { @@ -67,6 +69,7 @@ struct ImageUploaderResultTag { }; const SystemMessageTag systemMessage{}; +const RaidEntryMessageTag raidEntryMessage{}; const TimeoutMessageTag timeoutMessage{}; const LiveUpdatesUpdateEmoteMessageTag liveUpdatesUpdateEmoteMessage{}; const LiveUpdatesRemoveEmoteMessageTag liveUpdatesRemoveEmoteMessage{}; @@ -109,6 +112,9 @@ public: MessageBuilder(SystemMessageTag, const QString &text, const QTime &time = QTime::currentTime()); + MessageBuilder(RaidEntryMessageTag, const QString &text, + const QString &loginName, const QString &displayName, + const MessageColor &userColor, const QTime &time); MessageBuilder(TimeoutMessageTag, const QString &timeoutUser, const QString &sourceUser, const QString &systemMessageText, int times, const QTime &time = QTime::currentTime()); diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 8bac0d9fe..9724ec213 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -531,6 +531,35 @@ std::vector parseUserNoticeMessage(Channel *channel, { messageText = "Announcement"; } + else if (msgType == "raid") + { + auto login = tags.value("login").toString(); + auto displayName = tags.value("msg-param-displayName").toString(); + + if (!login.isEmpty() && !displayName.isEmpty()) + { + MessageColor color = MessageColor::System; + if (auto colorTag = tags.value("color").value(); + colorTag.isValid()) + { + color = MessageColor(colorTag); + } + + auto b = MessageBuilder( + raidEntryMessage, parseTagString(messageText), login, + displayName, color, calculateMessageTime(message).time()); + + b->flags.set(MessageFlag::Subscription); + if (mirrored) + { + b->flags.set(MessageFlag::SharedMessage); + } + + auto newMessage = b.release(); + builtMessages.emplace_back(newMessage); + return builtMessages; + } + } else if (msgType == "subgift") { if (auto monthsIt = tags.find("msg-param-gift-months"); @@ -600,12 +629,12 @@ std::vector parseUserNoticeMessage(Channel *channel, auto b = MessageBuilder(systemMessage, parseTagString(messageText), calculateMessageTime(message).time()); - b->flags.set(MessageFlag::Subscription); if (mirrored) { b->flags.set(MessageFlag::SharedMessage); } + auto newMessage = b.release(); builtMessages.emplace_back(newMessage); } @@ -1085,6 +1114,53 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, { messageText = "Announcement"; } + else if (msgType == "raid") + { + auto login = tags.value("login").toString(); + auto displayName = tags.value("msg-param-displayName").toString(); + + if (!login.isEmpty() && !displayName.isEmpty()) + { + MessageColor color = MessageColor::System; + if (auto colorTag = tags.value("color").value(); + colorTag.isValid()) + { + color = MessageColor(colorTag); + } + + auto b = MessageBuilder( + raidEntryMessage, parseTagString(messageText), login, + displayName, color, calculateMessageTime(message).time()); + + b->flags.set(MessageFlag::Subscription); + if (mirrored) + { + b->flags.set(MessageFlag::SharedMessage); + } + auto newMessage = b.release(); + + QString channelName; + + if (message->parameters().size() < 1) + { + return; + } + + if (!trimChannelName(message->parameter(0), channelName)) + { + return; + } + + auto chan = twitchServer.getChannelOrEmpty(channelName); + + if (!chan->isEmpty()) + { + chan->addMessage(newMessage, MessageContext::Original); + } + + return; + } + } else if (msgType == "subgift") { if (auto monthsIt = tags.find("msg-param-gift-months");