diff --git a/src/messages/messagebuilder.hpp b/src/messages/messagebuilder.hpp index 3cfac7636..43bc9f87b 100644 --- a/src/messages/messagebuilder.hpp +++ b/src/messages/messagebuilder.hpp @@ -22,7 +22,7 @@ public: // typename std::enable_if::value, T>::type template - T *append(Args &&... args) + T *emplace(Args &&... args) { static_assert(std::is_base_of::value, "T must extend MessageElement"); diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index 8686fac12..2e56d4cbc 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -53,9 +53,9 @@ MessagePtr TwitchMessageBuilder::parse() // This may be architecture dependent(datatype) qint64 ts = this->tags.value("tmi-sent-ts").toLongLong(); QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(ts); - this->append(dateTime.time()); + this->emplace(dateTime.time()); } else { - this->append(); + this->emplace(); } this->parseMessageID(); @@ -63,7 +63,7 @@ MessagePtr TwitchMessageBuilder::parse() this->parseRoomID(); // TIMESTAMP - this->append(); + this->emplace(); this->parseTwitchBadges(); @@ -123,7 +123,7 @@ MessagePtr TwitchMessageBuilder::parse() // twitch emote if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) { auto emoteImage = currentTwitchEmote->second; - this->append(emoteImage, MessageElement::TwitchEmote); + this->emplace(emoteImage, MessageElement::TwitchEmote); i += split.length() + 1; currentTwitchEmote = std::next(currentTwitchEmote); @@ -170,10 +170,10 @@ MessagePtr TwitchMessageBuilder::parse() textColor = MessageColor(MessageColor::Link); } - this->append(string, EmoteElement::Text) // + this->emplace(string, EmoteElement::Text) // ->setLink(link); } else { // is emoji - this->append(emoteData, EmoteElement::EmojiAll); + this->emplace(emoteData, EmoteElement::EmojiAll); } } @@ -224,7 +224,7 @@ void TwitchMessageBuilder::parseChannelName() QString channelName("#" + this->channel->name); Link link(Link::Url, this->channel->name + "\n" + this->messageID); - this->append(channelName, MessageElement::ChannelName, MessageColor::System) // + this->emplace(channelName, MessageElement::ChannelName, MessageColor::System) // ->setLink(link); } @@ -312,8 +312,8 @@ void TwitchMessageBuilder::appendUsername() usernameText += ":"; } - this->append(usernameText, MessageElement::Text, this->usernameColor, - FontStyle::MediumBold) + this->emplace(usernameText, MessageElement::Text, this->usernameColor, + FontStyle::MediumBold) ->setLink({Link::UserInfo, this->userName}); } @@ -474,7 +474,7 @@ bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString) bool TwitchMessageBuilder::appendEmote(const util::EmoteData &emoteData) { - this->append(emoteData, MessageElement::BttvEmote); + this->emplace(emoteData, MessageElement::BttvEmote); // Perhaps check for ignored emotes here? return true; @@ -513,7 +513,7 @@ void TwitchMessageBuilder::parseTwitchBadges() // Try to fetch channel-specific bit badge try { const auto &badge = channelResources.badgeSets.at("bits").versions.at(versionKey); - this->append(badge.badgeImage1x, MessageElement::BadgeVanity); + this->emplace(badge.badgeImage1x, MessageElement::BadgeVanity); continue; } catch (const std::out_of_range &) { // Channel does not contain a special bit badge for this version @@ -522,45 +522,45 @@ void TwitchMessageBuilder::parseTwitchBadges() // Use default bit badge try { const auto &badge = resourceManager.badgeSets.at("bits").versions.at(versionKey); - this->append(badge.badgeImage1x, MessageElement::BadgeVanity); + this->emplace(badge.badgeImage1x, MessageElement::BadgeVanity); } catch (const std::out_of_range &) { debug::Log("No default bit badge for version {} found", versionKey); continue; } } else if (badge == "staff/1") { - this->append(resourceManager.badgeStaff, - MessageElement::BadgeGlobalAuthority) + this->emplace(resourceManager.badgeStaff, + MessageElement::BadgeGlobalAuthority) ->setTooltip("Twitch Staff"); } else if (badge == "admin/1") { - this->append(resourceManager.badgeAdmin, - MessageElement::BadgeGlobalAuthority) + this->emplace(resourceManager.badgeAdmin, + MessageElement::BadgeGlobalAuthority) ->setTooltip("Twitch Admin"); } else if (badge == "global_mod/1") { - this->append(resourceManager.badgeGlobalModerator, - MessageElement::BadgeGlobalAuthority) + this->emplace(resourceManager.badgeGlobalModerator, + MessageElement::BadgeGlobalAuthority) ->setTooltip("Twitch Global Moderator"); } else if (badge == "moderator/1") { // TODO: Implement custom FFZ moderator badge - this->append(resourceManager.badgeModerator, - MessageElement::BadgeChannelAuthority) + this->emplace(resourceManager.badgeModerator, + MessageElement::BadgeChannelAuthority) ->setTooltip("Twitch Channel Moderator"); } else if (badge == "turbo/1") { - this->append(resourceManager.badgeTurbo, - MessageElement::BadgeGlobalAuthority) + this->emplace(resourceManager.badgeTurbo, + MessageElement::BadgeGlobalAuthority) ->setTooltip("Twitch Turbo Subscriber"); } else if (badge == "broadcaster/1") { - this->append(resourceManager.badgeBroadcaster, - MessageElement::BadgeChannelAuthority) + this->emplace(resourceManager.badgeBroadcaster, + MessageElement::BadgeChannelAuthority) ->setTooltip("Twitch Broadcaster"); } else if (badge == "premium/1") { - this->append(resourceManager.badgePremium, MessageElement::BadgeVanity) + this->emplace(resourceManager.badgePremium, MessageElement::BadgeVanity) ->setTooltip("Twitch Prime Subscriber"); } else if (badge.startsWith("partner/")) { int index = badge.midRef(8).toInt(); switch (index) { case 1: { - this->append(resourceManager.badgeVerified, - MessageElement::BadgeVanity) + this->emplace(resourceManager.badgeVerified, + MessageElement::BadgeVanity) ->setTooltip("Twitch Verified"); } break; default: { @@ -576,8 +576,8 @@ void TwitchMessageBuilder::parseTwitchBadges() auto badgeSetIt = channelResources.badgeSets.find("subscriber"); if (badgeSetIt == channelResources.badgeSets.end()) { // Fall back to default badge - this->append(resourceManager.badgeSubscriber, - MessageElement::BadgeSubscription) + this->emplace(resourceManager.badgeSubscriber, + MessageElement::BadgeSubscription) ->setTooltip("Twitch Subscriber"); continue; } @@ -590,15 +590,16 @@ void TwitchMessageBuilder::parseTwitchBadges() if (badgeVersionIt == badgeSet.versions.end()) { // Fall back to default badge - this->append(resourceManager.badgeSubscriber, - MessageElement::BadgeSubscription) + this->emplace(resourceManager.badgeSubscriber, + MessageElement::BadgeSubscription) ->setTooltip("Twitch Subscriber"); continue; } auto &badgeVersion = badgeVersionIt->second; - this->append(badgeVersion.badgeImage1x, MessageElement::BadgeSubscription) + this->emplace(badgeVersion.badgeImage1x, + MessageElement::BadgeSubscription) ->setTooltip("Twitch " + QString::fromStdString(badgeVersion.title)); } else { if (!resourceManager.dynamicBadgesLoaded) { @@ -624,7 +625,7 @@ void TwitchMessageBuilder::parseTwitchBadges() try { auto &badgeVersion = badgeSet.versions.at(versionKey); - this->append(badgeVersion.badgeImage1x, badgeType) + this->emplace(badgeVersion.badgeImage1x, badgeType) ->setTooltip("Twitch " + QString::fromStdString(badgeVersion.title)); } catch (const std::exception &e) { qDebug() << "Exception caught:" << e.what() @@ -649,7 +650,7 @@ void TwitchMessageBuilder::addChatterinoBadges() const auto badge = it->second; - this->append(badge->image, MessageElement::BadgeChatterino) + this->emplace(badge->image, MessageElement::BadgeChatterino) ->setTooltip(QString::fromStdString(badge->tooltip)); } @@ -692,8 +693,8 @@ bool TwitchMessageBuilder::tryParseCheermote(const QString &string) const auto &cheermote = *savedIt; - this->append(cheermote.emoteDataAnimated, EmoteElement::BitsAnimated); - this->append(amount, EmoteElement::Text, cheermote.color); + this->emplace(cheermote.emoteDataAnimated, EmoteElement::BitsAnimated); + this->emplace(amount, EmoteElement::Text, cheermote.color); return true; } @@ -701,6 +702,5 @@ bool TwitchMessageBuilder::tryParseCheermote(const QString &string) return false; } - } // namespace twitch } // namespace chatterino