chore: remove Singleton & replace getIApp with getApp (#5514)

This commit is contained in:
pajlada
2024-07-21 15:09:59 +02:00
committed by GitHub
parent 21186df058
commit 5deec1f02f
145 changed files with 802 additions and 856 deletions
+37 -37
View File
@@ -91,7 +91,7 @@ TwitchChannel::TwitchChannel(const QString &name)
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
this->bSignals_.emplace_back(
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
getApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
this->setMod(false);
this->refreshPubSub();
}));
@@ -143,18 +143,18 @@ TwitchChannel::TwitchChannel(const QString &name)
TwitchChannel::~TwitchChannel()
{
getIApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_,
this->seventvEmoteSetID_);
getApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_,
this->seventvEmoteSetID_);
if (getIApp()->getTwitch()->getBTTVLiveUpdates())
if (getApp()->getTwitch()->getBTTVLiveUpdates())
{
getIApp()->getTwitch()->getBTTVLiveUpdates()->partChannel(
getApp()->getTwitch()->getBTTVLiveUpdates()->partChannel(
this->roomId());
}
if (getIApp()->getTwitch()->getSeventvEventAPI())
if (getApp()->getTwitch()->getSeventvEventAPI())
{
getIApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel(
getApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel(
this->roomId());
}
}
@@ -332,7 +332,7 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
<< "] Channel point reward added:" << reward.id << ","
<< reward.title << "," << reward.isUserInputRequired;
auto *server = getIApp()->getTwitch();
auto *server = getApp()->getTwitch();
auto it = std::remove_if(
this->waitingRedemptions_.begin(), this->waitingRedemptions_.end(),
[&](const QueuedRedemption &msg) {
@@ -426,7 +426,7 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
qCDebug(chatterinoTwitch).nospace().noquote()
<< "[TwitchChannel " << this->getName() << "] Online";
getIApp()->getNotifications()->notifyTwitchChannelLive({
getApp()->getNotifications()->notifyTwitchChannelLive({
.channelId = this->roomId(),
.channelName = this->getName(),
.displayName = this->getDisplayName(),
@@ -452,7 +452,7 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
&builder);
this->addMessage(builder.release(), MessageContext::Original);
getIApp()->getNotifications()->notifyTwitchChannelOffline(
getApp()->getNotifications()->notifyTwitchChannelOffline(
this->roomId());
}
};
@@ -509,7 +509,7 @@ void TwitchChannel::showLoginMessage()
{
const auto linkColor = MessageColor(MessageColor::Link);
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
const auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
const auto expirationText =
QStringLiteral("You need to log in to send messages. You can link your "
"Twitch account");
@@ -532,7 +532,7 @@ void TwitchChannel::showLoginMessage()
void TwitchChannel::roomIdChanged()
{
if (getIApp()->isTest())
if (getApp()->isTest())
{
return;
}
@@ -544,7 +544,7 @@ void TwitchChannel::roomIdChanged()
this->refreshSevenTVChannelEmotes(false);
this->joinBttvChannel();
this->listenSevenTVCosmetics();
getIApp()->getTwitchLiveController()->add(
getApp()->getTwitchLiveController()->add(
std::dynamic_pointer_cast<TwitchChannel>(shared_from_this()));
}
@@ -710,7 +710,7 @@ void TwitchChannel::setStaff(bool value)
bool TwitchChannel::isBroadcaster() const
{
auto *app = getIApp();
auto *app = getApp();
return this->getName() ==
app->getAccounts()->twitch.getCurrent()->getUserName();
@@ -728,7 +728,7 @@ bool TwitchChannel::canReconnect() const
void TwitchChannel::reconnect()
{
getIApp()->getTwitchAbstract()->connect();
getApp()->getTwitchAbstract()->connect();
}
QString TwitchChannel::getCurrentStreamID() const
@@ -753,7 +753,7 @@ void TwitchChannel::setRoomId(const QString &id)
{
*this->roomID_.access() = id;
// This is intended for tests and benchmarks. See comment in constructor.
if (!getIApp()->isTest())
if (!getApp()->isTest())
{
this->roomIdChanged();
this->loadRecentMessages();
@@ -854,17 +854,17 @@ const QString &TwitchChannel::seventvEmoteSetID() const
void TwitchChannel::joinBttvChannel() const
{
if (getIApp()->getTwitch()->getBTTVLiveUpdates())
if (getApp()->getTwitch()->getBTTVLiveUpdates())
{
const auto currentAccount =
getIApp()->getAccounts()->twitch.getCurrent();
getApp()->getAccounts()->twitch.getCurrent();
QString userName;
if (currentAccount && !currentAccount->isAnon())
{
userName = currentAccount->getUserName();
}
getIApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel(
this->roomId(), userName);
getApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel(this->roomId(),
userName);
}
}
@@ -1012,14 +1012,14 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
this->seventvUserID_ = newUserID;
this->seventvEmoteSetID_ = newEmoteSetID;
runInGuiThread([this, oldUserID, oldEmoteSetID]() {
if (getIApp()->getTwitch()->getSeventvEventAPI())
if (getApp()->getTwitch()->getSeventvEventAPI())
{
getIApp()->getTwitch()->getSeventvEventAPI()->subscribeUser(
getApp()->getTwitch()->getSeventvEventAPI()->subscribeUser(
this->seventvUserID_, this->seventvEmoteSetID_);
if (oldUserID || oldEmoteSetID)
{
getIApp()->getTwitch()->dropSeventvChannel(
getApp()->getTwitch()->dropSeventvChannel(
oldUserID.value_or(QString()),
oldEmoteSetID.value_or(QString()));
}
@@ -1215,7 +1215,7 @@ void TwitchChannel::loadRecentMessages()
tc->addRecentChatter(msg->displayName);
}
getIApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
msgs);
},
[weak]() {
@@ -1303,7 +1303,7 @@ void TwitchChannel::loadRecentMessagesReconnect()
void TwitchChannel::refreshPubSub()
{
if (getIApp()->isTest())
if (getApp()->isTest())
{
return;
}
@@ -1314,17 +1314,17 @@ void TwitchChannel::refreshPubSub()
return;
}
auto currentAccount = getIApp()->getAccounts()->twitch.getCurrent();
auto currentAccount = getApp()->getAccounts()->twitch.getCurrent();
getIApp()->getTwitchPubSub()->setAccount(currentAccount);
getApp()->getTwitchPubSub()->setAccount(currentAccount);
getIApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId);
getApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId);
if (this->hasModRights())
{
getIApp()->getTwitchPubSub()->listenToAutomod(roomId);
getIApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId);
getApp()->getTwitchPubSub()->listenToAutomod(roomId);
getApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId);
}
getIApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId);
getApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId);
}
void TwitchChannel::refreshChatters()
@@ -1350,7 +1350,7 @@ void TwitchChannel::refreshChatters()
// Get chatter list via helix api
getHelix()->getChatters(
this->roomId(),
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(),
getApp()->getAccounts()->twitch.getCurrent()->getUserId(),
MAX_CHATTERS_TO_FETCH,
[this, weak = weakOf<Channel>(this)](auto result) {
if (auto shared = weak.lock())
@@ -1710,7 +1710,7 @@ std::vector<FfzBadges::Badge> TwitchChannel::ffzChannelBadges(
std::vector<FfzBadges::Badge> badges;
const auto *ffzBadges = getIApp()->getFfzBadges();
const auto *ffzBadges = getApp()->getFfzBadges();
for (const auto &badgeID : it->second)
{
@@ -1769,7 +1769,7 @@ void TwitchChannel::updateSevenTVActivity()
QStringLiteral("https://7tv.io/v3/users/%1/presences");
const auto currentSeventvUserID =
getIApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID();
getApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID();
if (currentSeventvUserID.isEmpty())
{
return;
@@ -1791,7 +1791,7 @@ void TwitchChannel::updateSevenTVActivity()
qCDebug(chatterinoSeventv) << "Sending activity in" << this->getName();
getIApp()->getSeventvAPI()->updatePresence(
getApp()->getSeventvAPI()->updatePresence(
this->roomId(), currentSeventvUserID,
[chan = weakOf<Channel>(this)]() {
const auto self =
@@ -1811,9 +1811,9 @@ void TwitchChannel::updateSevenTVActivity()
void TwitchChannel::listenSevenTVCosmetics() const
{
if (getIApp()->getTwitch()->getSeventvEventAPI())
if (getApp()->getTwitch()->getSeventvEventAPI())
{
getIApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel(
getApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel(
this->roomId());
}
}