Clean up TwitchAccount emote stuff (#4243)

* Remove unused TwitchAccount FollowResult enum

* Remove unused TwitchEmoteSetResolverResponse struct

* Remove unused and unimplemented `getEmoteSetBatches` function definition

* Remove unused `loadEmoteSetData` and `staticEmoteSets` from
TwitchAccount

* Remove forward declaration of TwitchAccount in TwitchAccountManager

* Clean up IgnorePhrase includes

* add missing newline in pubsubmanager.cpp
This commit is contained in:
pajlada 2022-12-18 15:36:39 +01:00 committed by GitHub
parent 8830b0e01c
commit a715b1ffff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 174 additions and 212 deletions

View file

@ -107,6 +107,8 @@ set(SOURCE_FILES
controllers/ignores/IgnoreController.hpp
controllers/ignores/IgnoreModel.cpp
controllers/ignores/IgnoreModel.hpp
controllers/ignores/IgnorePhrase.cpp
controllers/ignores/IgnorePhrase.hpp
controllers/moderationactions/ModerationAction.cpp
controllers/moderationactions/ModerationAction.hpp

View file

@ -4,6 +4,8 @@
#include "common/ChatterSet.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandController.hpp"
#include "messages/Emote.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"

View file

@ -15,6 +15,7 @@
#include "providers/irc/IrcChannel2.hpp"
#include "providers/irc/IrcServer.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

View file

@ -4,6 +4,7 @@
#include "controllers/accounts/AccountController.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "util/FormatTime.hpp"
#include "util/Helpers.hpp"

View file

@ -1,6 +1,7 @@
#include "controllers/highlights/HighlightController.hpp"
#include "common/QLogging.hpp"
#include "providers/twitch/TwitchAccount.hpp"
namespace {

View file

@ -2,6 +2,7 @@
#include "common/QLogging.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {

View file

@ -0,0 +1,115 @@
#include "controllers/ignores/IgnorePhrase.hpp"
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "providers/twitch/TwitchAccount.hpp"
namespace chatterino {
IgnorePhrase::IgnorePhrase(const QString &pattern, bool isRegex, bool isBlock,
const QString &replace, bool isCaseSensitive)
: pattern_(pattern)
, isRegex_(isRegex)
, regex_(pattern)
, isBlock_(isBlock)
, replace_(replace)
, isCaseSensitive_(isCaseSensitive)
{
if (this->isCaseSensitive_)
{
regex_.setPatternOptions(
QRegularExpression::UseUnicodePropertiesOption);
}
else
{
regex_.setPatternOptions(
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption);
}
}
bool IgnorePhrase::operator==(const IgnorePhrase &other) const
{
return std::tie(this->pattern_, this->isRegex_, this->isBlock_,
this->replace_, this->isCaseSensitive_) ==
std::tie(other.pattern_, other.isRegex_, other.isBlock_,
other.replace_, other.isCaseSensitive_);
}
const QString &IgnorePhrase::getPattern() const
{
return this->pattern_;
}
bool IgnorePhrase::isRegex() const
{
return this->isRegex_;
}
bool IgnorePhrase::isRegexValid() const
{
return this->regex_.isValid();
}
bool IgnorePhrase::isMatch(const QString &subject) const
{
return !this->pattern_.isEmpty() &&
(this->isRegex()
? (this->regex_.isValid() &&
this->regex_.match(subject).hasMatch())
: subject.contains(this->pattern_, this->caseSensitivity()));
}
const QRegularExpression &IgnorePhrase::getRegex() const
{
return this->regex_;
}
bool IgnorePhrase::isBlock() const
{
return this->isBlock_;
}
const QString &IgnorePhrase::getReplace() const
{
return this->replace_;
}
bool IgnorePhrase::isCaseSensitive() const
{
return this->isCaseSensitive_;
}
Qt::CaseSensitivity IgnorePhrase::caseSensitivity() const
{
return this->isCaseSensitive_ ? Qt::CaseSensitive : Qt::CaseInsensitive;
}
const std::unordered_map<EmoteName, EmotePtr> &IgnorePhrase::getEmotes() const
{
return this->emotes_;
}
bool IgnorePhrase::containsEmote() const
{
if (!this->emotesChecked_)
{
const auto &accvec = getApp()->accounts->twitch.accounts;
for (const auto &acc : accvec)
{
const auto &accemotes = *acc->accessEmotes();
for (const auto &emote : accemotes.emotes)
{
if (this->replace_.contains(emote.first.string,
Qt::CaseSensitive))
{
this->emotes_.emplace(emote.first, emote.second);
}
}
}
this->emotesChecked_ = true;
}
return !this->emotes_.empty();
}
} // namespace chatterino

View file

@ -1,7 +1,6 @@
#pragma once
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "messages/Emote.hpp"
#include "singletons/Settings.hpp"
#include "util/RapidjsonHelpers.hpp"
#include "util/RapidJsonSerializeQString.hpp"
@ -10,118 +9,39 @@
#include <QRegularExpression>
#include <QString>
#include <memory>
#include <unordered_map>
namespace chatterino {
class IgnorePhrase
{
public:
bool operator==(const IgnorePhrase &other) const
{
return std::tie(this->pattern_, this->isRegex_, this->isBlock_,
this->replace_, this->isCaseSensitive_) ==
std::tie(other.pattern_, other.isRegex_, other.isBlock_,
other.replace_, other.isCaseSensitive_);
}
IgnorePhrase(const QString &pattern, bool isRegex, bool isBlock,
const QString &replace, bool isCaseSensitive)
: pattern_(pattern)
, isRegex_(isRegex)
, regex_(pattern)
, isBlock_(isBlock)
, replace_(replace)
, isCaseSensitive_(isCaseSensitive)
{
if (this->isCaseSensitive_)
{
regex_.setPatternOptions(
QRegularExpression::UseUnicodePropertiesOption);
}
else
{
regex_.setPatternOptions(
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption);
}
}
const QString &replace, bool isCaseSensitive);
const QString &getPattern() const
{
return this->pattern_;
}
bool operator==(const IgnorePhrase &other) const;
bool isRegex() const
{
return this->isRegex_;
}
const QString &getPattern() const;
bool isRegexValid() const
{
return this->regex_.isValid();
}
bool isRegex() const;
bool isMatch(const QString &subject) const
{
return !this->pattern_.isEmpty() &&
(this->isRegex() ? (this->regex_.isValid() &&
this->regex_.match(subject).hasMatch())
: subject.contains(this->pattern_,
this->caseSensitivity()));
}
bool isRegexValid() const;
const QRegularExpression &getRegex() const
{
return this->regex_;
}
bool isMatch(const QString &subject) const;
bool isBlock() const
{
return this->isBlock_;
}
const QRegularExpression &getRegex() const;
const QString &getReplace() const
{
return this->replace_;
}
bool isBlock() const;
bool isCaseSensitive() const
{
return this->isCaseSensitive_;
}
const QString &getReplace() const;
Qt::CaseSensitivity caseSensitivity() const
{
return this->isCaseSensitive_ ? Qt::CaseSensitive : Qt::CaseInsensitive;
}
bool isCaseSensitive() const;
const std::unordered_map<EmoteName, EmotePtr> &getEmotes() const
{
return this->emotes_;
}
Qt::CaseSensitivity caseSensitivity() const;
bool containsEmote() const
{
if (!this->emotesChecked_)
{
const auto &accvec = getApp()->accounts->twitch.accounts;
for (const auto &acc : accvec)
{
const auto &accemotes = *acc->accessEmotes();
for (const auto &emote : accemotes.emotes)
{
if (this->replace_.contains(emote.first.string,
Qt::CaseSensitive))
{
this->emotes_.emplace(emote.first, emote.second);
}
}
}
this->emotesChecked_ = true;
}
return !this->emotes_.empty();
}
const std::unordered_map<EmoteName, EmotePtr> &getEmotes() const;
bool containsEmote() const;
private:
QString pattern_;

View file

@ -5,6 +5,7 @@
#include "util/RapidJsonSerializeQString.hpp"
#include <pajlada/serialize.hpp>
#include <QRegularExpression>
#include <QString>
#include <memory>

View file

@ -9,6 +9,7 @@
#include "messages/MessageElement.hpp"
#include "providers/LinkResolver.hpp"
#include "providers/twitch/PubSubActions.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Resources.hpp"
#include "singletons/Theme.hpp"

View file

@ -5,6 +5,7 @@
#include "controllers/accounts/AccountController.hpp"
#include "messages/LimitedQueue.hpp"
#include "messages/Message.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchAccountManager.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchHelpers.hpp"

View file

@ -4,6 +4,7 @@
#include "providers/twitch/PubSubActions.hpp"
#include "providers/twitch/PubSubHelpers.hpp"
#include "providers/twitch/PubSubMessages.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/DebugCount.hpp"
#include "util/Helpers.hpp"
#include "util/RapidjsonHelpers.hpp"
@ -476,6 +477,18 @@ PubSub::PubSub(const QString &host, std::chrono::seconds pingInterval)
bind(&PubSub::onConnectionFail, this, ::_1));
}
void PubSub::setAccount(std::shared_ptr<TwitchAccount> account)
{
this->token_ = account->getOAuthToken();
this->userID_ = account->getUserId();
}
void PubSub::setAccountData(QString token, QString userID)
{
this->token_ = token;
this->userID_ = userID;
}
void PubSub::addClient()
{
if (this->addingClient)

View file

@ -6,8 +6,8 @@
#include "providers/twitch/PubSubClientOptions.hpp"
#include "providers/twitch/PubSubMessages.hpp"
#include "providers/twitch/PubSubWebsocket.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/ExponentialBackoff.hpp"
#include "util/QStringHash.hpp"
#include <pajlada/signals/signal.hpp>
#include <QJsonObject>
@ -24,6 +24,8 @@
namespace chatterino {
class TwitchAccount;
class PubSub
{
using WebsocketMessagePtr =
@ -57,17 +59,9 @@ public:
PubSub(const QString &host,
std::chrono::seconds pingInterval = std::chrono::seconds(15));
void setAccount(std::shared_ptr<TwitchAccount> account)
{
this->token_ = account->getOAuthToken();
this->userID_ = account->getUserId();
}
void setAccount(std::shared_ptr<TwitchAccount> account);
void setAccountData(QString token, QString userID)
{
this->token_ = token;
this->userID_ = userID;
}
void setAccountData(QString token, QString userID);
~PubSub() = delete;

View file

@ -442,71 +442,4 @@ void TwitchAccount::autoModDeny(const QString msgID, ChannelPtr channel)
});
}
void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
{
if (!emoteSet)
{
qCWarning(chatterinoTwitch) << "null emote set sent";
return;
}
auto staticSetIt = this->staticEmoteSets.find(emoteSet->key);
if (staticSetIt != this->staticEmoteSets.end())
{
const auto &staticSet = staticSetIt->second;
emoteSet->channelName = staticSet.channelName;
emoteSet->text = staticSet.text;
return;
}
getHelix()->getEmoteSetData(
emoteSet->key,
[emoteSet](HelixEmoteSetData emoteSetData) {
// Follower emotes can be only used in their origin channel
if (emoteSetData.emoteType == "follower")
{
emoteSet->local = true;
}
if (emoteSetData.ownerId.isEmpty() ||
emoteSetData.setId != emoteSet->key)
{
qCDebug(chatterinoTwitch)
<< QString("Failed to fetch emoteSetData for %1, assuming "
"Twitch is the owner")
.arg(emoteSet->key);
// most (if not all) emotes that fail to load are time limited event emotes owned by Twitch
emoteSet->channelName = "twitch";
emoteSet->text = "Twitch";
return;
}
// emote set 0 = global emotes
if (emoteSetData.ownerId == "0")
{
// emoteSet->channelName = QString();
emoteSet->text = "Twitch Global";
return;
}
getHelix()->getUserById(
emoteSetData.ownerId,
[emoteSet](HelixUser user) {
emoteSet->channelName = user.login;
emoteSet->text = user.displayName;
},
[emoteSetData] {
qCWarning(chatterinoTwitch)
<< "Failed to query user by id:" << emoteSetData.ownerId
<< emoteSetData.setId;
});
},
[emoteSet] {
// fetching emoteset data failed
return;
});
}
} // namespace chatterino

View file

@ -20,39 +20,6 @@
namespace chatterino {
enum FollowResult {
FollowResult_Following,
FollowResult_NotFollowing,
FollowResult_Failed,
};
struct TwitchEmoteSetResolverResponse {
const QString channelName;
const QString channelId;
const QString type;
const int tier;
const bool isCustom;
// Example response:
// {
// "channel_name": "zneix",
// "channel_id": "99631238",
// "type": "",
// "tier": 1,
// "custom": false
// }
TwitchEmoteSetResolverResponse(QJsonObject jsonObject)
: channelName(jsonObject.value("channel_name").toString())
, channelId(jsonObject.value("channel_id").toString())
, type(jsonObject.value("type").toString())
, tier(jsonObject.value("tier").toInt())
, isCustom(jsonObject.value("custom").toBool())
{
}
};
std::vector<QStringList> getEmoteSetBatches(QStringList emoteSetKeys);
class TwitchAccount : public Account
{
public:
@ -69,8 +36,6 @@ public:
std::vector<TwitchEmote> emotes;
};
std::map<QString, EmoteSet> staticEmoteSets;
struct TwitchAccountEmoteData {
std::vector<std::shared_ptr<EmoteSet>> emoteSets;
@ -127,8 +92,6 @@ public:
void autoModDeny(const QString msgID, ChannelPtr channel);
private:
void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet);
QString oauthClient_;
QString oauthToken_;
QString userName_;

View file

@ -2,7 +2,6 @@
#include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/SharedPtrElementLess.hpp"
#include <boost/signals2.hpp>

View file

@ -6,6 +6,7 @@
#include "common/QLogging.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "messages/Emote.hpp"
#include "messages/Message.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/bttv/LoadBttvChannelEmote.hpp"
@ -15,6 +16,7 @@
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"
#include "providers/twitch/PubSubManager.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

View file

@ -6,10 +6,12 @@
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "controllers/userdata/UserDataController.hpp"
#include "messages/Emote.hpp"
#include "messages/Message.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/ffz/FfzBadges.hpp"
#include "providers/seventv/SeventvBadges.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "providers/twitch/TwitchBadges.hpp"
#include "providers/twitch/TwitchChannel.hpp"

View file

@ -7,6 +7,7 @@
#include "common/Version.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"

View file

@ -6,8 +6,10 @@
#include "controllers/accounts/AccountController.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "debug/Benchmark.hpp"
#include "messages/Emote.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Emotes.hpp"

View file

@ -5,6 +5,7 @@
#include "common/NetworkRequest.hpp"
#include "common/QLogging.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/Clipboard.hpp"
#include "util/Helpers.hpp"

View file

@ -5,6 +5,7 @@
#include "common/QLogging.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "messages/MessageThread.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/helper/ChannelView.hpp"
#include "widgets/helper/ResizingTextEdit.hpp"

View file

@ -11,6 +11,7 @@
#include "messages/MessageBuilder.hpp"
#include "providers/IvrApi.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Resources.hpp"

View file

@ -14,6 +14,7 @@
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp"
#include "providers/LinkResolver.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Resources.hpp"

View file

@ -6,6 +6,7 @@
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Emotes.hpp"

View file

@ -11,6 +11,7 @@
#include "controllers/notifications/NotificationController.hpp"
#include "messages/MessageThread.hpp"
#include "providers/twitch/EmoteValue.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"

View file

@ -7,6 +7,7 @@
#include "controllers/hotkeys/HotkeyCategory.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Resources.hpp"