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