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