mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
renamed template method from "append" to "emplace"
to be in line with the std library naming scheme
This commit is contained in:
parent
0febffc6d8
commit
135f9910f8
|
@ -22,7 +22,7 @@ public:
|
|||
// typename std::enable_if<std::is_base_of<MessageElement, T>::value, T>::type
|
||||
|
||||
template <class T, class... Args>
|
||||
T *append(Args &&... args)
|
||||
T *emplace(Args &&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<MessageElement, T>::value, "T must extend MessageElement");
|
||||
|
||||
|
|
|
@ -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<TimestampElement>(dateTime.time());
|
||||
this->emplace<TimestampElement>(dateTime.time());
|
||||
} else {
|
||||
this->append<TimestampElement>();
|
||||
this->emplace<TimestampElement>();
|
||||
}
|
||||
|
||||
this->parseMessageID();
|
||||
|
@ -63,7 +63,7 @@ MessagePtr TwitchMessageBuilder::parse()
|
|||
this->parseRoomID();
|
||||
|
||||
// TIMESTAMP
|
||||
this->append<TwitchModerationElement>();
|
||||
this->emplace<TwitchModerationElement>();
|
||||
|
||||
this->parseTwitchBadges();
|
||||
|
||||
|
@ -123,7 +123,7 @@ MessagePtr TwitchMessageBuilder::parse()
|
|||
// twitch emote
|
||||
if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) {
|
||||
auto emoteImage = currentTwitchEmote->second;
|
||||
this->append<EmoteElement>(emoteImage, MessageElement::TwitchEmote);
|
||||
this->emplace<EmoteElement>(emoteImage, MessageElement::TwitchEmote);
|
||||
|
||||
i += split.length() + 1;
|
||||
currentTwitchEmote = std::next(currentTwitchEmote);
|
||||
|
@ -170,10 +170,10 @@ MessagePtr TwitchMessageBuilder::parse()
|
|||
textColor = MessageColor(MessageColor::Link);
|
||||
}
|
||||
|
||||
this->append<TextElement>(string, EmoteElement::Text) //
|
||||
this->emplace<TextElement>(string, EmoteElement::Text) //
|
||||
->setLink(link);
|
||||
} else { // is emoji
|
||||
this->append<EmoteElement>(emoteData, EmoteElement::EmojiAll);
|
||||
this->emplace<EmoteElement>(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<TextElement>(channelName, MessageElement::ChannelName, MessageColor::System) //
|
||||
this->emplace<TextElement>(channelName, MessageElement::ChannelName, MessageColor::System) //
|
||||
->setLink(link);
|
||||
}
|
||||
|
||||
|
@ -312,8 +312,8 @@ void TwitchMessageBuilder::appendUsername()
|
|||
usernameText += ":";
|
||||
}
|
||||
|
||||
this->append<TextElement>(usernameText, MessageElement::Text, this->usernameColor,
|
||||
FontStyle::MediumBold)
|
||||
this->emplace<TextElement>(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<EmoteElement>(emoteData, MessageElement::BttvEmote);
|
||||
this->emplace<EmoteElement>(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<ImageElement>(badge.badgeImage1x, MessageElement::BadgeVanity);
|
||||
this->emplace<ImageElement>(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<ImageElement>(badge.badgeImage1x, MessageElement::BadgeVanity);
|
||||
this->emplace<ImageElement>(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<ImageElement>(resourceManager.badgeStaff,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(resourceManager.badgeStaff,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Staff");
|
||||
} else if (badge == "admin/1") {
|
||||
this->append<ImageElement>(resourceManager.badgeAdmin,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(resourceManager.badgeAdmin,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Admin");
|
||||
} else if (badge == "global_mod/1") {
|
||||
this->append<ImageElement>(resourceManager.badgeGlobalModerator,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(resourceManager.badgeGlobalModerator,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Global Moderator");
|
||||
} else if (badge == "moderator/1") {
|
||||
// TODO: Implement custom FFZ moderator badge
|
||||
this->append<ImageElement>(resourceManager.badgeModerator,
|
||||
MessageElement::BadgeChannelAuthority)
|
||||
this->emplace<ImageElement>(resourceManager.badgeModerator,
|
||||
MessageElement::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Channel Moderator");
|
||||
} else if (badge == "turbo/1") {
|
||||
this->append<ImageElement>(resourceManager.badgeTurbo,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(resourceManager.badgeTurbo,
|
||||
MessageElement::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Turbo Subscriber");
|
||||
} else if (badge == "broadcaster/1") {
|
||||
this->append<ImageElement>(resourceManager.badgeBroadcaster,
|
||||
MessageElement::BadgeChannelAuthority)
|
||||
this->emplace<ImageElement>(resourceManager.badgeBroadcaster,
|
||||
MessageElement::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Broadcaster");
|
||||
} else if (badge == "premium/1") {
|
||||
this->append<ImageElement>(resourceManager.badgePremium, MessageElement::BadgeVanity)
|
||||
this->emplace<ImageElement>(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<ImageElement>(resourceManager.badgeVerified,
|
||||
MessageElement::BadgeVanity)
|
||||
this->emplace<ImageElement>(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<ImageElement>(resourceManager.badgeSubscriber,
|
||||
MessageElement::BadgeSubscription)
|
||||
this->emplace<ImageElement>(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<ImageElement>(resourceManager.badgeSubscriber,
|
||||
MessageElement::BadgeSubscription)
|
||||
this->emplace<ImageElement>(resourceManager.badgeSubscriber,
|
||||
MessageElement::BadgeSubscription)
|
||||
->setTooltip("Twitch Subscriber");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto &badgeVersion = badgeVersionIt->second;
|
||||
|
||||
this->append<ImageElement>(badgeVersion.badgeImage1x, MessageElement::BadgeSubscription)
|
||||
this->emplace<ImageElement>(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<ImageElement>(badgeVersion.badgeImage1x, badgeType)
|
||||
this->emplace<ImageElement>(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<ImageElement>(badge->image, MessageElement::BadgeChatterino)
|
||||
this->emplace<ImageElement>(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<EmoteElement>(cheermote.emoteDataAnimated, EmoteElement::BitsAnimated);
|
||||
this->append<TextElement>(amount, EmoteElement::Text, cheermote.color);
|
||||
this->emplace<EmoteElement>(cheermote.emoteDataAnimated, EmoteElement::BitsAnimated);
|
||||
this->emplace<TextElement>(amount, EmoteElement::Text, cheermote.color);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -701,6 +702,5 @@ bool TwitchMessageBuilder::tryParseCheermote(const QString &string)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace chatterino
|
||||
|
|
Loading…
Reference in a new issue