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())
@@ -38,8 +38,9 @@ void TabCompletionModel::updateResults(const QString &query,
#ifdef CHATTERINO_HAVE_PLUGINS
// Try plugins first
bool done{};
std::tie(done, results) = getApp()->plugins->updateCustomCompletions(
query, fullTextContent, cursorPosition, isFirstWord);
std::tie(done, results) =
getIApp()->getPlugins()->updateCustomCompletions(
query, fullTextContent, cursorPosition, isFirstWord);
if (done)
{
this->setStringList(results);
@@ -71,7 +71,7 @@ void CommandSource::initializeItems()
std::vector<CommandItem> commands;
#ifdef CHATTERINO_HAVE_PLUGINS
for (const auto &command : getApp()->commands->pluginCommands())
for (const auto &command : getIApp()->getCommands()->pluginCommands())
{
addCommand(command, commands);
}
@@ -509,7 +509,7 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
break;
}
getApp()->windows->forceLayoutChannelViews();
getIApp()->getWindows()->forceLayoutChannelViews();
}
} // namespace chatterino
@@ -113,7 +113,7 @@ void UserHighlightModel::customRowSetData(
break;
}
getApp()->windows->forceLayoutChannelViews();
getIApp()->getWindows()->forceLayoutChannelViews();
}
// row into vector item
+1 -1
View File
@@ -58,7 +58,7 @@ std::vector<QString> Hotkey::arguments() const
QString Hotkey::getCategory() const
{
return getApp()->hotkeys->categoryDisplayName(this->category_);
return getIApp()->getHotkeys()->categoryDisplayName(this->category_);
}
Qt::ShortcutContext Hotkey::getContext() const
+1 -1
View File
@@ -95,7 +95,7 @@ bool IgnorePhrase::containsEmote() const
{
if (!this->emotesChecked_)
{
const auto &accvec = getApp()->accounts->twitch.accounts;
const auto &accvec = getIApp()->getAccounts()->twitch.accounts;
for (const auto &acc : accvec)
{
const auto &accemotes = *acc->accessEmotes();
@@ -183,20 +183,20 @@ void NotificationController::checkStream(bool live, QString channelName)
if (Toasts::isEnabled())
{
getApp()->toasts->sendChannelNotification(channelName, QString(),
Platform::Twitch);
getIApp()->getToasts()->sendChannelNotification(channelName, QString(),
Platform::Twitch);
}
if (getSettings()->notificationPlaySound &&
!(isInStreamerMode() &&
getSettings()->streamerModeSuppressLiveNotifications))
{
getApp()->notifications->playSound();
getIApp()->getNotifications()->playSound();
}
if (getSettings()->notificationFlashTaskbar &&
!(isInStreamerMode() &&
getSettings()->streamerModeSuppressLiveNotifications))
{
getApp()->windows->sendAlert();
getIApp()->getWindows()->sendAlert();
}
MessageBuilder builder;
TwitchMessageBuilder::liveMessage(channelName, &builder);
+10 -9
View File
@@ -63,7 +63,7 @@ namespace chatterino::lua::api {
int c2_register_command(lua_State *L)
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "internal error: no plugin");
@@ -97,7 +97,7 @@ int c2_register_command(lua_State *L)
int c2_register_callback(lua_State *L)
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "internal error: no plugin");
@@ -155,7 +155,7 @@ int c2_send_msg(lua_State *L)
const auto chn = getApp()->twitch->getChannelOrEmpty(channel);
if (chn->isEmpty())
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
qCWarning(chatterinoLua)
<< "Plugin" << pl->id
@@ -166,7 +166,8 @@ int c2_send_msg(lua_State *L)
}
QString message = text;
message = message.replace('\n', ' ');
QString outText = getApp()->commands->execCommand(message, chn, false);
QString outText =
getIApp()->getCommands()->execCommand(message, chn, false);
chn->sendMessage(outText);
lua::push(L, true);
return 1;
@@ -203,7 +204,7 @@ int c2_system_msg(lua_State *L)
const auto chn = getApp()->twitch->getChannelOrEmpty(channel);
if (chn->isEmpty())
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
qCWarning(chatterinoLua)
<< "Plugin" << pl->id
<< "tried to show a system message (using system_msg) in channel"
@@ -218,7 +219,7 @@ int c2_system_msg(lua_State *L)
int c2_log(lua_State *L)
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "c2_log: internal error: no plugin?");
@@ -285,7 +286,7 @@ int g_load(lua_State *L)
int loadfile(lua_State *L, const QString &str)
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
return luaL_error(L, "loadfile: internal error: no plugin?");
@@ -327,7 +328,7 @@ int searcherAbsolute(lua_State *L)
name = name.replace('.', QDir::separator());
QString filename;
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
return luaL_error(L, "searcherAbsolute: internal error: no plugin?");
@@ -368,7 +369,7 @@ int searcherRelative(lua_State *L)
int g_print(lua_State *L)
{
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "c2_print: internal error: no plugin?");
+1 -1
View File
@@ -146,7 +146,7 @@ bool Plugin::registerCommand(const QString &name, const QString &functionName)
return false;
}
auto ok = getApp()->commands->registerPluginCommand(name);
auto ok = getIApp()->getCommands()->registerPluginCommand(name);
if (!ok)
{
return false;
+1 -1
View File
@@ -281,7 +281,7 @@ bool PluginController::reload(const QString &id)
}
for (const auto &[cmd, _] : it->second->ownedCommands)
{
getApp()->commands->unregisterPluginCommand(cmd);
getIApp()->getCommands()->unregisterPluginCommand(cmd);
}
it->second->ownedCommands.clear();
QDir loadDir = it->second->loadDirectory_;