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
@@ -120,7 +120,8 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
[](const auto &altText, const auto &channel, const auto *message) {
(void)(channel); //unused
(void)(message); //unused
auto uid = getApp()->accounts->twitch.getCurrent()->getUserId();
auto uid =
getIApp()->getAccounts()->twitch.getCurrent()->getUserId();
return uid.isEmpty() ? altText : uid;
},
},
@@ -129,7 +130,8 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
[](const auto &altText, const auto &channel, const auto *message) {
(void)(channel); //unused
(void)(message); //unused
auto name = getApp()->accounts->twitch.getCurrent()->getUserName();
auto name =
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
return name.isEmpty() ? altText : name;
},
},
@@ -560,7 +562,7 @@ bool CommandController::registerPluginCommand(const QString &commandName)
}
this->commands_[commandName] = [commandName](const CommandContext &ctx) {
return getApp()->plugins->tryExecPluginCommand(commandName, ctx);
return getIApp()->getPlugins()->tryExecPluginCommand(commandName, ctx);
};
this->pluginCommands_.append(commandName);
return true;
+20 -9
View File
@@ -219,7 +219,7 @@ QString marker(const CommandContext &ctx)
}
// Avoid Helix calls without Client ID and/or OAuth Token
if (getApp()->accounts->twitch.getCurrent()->isAnon())
if (getIApp()->getAccounts()->twitch.getCurrent()->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
"You need to be logged in to create stream markers!"));
@@ -365,8 +365,12 @@ QString popup(const CommandContext &ctx)
// Popup the current split
if (target.isEmpty())
{
auto *currentPage = dynamic_cast<SplitContainer *>(
getApp()->windows->getMainWindow().getNotebook().getSelectedPage());
auto *currentPage =
dynamic_cast<SplitContainer *>(getIApp()
->getWindows()
->getMainWindow()
.getNotebook()
.getSelectedPage());
if (currentPage != nullptr)
{
auto *currentSplit = currentPage->getSelectedSplit();
@@ -385,7 +389,7 @@ QString popup(const CommandContext &ctx)
// Open channel passed as argument in a popup
auto *app = getApp();
auto targetChannel = app->twitch->getOrAddChannel(target);
app->windows->openInPopup(targetChannel);
app->getWindows()->openInPopup(targetChannel);
return "";
}
@@ -394,8 +398,11 @@ QString clearmessages(const CommandContext &ctx)
{
(void)ctx;
auto *currentPage = dynamic_cast<SplitContainer *>(
getApp()->windows->getMainWindow().getNotebook().getSelectedPage());
auto *currentPage = dynamic_cast<SplitContainer *>(getIApp()
->getWindows()
->getMainWindow()
.getNotebook()
.getSelectedPage());
if (auto *split = currentPage->getSelectedSplit())
{
@@ -580,8 +587,11 @@ QString openUsercard(const CommandContext &ctx)
// try to link to current split if possible
Split *currentSplit = nullptr;
auto *currentPage = dynamic_cast<SplitContainer *>(
getApp()->windows->getMainWindow().getNotebook().getSelectedPage());
auto *currentPage = dynamic_cast<SplitContainer *>(getIApp()
->getWindows()
->getMainWindow()
.getNotebook()
.getSelectedPage());
if (currentPage != nullptr)
{
currentSplit = currentPage->getSelectedSplit();
@@ -592,7 +602,8 @@ QString openUsercard(const CommandContext &ctx)
if (differentChannel || currentSplit == nullptr)
{
// not possible to use current split, try searching for one
const auto &notebook = getApp()->windows->getMainWindow().getNotebook();
const auto &notebook =
getIApp()->getWindows()->getMainWindow().getNotebook();
auto count = notebook.getPageCount();
for (int i = 0; i < count; i++)
{
@@ -34,7 +34,7 @@ QString addModerator(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -34,7 +34,7 @@ QString addVIP(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -33,7 +33,7 @@ QString sendAnnouncement(const CommandContext &ctx)
return "";
}
auto user = getApp()->accounts->twitch.getCurrent();
auto user = getIApp()->getAccounts()->twitch.getCurrent();
if (user->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
@@ -147,7 +147,7 @@ QString sendBan(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
@@ -210,7 +210,7 @@ QString sendBanById(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
@@ -258,7 +258,7 @@ QString sendTimeout(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
@@ -37,7 +37,7 @@ QString blockUser(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
@@ -53,7 +53,7 @@ QString blockUser(const CommandContext &ctx)
target,
[currentUser, channel{ctx.channel},
target](const HelixUser &targetUser) {
getApp()->accounts->twitch.getCurrent()->blockUser(
getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addMessage(makeSystemMessage(
@@ -111,7 +111,7 @@ QString unblockUser(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
@@ -126,7 +126,7 @@ QString unblockUser(const CommandContext &ctx)
getHelix()->getUserByName(
target,
[currentUser, channel{ctx.channel}, target](const auto &targetUser) {
getApp()->accounts->twitch.getCurrent()->unblockUser(
getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addMessage(makeSystemMessage(
@@ -101,7 +101,7 @@ namespace chatterino::commands {
QString emoteOnly(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -131,7 +131,7 @@ QString emoteOnly(const CommandContext &ctx)
QString emoteOnlyOff(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -160,7 +160,7 @@ QString emoteOnlyOff(const CommandContext &ctx)
QString subscribers(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -190,7 +190,7 @@ QString subscribers(const CommandContext &ctx)
QString subscribersOff(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -220,7 +220,7 @@ QString subscribersOff(const CommandContext &ctx)
QString slow(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -267,7 +267,7 @@ QString slow(const CommandContext &ctx)
QString slowOff(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -297,7 +297,7 @@ QString slowOff(const CommandContext &ctx)
QString followers(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -345,7 +345,7 @@ QString followers(const CommandContext &ctx)
QString followersOff(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -375,7 +375,7 @@ QString followersOff(const CommandContext &ctx)
QString uniqueChat(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -405,7 +405,7 @@ QString uniqueChat(const CommandContext &ctx)
QString uniqueChatOff(const CommandContext &ctx)
{
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
@@ -77,7 +77,7 @@ QString chatters(const CommandContext &ctx)
// Refresh chatter list via helix api for mods
getHelix()->getChatters(
ctx.twitchChannel->roomId(),
getApp()->accounts->twitch.getCurrent()->getUserId(), 1,
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 1,
[channel{ctx.channel}](auto result) {
channel->addMessage(
makeSystemMessage(QString("Chatter count: %1.")
@@ -107,7 +107,7 @@ QString testChatters(const CommandContext &ctx)
getHelix()->getChatters(
ctx.twitchChannel->roomId(),
getApp()->accounts->twitch.getCurrent()->getUserId(), 5000,
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 5000,
[channel{ctx.channel}, twitchChannel{ctx.twitchChannel}](auto result) {
QStringList entries;
for (const auto &username : result.chatters)
@@ -21,7 +21,7 @@ QString deleteMessages(TwitchChannel *twitchChannel, const QString &messageID)
{
const auto *commandName = messageID.isEmpty() ? "/clear" : "/delete";
auto user = getApp()->accounts->twitch.getCurrent();
auto user = getIApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -82,7 +82,7 @@ QString getVIPs(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
@@ -137,7 +137,7 @@ QString startRaid(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -195,7 +195,7 @@ QString cancelRaid(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -34,7 +34,7 @@ QString removeModerator(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -34,7 +34,7 @@ QString removeVIP(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -94,15 +94,16 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
MessageBuilder b;
b.emplace<TimestampElement>();
b.emplace<TextElement>(app->accounts->twitch.getCurrent()->getUserName(),
MessageElementFlag::Text, MessageColor::Text,
FontStyle::ChatMediumBold);
b.emplace<TextElement>(
app->getAccounts()->twitch.getCurrent()->getUserName(),
MessageElementFlag::Text, MessageColor::Text,
FontStyle::ChatMediumBold);
b.emplace<TextElement>("->", MessageElementFlag::Text,
getApp()->themes->messages.textColors.system);
getIApp()->getThemes()->messages.textColors.system);
b.emplace<TextElement>(words[1] + ":", MessageElementFlag::Text,
MessageColor::Text, FontStyle::ChatMediumBold);
const auto &acc = app->accounts->twitch.getCurrent();
const auto &acc = app->getAccounts()->twitch.getCurrent();
const auto &accemotes = *acc->accessEmotes();
const auto &bttvemotes = app->twitch->getBttvEmotes();
const auto &ffzemotes = app->twitch->getFfzEmotes();
@@ -208,7 +209,7 @@ QString sendWhisper(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -23,7 +23,7 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating)
return {};
}
auto user = getApp()->accounts->twitch.getCurrent();
auto user = getIApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -24,7 +24,7 @@ QString sendShoutout(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
@@ -100,7 +100,7 @@ QString startCommercial(const CommandContext &ctx)
return "";
}
auto user = getApp()->accounts->twitch.getCurrent();
auto user = getIApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -106,7 +106,7 @@ QString unbanUser(const CommandContext &ctx)
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
@@ -25,7 +25,7 @@ QString updateUserColor(const CommandContext &ctx)
"The /color command only works in Twitch channels."));
return "";
}
auto user = getApp()->accounts->twitch.getCurrent();
auto user = getIApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())