diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index b6d627d8b..b68c393f7 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -226,72 +226,7 @@ MessagePtr TwitchMessageBuilder::build() } // reply threads - if (this->thread_) - { - // set references - this->message().replyThread = this->thread_; - this->thread_->addToThread(this->weakOf()); - - // enable reply flag - this->message().flags.set(MessageFlag::ReplyMessage); - - const auto &threadRoot = this->thread_->root(); - - QString usernameText = SharedMessageBuilder::stylizeUsername( - threadRoot->loginName, *threadRoot.get()); - - this->emplace(); - - // construct reply elements - this->emplace( - "Replying to", MessageElementFlag::RepliedMessage, - MessageColor::System, FontStyle::ChatMediumSmall) - ->setLink({Link::ViewThread, this->thread_->rootId()}); - - this->emplace( - "@" + usernameText + ":", MessageElementFlag::RepliedMessage, - threadRoot->usernameColor, FontStyle::ChatMediumSmall) - ->setLink({Link::UserInfo, threadRoot->displayName}); - - this->emplace( - threadRoot->messageText, - MessageElementFlags({MessageElementFlag::RepliedMessage, - MessageElementFlag::Text}), - this->textColor_, FontStyle::ChatMediumSmall) - ->setLink({Link::ViewThread, this->thread_->rootId()}); - } - else if (this->tags.find("reply-parent-msg-id") != this->tags.end()) - { - // Message is a reply but we couldn't find the original message. - // Render the message using the additional reply tags - - auto replyDisplayName = this->tags.find("reply-parent-display-name"); - auto replyBody = this->tags.find("reply-parent-msg-body"); - - if (replyDisplayName != this->tags.end() && - replyBody != this->tags.end()) - { - auto name = replyDisplayName->toString(); - auto body = parseTagString(replyBody->toString()); - - this->emplace(); - - this->emplace( - "Replying to", MessageElementFlag::RepliedMessage, - MessageColor::System, FontStyle::ChatMediumSmall); - - this->emplace( - "@" + name + ":", MessageElementFlag::RepliedMessage, - this->textColor_, FontStyle::ChatMediumSmall) - ->setLink({Link::UserInfo, name}); - - this->emplace( - body, - MessageElementFlags({MessageElementFlag::RepliedMessage, - MessageElementFlag::Text}), - this->textColor_, FontStyle::ChatMediumSmall); - } - } + this->parseThread(); // timestamp this->message().serverReceivedTime = calculateMessageTime(this->ircMessage); @@ -634,6 +569,76 @@ void TwitchMessageBuilder::parseRoomID() } } +void TwitchMessageBuilder::parseThread() +{ + if (this->thread_) + { + // set references + this->message().replyThread = this->thread_; + this->thread_->addToThread(this->weakOf()); + + // enable reply flag + this->message().flags.set(MessageFlag::ReplyMessage); + + const auto &threadRoot = this->thread_->root(); + + QString usernameText = SharedMessageBuilder::stylizeUsername( + threadRoot->loginName, *threadRoot.get()); + + this->emplace(); + + // construct reply elements + this->emplace( + "Replying to", MessageElementFlag::RepliedMessage, + MessageColor::System, FontStyle::ChatMediumSmall) + ->setLink({Link::ViewThread, this->thread_->rootId()}); + + this->emplace( + "@" + usernameText + ":", MessageElementFlag::RepliedMessage, + threadRoot->usernameColor, FontStyle::ChatMediumSmall) + ->setLink({Link::UserInfo, threadRoot->displayName}); + + this->emplace( + threadRoot->messageText, + MessageElementFlags({MessageElementFlag::RepliedMessage, + MessageElementFlag::Text}), + this->textColor_, FontStyle::ChatMediumSmall) + ->setLink({Link::ViewThread, this->thread_->rootId()}); + } + else if (this->tags.find("reply-parent-msg-id") != this->tags.end()) + { + // Message is a reply but we couldn't find the original message. + // Render the message using the additional reply tags + + auto replyDisplayName = this->tags.find("reply-parent-display-name"); + auto replyBody = this->tags.find("reply-parent-msg-body"); + + if (replyDisplayName != this->tags.end() && + replyBody != this->tags.end()) + { + auto name = replyDisplayName->toString(); + auto body = parseTagString(replyBody->toString()); + + this->emplace(); + + this->emplace( + "Replying to", MessageElementFlag::RepliedMessage, + MessageColor::System, FontStyle::ChatMediumSmall); + + this->emplace( + "@" + name + ":", MessageElementFlag::RepliedMessage, + this->textColor_, FontStyle::ChatMediumSmall) + ->setLink({Link::UserInfo, name}); + + this->emplace( + body, + MessageElementFlags({MessageElementFlag::RepliedMessage, + MessageElementFlag::Text}), + this->textColor_, FontStyle::ChatMediumSmall); + } + } +} + void TwitchMessageBuilder::parseUsernameColor() { const auto *userData = getIApp()->getUserData(); diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index 9a2415706..df1d782ba 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -95,6 +95,9 @@ private: void parseUsername() override; void parseMessageID(); void parseRoomID(); + // Parse & build thread information into the message + // Will read information from thread_ or from IRC tags + void parseThread(); void appendUsername(); void runIgnoreReplaces(std::vector &twitchEmotes);