refactor: Remove most raw accesses into Application (#5104)

This commit is contained in:
pajlada
2024-01-19 17:59:55 +01:00
committed by GitHub
parent 326a402710
commit 4380ef8c5f
82 changed files with 552 additions and 452 deletions
+3 -9
View File
@@ -347,9 +347,7 @@ void SeventvEventAPI::onUserUpdate(const Dispatch &dispatch)
void SeventvEventAPI::onCosmeticCreate(const CosmeticCreateDispatch &cosmetic)
{
// We're using `Application::instance` instead of getApp(), because we're not in the GUI thread.
// `seventvBadges` does its own locking.
auto *badges = Application::instance->seventvBadges;
auto *badges = getIApp()->getSeventvBadges();
switch (cosmetic.kind)
{
case CosmeticKind::Badge: {
@@ -364,9 +362,7 @@ void SeventvEventAPI::onCosmeticCreate(const CosmeticCreateDispatch &cosmetic)
void SeventvEventAPI::onEntitlementCreate(
const EntitlementCreateDeleteDispatch &entitlement)
{
// We're using `Application::instance` instead of getApp(), because we're not in the GUI thread.
// `seventvBadges` does its own locking.
auto *badges = Application::instance->seventvBadges;
auto *badges = getIApp()->getSeventvBadges();
switch (entitlement.kind)
{
case CosmeticKind::Badge: {
@@ -382,9 +378,7 @@ void SeventvEventAPI::onEntitlementCreate(
void SeventvEventAPI::onEntitlementDelete(
const EntitlementCreateDeleteDispatch &entitlement)
{
// We're using `Application::instance` instead of getApp(), because we're not in the GUI thread.
// `seventvBadges` does its own locking.
auto *badges = Application::instance->seventvBadges;
auto *badges = getIApp()->getSeventvBadges();
switch (entitlement.kind)
{
case CosmeticKind::Badge: {
+10 -9
View File
@@ -386,7 +386,7 @@ std::vector<MessagePtr> parseNoticeMessage(Communi::IrcNoticeMessage *message)
{
const auto linkColor = MessageColor(MessageColor::Link);
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
const auto curUser = getApp()->accounts->twitch.getCurrent();
const auto curUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto expirationText = QString("Login expired for user \"%1\"!")
.arg(curUser->getUserName());
const auto loginPromptText = QString("Try adding your account again.");
@@ -774,10 +774,10 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
chan->addOrReplaceTimeout(std::move(clearChat.message));
// refresh all
getApp()->windows->repaintVisibleChatWidgets(chan.get());
getIApp()->getWindows()->repaintVisibleChatWidgets(chan.get());
if (getSettings()->hideModerated)
{
getApp()->windows->forceLayoutChannelViews();
getIApp()->getWindows()->forceLayoutChannelViews();
}
}
@@ -828,7 +828,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
// set received emote-sets, used in TwitchAccount::loadUserstateEmotes
bool emoteSetsChanged = currentUser->setUserstateEmoteSets(
@@ -880,7 +880,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleGlobalUserStateMessage(
Communi::IrcMessage *message)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
// set received emote-sets, this time used to initially load emotes
// NOTE: this should always return true unless we reconnect
@@ -1134,7 +1134,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
}
if (message->nick() ==
getApp()->accounts->twitch.getCurrent()->getUserName())
getIApp()->getAccounts()->twitch.getCurrent()->getUserName())
{
twitchChannel->addMessage(makeSystemMessage("joined channel"));
twitchChannel->joined.invoke();
@@ -1157,7 +1157,7 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
}
const auto selfAccountName =
getApp()->accounts->twitch.getCurrent()->getUserName();
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
if (message->nick() != selfAccountName &&
getSettings()->showParts.getValue())
{
@@ -1207,8 +1207,9 @@ void IrcMessageHandler::setSimilarityFlags(const MessagePtr &message,
{
if (getSettings()->similarityEnabled)
{
bool isMyself = message->loginName ==
getApp()->accounts->twitch.getCurrent()->getUserName();
bool isMyself =
message->loginName ==
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
bool hideMyself = getSettings()->hideSimilarMyself;
if (isMyself && !hideMyself)
+16 -14
View File
@@ -94,7 +94,7 @@ TwitchChannel::TwitchChannel(const QString &name)
}
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([this] {
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
this->setMod(false);
this->refreshPubSub();
}));
@@ -141,22 +141,22 @@ TwitchChannel::TwitchChannel(const QString &name)
{
qCDebug(chatterinoTwitch)
<< "[TwitchChannel" << this->getName() << "] Online";
if (getApp()->notifications->isChannelNotified(this->getName(),
Platform::Twitch))
if (getIApp()->getNotifications()->isChannelNotified(
this->getName(), Platform::Twitch))
{
if (Toasts::isEnabled())
{
getApp()->toasts->sendChannelNotification(
getIApp()->getToasts()->sendChannelNotification(
this->getName(), this->accessStreamStatus()->title,
Platform::Twitch);
}
if (getSettings()->notificationPlaySound)
{
getApp()->notifications->playSound();
getIApp()->getNotifications()->playSound();
}
if (getSettings()->notificationFlashTaskbar)
{
getApp()->windows->sendAlert();
getIApp()->getWindows()->sendAlert();
}
}
// Channel live message
@@ -176,7 +176,7 @@ TwitchChannel::TwitchChannel(const QString &name)
!(isInStreamerMode() &&
getSettings()->streamerModeSuppressLiveNotifications))
{
getApp()->notifications->playSound();
getIApp()->getNotifications()->playSound();
}
}
else
@@ -538,7 +538,7 @@ void TwitchChannel::showLoginMessage()
{
const auto linkColor = MessageColor(MessageColor::Link);
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
const auto currentUser = getApp()->accounts->twitch.getCurrent();
const auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto expirationText =
QStringLiteral("You need to log in to send messages. You can link your "
"Twitch account");
@@ -622,7 +622,7 @@ QString TwitchChannel::prepareMessage(const QString &message) const
void TwitchChannel::sendMessage(const QString &message)
{
auto *app = getApp();
if (!app->accounts->twitch.isLoggedIn())
if (!app->getAccounts()->twitch.isLoggedIn())
{
if (!message.isEmpty())
{
@@ -656,7 +656,7 @@ void TwitchChannel::sendMessage(const QString &message)
void TwitchChannel::sendReply(const QString &message, const QString &replyId)
{
auto *app = getApp();
if (!app->accounts->twitch.isLoggedIn())
if (!app->getAccounts()->twitch.isLoggedIn())
{
if (!message.isEmpty())
{
@@ -864,7 +864,8 @@ void TwitchChannel::joinBttvChannel() const
{
if (getApp()->twitch->bttvLiveUpdates)
{
const auto currentAccount = getApp()->accounts->twitch.getCurrent();
const auto currentAccount =
getIApp()->getAccounts()->twitch.getCurrent();
QString userName;
if (currentAccount && !currentAccount->isAnon())
{
@@ -1307,7 +1308,7 @@ void TwitchChannel::refreshPubSub()
return;
}
auto currentAccount = getApp()->accounts->twitch.getCurrent();
auto currentAccount = getIApp()->getAccounts()->twitch.getCurrent();
getIApp()->getTwitchPubSub()->setAccount(currentAccount);
@@ -1342,7 +1343,8 @@ void TwitchChannel::refreshChatters()
// Get chatter list via helix api
getHelix()->getChatters(
this->roomId(), getApp()->accounts->twitch.getCurrent()->getUserId(),
this->roomId(),
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(),
MAX_CHATTERS_TO_FETCH,
[this, weak = weakOf<Channel>(this)](auto result) {
if (auto shared = weak.lock())
@@ -1731,7 +1733,7 @@ void TwitchChannel::updateSevenTVActivity()
QStringLiteral("https://7tv.io/v3/users/%1/presences");
const auto currentSeventvUserID =
getApp()->accounts->twitch.getCurrent()->getSeventvUserID();
getIApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID();
if (currentSeventvUserID.isEmpty())
{
return;
+2 -2
View File
@@ -66,7 +66,7 @@ TwitchIrcServer::TwitchIrcServer()
void TwitchIrcServer::initialize(Settings &settings, const Paths &paths)
{
getApp()->accounts->twitch.currentUserChanged.connect([this]() {
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this]() {
postToThread([this] {
this->connect();
});
@@ -81,7 +81,7 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection,
ConnectionType type)
{
std::shared_ptr<TwitchAccount> account =
getApp()->accounts->twitch.getCurrent();
getIApp()->getAccounts()->twitch.getCurrent();
qCDebug(chatterinoTwitch) << "logging in as" << account->getUserName();