mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
clangformat
This commit is contained in:
parent
4eefeb80e7
commit
6ca4f661a7
|
@ -26,9 +26,9 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
||||
const Communi::IrcPrivateMessage *_ircMessage,
|
||||
const MessageParseArgs &_args)
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(
|
||||
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
||||
const MessageParseArgs &_args)
|
||||
: channel(_channel)
|
||||
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
||||
, ircMessage(_ircMessage)
|
||||
|
@ -40,10 +40,9 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
|||
this->usernameColor_ = getApp()->themes->messages.textColors.system;
|
||||
}
|
||||
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
||||
const Communi::IrcMessage *_ircMessage,
|
||||
const MessageParseArgs &_args, QString content,
|
||||
bool isAction)
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(
|
||||
Channel *_channel, const Communi::IrcMessage *_ircMessage,
|
||||
const MessageParseArgs &_args, QString content, bool isAction)
|
||||
: channel(_channel)
|
||||
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
||||
, ircMessage(_ircMessage)
|
||||
|
@ -62,17 +61,21 @@ bool TwitchMessageBuilder::isIgnored() const
|
|||
// TODO(pajlada): Do we need to check if the phrase is valid first?
|
||||
for (const auto &phrase : app->ignores->phrases.getVector()) {
|
||||
if (phrase.isBlock() && phrase.isMatch(this->originalMessage_)) {
|
||||
log("Blocking message because it contains ignored phrase {}", phrase.getPattern());
|
||||
log("Blocking message because it contains ignored phrase {}",
|
||||
phrase.getPattern());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (getSettings()->enableTwitchIgnoredUsers && this->tags.contains("user-id")) {
|
||||
if (getSettings()->enableTwitchIgnoredUsers &&
|
||||
this->tags.contains("user-id")) {
|
||||
auto sourceUserID = this->tags.value("user-id").toString();
|
||||
|
||||
for (const auto &user : app->accounts->twitch.getCurrent()->getIgnores()) {
|
||||
for (const auto &user :
|
||||
app->accounts->twitch.getCurrent()->getIgnores()) {
|
||||
if (sourceUserID == user.id) {
|
||||
log("Blocking message because it's from blocked user {}", user.name);
|
||||
log("Blocking message because it's from blocked user {}",
|
||||
user.name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -161,17 +164,21 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
const auto &phrases = app->ignores->phrases.getVector();
|
||||
auto removeEmotesInRange =
|
||||
[](int pos, int len,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &twitchEmotes) mutable {
|
||||
auto it = std::partition(
|
||||
twitchEmotes.begin(), twitchEmotes.end(), [pos, len](const auto &item) {
|
||||
return !((std::get<0>(item) >= pos) && std::get<0>(item) < (pos + len));
|
||||
});
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>>
|
||||
&twitchEmotes) mutable {
|
||||
auto it =
|
||||
std::partition(twitchEmotes.begin(), twitchEmotes.end(),
|
||||
[pos, len](const auto &item) {
|
||||
return !((std::get<0>(item) >= pos) &&
|
||||
std::get<0>(item) < (pos + len));
|
||||
});
|
||||
for (auto copy = it; copy != twitchEmotes.end(); ++copy) {
|
||||
if (std::get<1>(*copy) == nullptr) {
|
||||
log("remem nullptr {}", std::get<2>(*copy).string);
|
||||
}
|
||||
}
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> v(it, twitchEmotes.end());
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> v(
|
||||
it, twitchEmotes.end());
|
||||
twitchEmotes.erase(it, twitchEmotes.end());
|
||||
return v;
|
||||
};
|
||||
|
@ -185,7 +192,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
}
|
||||
};
|
||||
|
||||
auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase, const QStringRef &midrepl,
|
||||
auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase,
|
||||
const QStringRef &midrepl,
|
||||
int startIndex) mutable {
|
||||
if (!phrase.containsEmote()) {
|
||||
return;
|
||||
|
@ -218,7 +226,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
}
|
||||
QRegularExpressionMatch match;
|
||||
int from = 0;
|
||||
while ((from = this->originalMessage_.indexOf(regex, from, &match)) != -1) {
|
||||
while ((from = this->originalMessage_.indexOf(regex, from,
|
||||
&match)) != -1) {
|
||||
int len = match.capturedLength();
|
||||
auto vret = removeEmotesInRange(from, len, twitchEmotes);
|
||||
auto mid = this->originalMessage_.mid(from, len);
|
||||
|
@ -243,7 +252,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
|
||||
shiftIndicesAfter(from + len, midsize - len);
|
||||
|
||||
auto midExtendedRef = this->originalMessage_.midRef(pos1, pos2 - pos1);
|
||||
auto midExtendedRef =
|
||||
this->originalMessage_.midRef(pos1, pos2 - pos1);
|
||||
|
||||
for (auto &tup : vret) {
|
||||
if (std::get<1>(tup) == nullptr) {
|
||||
|
@ -252,7 +262,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
}
|
||||
int index = 0;
|
||||
QString emote = " " + std::get<2>(tup).string + " ";
|
||||
while ((index = midExtendedRef.indexOf(emote, index)) != -1) {
|
||||
while ((index = midExtendedRef.indexOf(emote, index)) !=
|
||||
-1) {
|
||||
std::get<0>(tup) = from + index + 1;
|
||||
index += emote.size() - 1;
|
||||
twitchEmotes.push_back(tup);
|
||||
|
@ -269,8 +280,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
continue;
|
||||
}
|
||||
int from = 0;
|
||||
while ((from = this->originalMessage_.indexOf(pattern, from,
|
||||
phrase.caseSensitivity())) != -1) {
|
||||
while ((from = this->originalMessage_.indexOf(
|
||||
pattern, from, phrase.caseSensitivity())) != -1) {
|
||||
int len = pattern.size();
|
||||
auto vret = removeEmotesInRange(from, len, twitchEmotes);
|
||||
auto replace = phrase.getReplace();
|
||||
|
@ -295,7 +306,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
|
||||
shiftIndicesAfter(from + len, replacesize - len);
|
||||
|
||||
auto midExtendedRef = this->originalMessage_.midRef(pos1, pos2 - pos1);
|
||||
auto midExtendedRef =
|
||||
this->originalMessage_.midRef(pos1, pos2 - pos1);
|
||||
|
||||
for (auto &tup : vret) {
|
||||
if (std::get<1>(tup) == nullptr) {
|
||||
|
@ -304,7 +316,8 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
}
|
||||
int index = 0;
|
||||
QString emote = " " + std::get<2>(tup).string + " ";
|
||||
while ((index = midExtendedRef.indexOf(emote, index)) != -1) {
|
||||
while ((index = midExtendedRef.indexOf(emote, index)) !=
|
||||
-1) {
|
||||
std::get<0>(tup) = from + index + 1;
|
||||
index += emote.size() - 1;
|
||||
twitchEmotes.push_back(tup);
|
||||
|
@ -319,10 +332,13 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
}
|
||||
|
||||
std::sort(twitchEmotes.begin(), twitchEmotes.end(),
|
||||
[](const auto &a, const auto &b) { return std::get<0>(a) < std::get<0>(b); });
|
||||
[](const auto &a, const auto &b) {
|
||||
return std::get<0>(a) < std::get<0>(b);
|
||||
});
|
||||
twitchEmotes.erase(std::unique(twitchEmotes.begin(), twitchEmotes.end(),
|
||||
[](const auto &first, const auto &second) {
|
||||
return std::get<0>(first) == std::get<0>(second);
|
||||
return std::get<0>(first) ==
|
||||
std::get<0>(second);
|
||||
}),
|
||||
twitchEmotes.end());
|
||||
|
||||
|
@ -337,22 +353,27 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
}
|
||||
|
||||
void TwitchMessageBuilder::addWords(
|
||||
const QStringList &words, const std::vector<std::tuple<int, EmotePtr, EmoteName>> &twitchEmotes)
|
||||
const QStringList &words,
|
||||
const std::vector<std::tuple<int, EmotePtr, EmoteName>> &twitchEmotes)
|
||||
{
|
||||
auto i = int();
|
||||
auto currentTwitchEmote = twitchEmotes.begin();
|
||||
|
||||
for (const auto &word : words) {
|
||||
// check if it's a twitch emote twitch emote
|
||||
while (currentTwitchEmote != twitchEmotes.end() && std::get<0>(*currentTwitchEmote) < i) {
|
||||
while (currentTwitchEmote != twitchEmotes.end() &&
|
||||
std::get<0>(*currentTwitchEmote) < i) {
|
||||
++currentTwitchEmote;
|
||||
}
|
||||
if (currentTwitchEmote != twitchEmotes.end() && std::get<0>(*currentTwitchEmote) == i) {
|
||||
if (currentTwitchEmote != twitchEmotes.end() &&
|
||||
std::get<0>(*currentTwitchEmote) == i) {
|
||||
auto emoteImage = std::get<1>(*currentTwitchEmote);
|
||||
if (emoteImage == nullptr) {
|
||||
log("emoteImage nullptr {}", std::get<2>(*currentTwitchEmote).string);
|
||||
log("emoteImage nullptr {}",
|
||||
std::get<2>(*currentTwitchEmote).string);
|
||||
}
|
||||
this->emplace<EmoteElement>(emoteImage, MessageElementFlag::TwitchEmote);
|
||||
this->emplace<EmoteElement>(emoteImage,
|
||||
MessageElementFlag::TwitchEmote);
|
||||
|
||||
i += word.length() + 1;
|
||||
currentTwitchEmote++;
|
||||
|
@ -362,7 +383,8 @@ void TwitchMessageBuilder::addWords(
|
|||
|
||||
// split words
|
||||
for (auto &variant : getApp()->emotes->emojis.parse(word)) {
|
||||
boost::apply_visitor([&](auto &&arg) { this->addTextOrEmoji(arg); }, variant);
|
||||
boost::apply_visitor([&](auto &&arg) { this->addTextOrEmoji(arg); },
|
||||
variant);
|
||||
}
|
||||
|
||||
for (int j = 0; j < word.size(); j++) {
|
||||
|
@ -404,16 +426,18 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
|||
// Actually just text
|
||||
auto linkString = this->matchLink(string);
|
||||
auto link = Link();
|
||||
auto textColor =
|
||||
this->action_ ? MessageColor(this->usernameColor_) : MessageColor(MessageColor::Text);
|
||||
auto textColor = this->action_ ? MessageColor(this->usernameColor_)
|
||||
: MessageColor(MessageColor::Text);
|
||||
|
||||
if (linkString.isEmpty()) {
|
||||
if (string.startsWith('@')) {
|
||||
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername, textColor,
|
||||
FontStyle::ChatMediumBold);
|
||||
this->emplace<TextElement>(string, MessageElementFlag::NonBoldUsername, textColor);
|
||||
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
|
||||
textColor, FontStyle::ChatMediumBold);
|
||||
this->emplace<TextElement>(
|
||||
string, MessageElementFlag::NonBoldUsername, textColor);
|
||||
} else {
|
||||
this->emplace<TextElement>(string, MessageElementFlag::Text, textColor);
|
||||
this->emplace<TextElement>(string, MessageElementFlag::Text,
|
||||
textColor);
|
||||
}
|
||||
} else {
|
||||
static QRegularExpression domainRegex(
|
||||
|
@ -424,7 +448,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
|||
auto match = domainRegex.match(string);
|
||||
if (match.isValid()) {
|
||||
lowercaseLinkString = string.mid(0, match.capturedStart(1)) +
|
||||
match.captured(1).toLower() + string.mid(match.capturedEnd(1));
|
||||
match.captured(1).toLower() +
|
||||
string.mid(match.capturedEnd(1));
|
||||
} else {
|
||||
lowercaseLinkString = string;
|
||||
}
|
||||
|
@ -432,24 +457,28 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
|||
|
||||
textColor = MessageColor(MessageColor::Link);
|
||||
auto linkMELowercase =
|
||||
this->emplace<TextElement>(lowercaseLinkString, MessageElementFlag::LowercaseLink,
|
||||
this->emplace<TextElement>(lowercaseLinkString,
|
||||
MessageElementFlag::LowercaseLink,
|
||||
textColor)
|
||||
->setLink(link);
|
||||
auto linkMEOriginal =
|
||||
this->emplace<TextElement>(string, MessageElementFlag::OriginalLink, textColor)
|
||||
this->emplace<TextElement>(string, MessageElementFlag::OriginalLink,
|
||||
textColor)
|
||||
->setLink(link);
|
||||
|
||||
LinkResolver::getLinkInfo(linkString, [linkMELowercase, linkMEOriginal, linkString](
|
||||
QString tooltipText, Link originalLink) {
|
||||
if (!tooltipText.isEmpty()) {
|
||||
linkMELowercase->setTooltip(tooltipText);
|
||||
linkMEOriginal->setTooltip(tooltipText);
|
||||
}
|
||||
if (originalLink.value != linkString && !originalLink.value.isEmpty()) {
|
||||
linkMELowercase->setLink(originalLink)->updateLink();
|
||||
linkMEOriginal->setLink(originalLink)->updateLink();
|
||||
}
|
||||
});
|
||||
LinkResolver::getLinkInfo(
|
||||
linkString, [linkMELowercase, linkMEOriginal, linkString](
|
||||
QString tooltipText, Link originalLink) {
|
||||
if (!tooltipText.isEmpty()) {
|
||||
linkMELowercase->setTooltip(tooltipText);
|
||||
linkMEOriginal->setTooltip(tooltipText);
|
||||
}
|
||||
if (originalLink.value != linkString &&
|
||||
!originalLink.value.isEmpty()) {
|
||||
linkMELowercase->setLink(originalLink)->updateLink();
|
||||
linkMEOriginal->setLink(originalLink)->updateLink();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// if (!linkString.isEmpty()) {
|
||||
|
@ -557,9 +586,11 @@ void TwitchMessageBuilder::appendUsername()
|
|||
|
||||
auto iterator = this->tags.find("display-name");
|
||||
if (iterator != this->tags.end()) {
|
||||
QString displayName = parseTagString(iterator.value().toString()).trimmed();
|
||||
QString displayName =
|
||||
parseTagString(iterator.value().toString()).trimmed();
|
||||
|
||||
if (QString::compare(displayName, this->userName, Qt::CaseInsensitive) == 0) {
|
||||
if (QString::compare(displayName, this->userName,
|
||||
Qt::CaseInsensitive) == 0) {
|
||||
username = displayName;
|
||||
|
||||
this->message().displayName = displayName;
|
||||
|
@ -577,7 +608,8 @@ void TwitchMessageBuilder::appendUsername()
|
|||
QString usernameText;
|
||||
|
||||
pajlada::Settings::Setting<int> usernameDisplayMode(
|
||||
"/appearance/messages/usernameDisplayMode", UsernameDisplayMode::UsernameAndLocalizedName);
|
||||
"/appearance/messages/usernameDisplayMode",
|
||||
UsernameDisplayMode::UsernameAndLocalizedName);
|
||||
|
||||
switch (usernameDisplayMode.getValue()) {
|
||||
case UsernameDisplayMode::Username: {
|
||||
|
@ -608,7 +640,8 @@ void TwitchMessageBuilder::appendUsername()
|
|||
// IrcManager::getInstance().getUser().getUserName();
|
||||
} else if (this->args.isReceivedWhisper) {
|
||||
// Sender username
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Username, this->usernameColor_,
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
|
||||
this->usernameColor_,
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::UserWhisper, this->message().displayName});
|
||||
|
||||
|
@ -616,7 +649,8 @@ void TwitchMessageBuilder::appendUsername()
|
|||
|
||||
// Separator
|
||||
this->emplace<TextElement>("->", MessageElementFlag::Username,
|
||||
app->themes->messages.textColors.system, FontStyle::ChatMedium);
|
||||
app->themes->messages.textColors.system,
|
||||
FontStyle::ChatMedium);
|
||||
|
||||
QColor selfColor = currentUser->color();
|
||||
if (!selfColor.isValid()) {
|
||||
|
@ -624,14 +658,16 @@ void TwitchMessageBuilder::appendUsername()
|
|||
}
|
||||
|
||||
// Your own username
|
||||
this->emplace<TextElement>(currentUser->getUserName() + ":", MessageElementFlag::Username,
|
||||
selfColor, FontStyle::ChatMediumBold);
|
||||
this->emplace<TextElement>(currentUser->getUserName() + ":",
|
||||
MessageElementFlag::Username, selfColor,
|
||||
FontStyle::ChatMediumBold);
|
||||
} else {
|
||||
if (!this->action_) {
|
||||
usernameText += ":";
|
||||
}
|
||||
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Username, this->usernameColor_,
|
||||
this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
|
||||
this->usernameColor_,
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::UserInfo, this->message().displayName});
|
||||
}
|
||||
|
@ -657,7 +693,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
|||
// update the media player url if necessary
|
||||
QUrl highlightSoundUrl;
|
||||
if (getSettings()->customHighlightSound) {
|
||||
highlightSoundUrl = QUrl::fromLocalFile(getSettings()->pathHighlightSound.getValue());
|
||||
highlightSoundUrl =
|
||||
QUrl::fromLocalFile(getSettings()->pathHighlightSound.getValue());
|
||||
} else {
|
||||
highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav");
|
||||
}
|
||||
|
@ -670,12 +707,15 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
|||
|
||||
// TODO: This vector should only be rebuilt upon highlights being changed
|
||||
// fourtf: should be implemented in the HighlightsController
|
||||
std::vector<HighlightPhrase> activeHighlights = app->highlights->phrases.getVector();
|
||||
std::vector<HighlightPhrase> userHighlights = app->highlights->highlightedUsers.getVector();
|
||||
std::vector<HighlightPhrase> activeHighlights =
|
||||
app->highlights->phrases.getVector();
|
||||
std::vector<HighlightPhrase> userHighlights =
|
||||
app->highlights->highlightedUsers.getVector();
|
||||
|
||||
if (getSettings()->enableSelfHighlight && currentUsername.size() > 0) {
|
||||
HighlightPhrase selfHighlight(currentUsername, getSettings()->enableSelfHighlightTaskbar,
|
||||
getSettings()->enableSelfHighlightSound, false);
|
||||
HighlightPhrase selfHighlight(
|
||||
currentUsername, getSettings()->enableSelfHighlightTaskbar,
|
||||
getSettings()->enableSelfHighlightSound, false);
|
||||
activeHighlights.emplace_back(std::move(selfHighlight));
|
||||
}
|
||||
|
||||
|
@ -710,7 +750,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
|||
}
|
||||
for (const HighlightPhrase &userHighlight : userHighlights) {
|
||||
if (userHighlight.isMatch(this->ircMessage->nick())) {
|
||||
log("Highlight because user {} sent a message", this->ircMessage->nick());
|
||||
log("Highlight because user {} sent a message",
|
||||
this->ircMessage->nick());
|
||||
doHighlight = true;
|
||||
|
||||
if (userHighlight.getAlert()) {
|
||||
|
@ -728,7 +769,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (this->args.isReceivedWhisper && getSettings()->enableWhisperHighlight) {
|
||||
if (this->args.isReceivedWhisper &&
|
||||
getSettings()->enableWhisperHighlight) {
|
||||
if (getSettings()->enableWhisperHighlightTaskbar) {
|
||||
doAlert = true;
|
||||
}
|
||||
|
@ -740,19 +782,22 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
|||
this->message().flags.set(MessageFlag::Highlighted, doHighlight);
|
||||
|
||||
if (!isPastMsg) {
|
||||
if (playSound && (!hasFocus || getSettings()->highlightAlwaysPlaySound)) {
|
||||
if (playSound &&
|
||||
(!hasFocus || getSettings()->highlightAlwaysPlaySound)) {
|
||||
player->play();
|
||||
}
|
||||
|
||||
if (doAlert) {
|
||||
QApplication::alert(getApp()->windows->getMainWindow().window(), 2500);
|
||||
QApplication::alert(getApp()->windows->getMainWindow().window(),
|
||||
2500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::appendTwitchEmote(const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec)
|
||||
void TwitchMessageBuilder::appendTwitchEmote(
|
||||
const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec)
|
||||
{
|
||||
auto app = getApp();
|
||||
if (!emote.contains(':')) {
|
||||
|
@ -779,11 +824,13 @@ void TwitchMessageBuilder::appendTwitchEmote(const QString &emote,
|
|||
auto start = coords.at(0).toInt();
|
||||
auto end = coords.at(1).toInt();
|
||||
|
||||
if (start >= end || start < 0 || end > this->originalMessage_.length()) {
|
||||
if (start >= end || start < 0 ||
|
||||
end > this->originalMessage_.length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto name = EmoteName{this->originalMessage_.mid(start, end - start + 1)};
|
||||
auto name =
|
||||
EmoteName{this->originalMessage_.mid(start, end - start + 1)};
|
||||
auto tup = std::tuple<int, EmotePtr, EmoteName>{
|
||||
start, app->emotes->twitch.getOrCreateEmote(id, name), name};
|
||||
if (std::get<1>(tup) == nullptr) {
|
||||
|
@ -828,8 +875,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
auto app = getApp();
|
||||
|
||||
auto iterator = this->tags.find("badges");
|
||||
if (iterator == this->tags.end())
|
||||
return;
|
||||
if (iterator == this->tags.end()) return;
|
||||
|
||||
for (QString badge : iterator.value().toString().split(',')) {
|
||||
if (badge.startsWith("bits/")) {
|
||||
|
@ -839,8 +885,10 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
// Try to fetch channel-specific bit badge
|
||||
try {
|
||||
if (twitchChannel)
|
||||
if (const auto &badge = this->twitchChannel->twitchBadge("bits", cheerAmount)) {
|
||||
this->emplace<EmoteElement>(badge.get(), MessageElementFlag::BadgeVanity)
|
||||
if (const auto &badge = this->twitchChannel->twitchBadge(
|
||||
"bits", cheerAmount)) {
|
||||
this->emplace<EmoteElement>(
|
||||
badge.get(), MessageElementFlag::BadgeVanity)
|
||||
->setTooltip(tooltip);
|
||||
continue;
|
||||
}
|
||||
|
@ -849,45 +897,55 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
}
|
||||
|
||||
// Use default bit badge
|
||||
if (auto badge = this->twitchChannel->globalTwitchBadges().badge("bits", cheerAmount)) {
|
||||
this->emplace<EmoteElement>(badge.get(), MessageElementFlag::BadgeVanity)
|
||||
if (auto badge = this->twitchChannel->globalTwitchBadges().badge(
|
||||
"bits", cheerAmount)) {
|
||||
this->emplace<EmoteElement>(badge.get(),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip(tooltip);
|
||||
}
|
||||
} else if (badge == "staff/1") {
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.staff),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.staff),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Staff");
|
||||
} else if (badge == "admin/1") {
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.admin),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.admin),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Admin");
|
||||
} else if (badge == "global_mod/1") {
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.globalmod),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.globalmod),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Global Moderator");
|
||||
} else if (badge == "moderator/1") {
|
||||
// TODO: Implement custom FFZ moderator badge
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.moderator),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.moderator),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Channel Moderator");
|
||||
} else if (badge == "turbo/1") {
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.turbo),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.turbo),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Turbo Subscriber");
|
||||
} else if (badge == "broadcaster/1") {
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.broadcaster),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.broadcaster),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Broadcaster");
|
||||
} else if (badge == "premium/1") {
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.prime),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.prime),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Prime Subscriber");
|
||||
} else if (badge.startsWith("partner/")) {
|
||||
int index = badge.midRef(8).toInt();
|
||||
switch (index) {
|
||||
case 1: {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.verified, 0.25),
|
||||
Image::fromPixmap(app->resources->twitch.verified,
|
||||
0.25),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Verified");
|
||||
} break;
|
||||
|
@ -898,23 +956,27 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
} break;
|
||||
}
|
||||
} else if (badge.startsWith("subscriber/")) {
|
||||
if (auto badgeEmote = this->twitchChannel->twitchBadge("subscriber", badge.mid(11))) {
|
||||
this->emplace<EmoteElement>(badgeEmote.get(), MessageElementFlag::BadgeSubscription)
|
||||
if (auto badgeEmote = this->twitchChannel->twitchBadge(
|
||||
"subscriber", badge.mid(11))) {
|
||||
this->emplace<EmoteElement>(
|
||||
badgeEmote.get(), MessageElementFlag::BadgeSubscription)
|
||||
->setTooltip((*badgeEmote)->tooltip.string);
|
||||
continue;
|
||||
}
|
||||
|
||||
// use default subscriber badge if custom one not found
|
||||
this->emplace<ImageElement>(Image::fromPixmap(app->resources->twitch.subscriber, 0.25),
|
||||
MessageElementFlag::BadgeSubscription)
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromPixmap(app->resources->twitch.subscriber, 0.25),
|
||||
MessageElementFlag::BadgeSubscription)
|
||||
->setTooltip("Twitch Subscriber");
|
||||
} else {
|
||||
auto splits = badge.split('/');
|
||||
if (splits.size() != 2)
|
||||
continue;
|
||||
if (splits.size() != 2) continue;
|
||||
|
||||
if (auto badgeEmote = this->twitchChannel->twitchBadge(splits[0], splits[1])) {
|
||||
this->emplace<EmoteElement>(badgeEmote.get(), MessageElementFlag::BadgeVanity)
|
||||
if (auto badgeEmote =
|
||||
this->twitchChannel->twitchBadge(splits[0], splits[1])) {
|
||||
this->emplace<EmoteElement>(badgeEmote.get(),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip((*badgeEmote)->tooltip.string);
|
||||
continue;
|
||||
}
|
||||
|
@ -924,9 +986,11 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
|
||||
void TwitchMessageBuilder::appendChatterinoBadges()
|
||||
{
|
||||
auto chatterinoBadgePtr = getApp()->chatterinoBadges->getBadge({this->userName});
|
||||
auto chatterinoBadgePtr =
|
||||
getApp()->chatterinoBadges->getBadge({this->userName});
|
||||
if (chatterinoBadgePtr) {
|
||||
this->emplace<EmoteElement>(*chatterinoBadgePtr, MessageElementFlag::BadgeChatterino);
|
||||
this->emplace<EmoteElement>(*chatterinoBadgePtr,
|
||||
MessageElementFlag::BadgeChatterino);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,13 @@ public:
|
|||
|
||||
TwitchMessageBuilder() = delete;
|
||||
|
||||
explicit TwitchMessageBuilder(Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
||||
explicit TwitchMessageBuilder(Channel *_channel,
|
||||
const Communi::IrcPrivateMessage *_ircMessage,
|
||||
const MessageParseArgs &_args);
|
||||
explicit TwitchMessageBuilder(Channel *_channel, const Communi::IrcMessage *_ircMessage,
|
||||
const MessageParseArgs &_args, QString content, bool isAction);
|
||||
explicit TwitchMessageBuilder(Channel *_channel,
|
||||
const Communi::IrcMessage *_ircMessage,
|
||||
const MessageParseArgs &_args,
|
||||
QString content, bool isAction);
|
||||
|
||||
Channel *channel;
|
||||
TwitchChannel *twitchChannel;
|
||||
|
@ -52,12 +55,14 @@ private:
|
|||
void appendUsername();
|
||||
void parseHighlights(bool isPastMsg);
|
||||
|
||||
void appendTwitchEmote(const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec);
|
||||
void appendTwitchEmote(
|
||||
const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec);
|
||||
Outcome tryAppendEmote(const EmoteName &name);
|
||||
|
||||
void addWords(const QStringList &words,
|
||||
const std::vector<std::tuple<int, EmotePtr, EmoteName>> &twitchEmotes);
|
||||
void addWords(
|
||||
const QStringList &words,
|
||||
const std::vector<std::tuple<int, EmotePtr, EmoteName>> &twitchEmotes);
|
||||
void addTextOrEmoji(EmotePtr emote);
|
||||
void addTextOrEmoji(const QString &value);
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
namespace chatterino {
|
||||
|
||||
static void addPhrasesTab(LayoutCreator<QVBoxLayout> box);
|
||||
static void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> box, QStringListModel &model);
|
||||
static void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> box,
|
||||
QStringListModel &model);
|
||||
|
||||
IgnoresPage::IgnoresPage()
|
||||
: SettingsPage("Ignores", "")
|
||||
|
@ -35,7 +36,8 @@ IgnoresPage::IgnoresPage()
|
|||
auto tabs = layout.emplace<QTabWidget>();
|
||||
|
||||
addPhrasesTab(tabs.appendTab(new QVBoxLayout, "Phrases"));
|
||||
addUsersTab(*this, tabs.appendTab(new QVBoxLayout, "Users"), this->userListModel_);
|
||||
addUsersTab(*this, tabs.appendTab(new QVBoxLayout, "Users"),
|
||||
this->userListModel_);
|
||||
|
||||
auto label = layout.emplace<QLabel>(INFO);
|
||||
label->setWordWrap(true);
|
||||
|
@ -45,10 +47,15 @@ IgnoresPage::IgnoresPage()
|
|||
void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
|
||||
{
|
||||
EditableModelView *view =
|
||||
layout.emplace<EditableModelView>(getApp()->ignores->createModel(nullptr)).getElement();
|
||||
view->setTitles({"Pattern", "Regex", "Case Sensitive", "Block", "Replacement"});
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
layout
|
||||
.emplace<EditableModelView>(getApp()->ignores->createModel(nullptr))
|
||||
.getElement();
|
||||
view->setTitles(
|
||||
{"Pattern", "Regex", "Case Sensitive", "Block", "Replacement"});
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::Fixed);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
0, QHeaderView::Stretch);
|
||||
|
||||
QTimer::singleShot(1, [view] {
|
||||
view->getTableView()->resizeColumnsToContents();
|
||||
|
@ -56,12 +63,14 @@ void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
|
|||
});
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
getApp()->ignores->phrases.appendItem(IgnorePhrase{
|
||||
"my phrase", false, false, getSettings()->ignoredPhraseReplace.getValue(), true});
|
||||
getApp()->ignores->phrases.appendItem(
|
||||
IgnorePhrase{"my phrase", false, false,
|
||||
getSettings()->ignoredPhraseReplace.getValue(), true});
|
||||
});
|
||||
}
|
||||
|
||||
void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users, QStringListModel &userModel)
|
||||
void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users,
|
||||
QStringListModel &userModel)
|
||||
{
|
||||
users.append(page.createCheckBox("Enable twitch ignored users",
|
||||
getSettings()->enableTwitchIgnoredUsers));
|
||||
|
|
Loading…
Reference in a new issue