chore: refactor TwitchIrcServer (#5421)

This commit is contained in:
pajlada
2024-06-01 14:56:40 +02:00
committed by GitHub
parent 2a46ee708e
commit b6dc5d9e03
28 changed files with 373 additions and 163 deletions
+2 -1
View File
@@ -54,7 +54,8 @@ bool FramelessEmbedWindow::nativeEvent(const QByteArray &eventType,
auto channelName = root.value("channel-name").toString();
this->split_->setChannel(
getApp()->twitch->getOrAddChannel(channelName));
getIApp()->getTwitchAbstract()->getOrAddChannel(
channelName));
}
}
}
+9 -8
View File
@@ -254,7 +254,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
const auto &messages = getSampleMiscMessages();
static int index = 0;
const auto &msg = messages[index++ % messages.size()];
getApp()->twitch->addFakeMessage(msg);
getIApp()->getTwitchAbstract()->addFakeMessage(msg);
return "";
});
@@ -262,7 +262,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
const auto &messages = getSampleCheerMessages();
static int index = 0;
const auto &msg = messages[index++ % messages.size()];
getApp()->twitch->addFakeMessage(msg);
getIApp()->getTwitchAbstract()->addFakeMessage(msg);
return "";
});
@@ -270,7 +270,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
const auto &messages = getSampleLinkMessages();
static int index = 0;
const auto &msg = messages[index++ % messages.size()];
getApp()->twitch->addFakeMessage(msg);
getIApp()->getTwitchAbstract()->addFakeMessage(msg);
return "";
});
@@ -286,7 +286,8 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
oMessage->toInner<PubSubMessageMessage>()
->toInner<PubSubCommunityPointsChannelV1Message>();
app->twitch->addFakeMessage(getSampleChannelRewardIRCMessage());
getIApp()->getTwitchAbstract()->addFakeMessage(
getSampleChannelRewardIRCMessage());
getIApp()->getTwitchPubSub()->pointReward.redeemed.invoke(
oInnerMessage->data.value("redemption").toObject());
alt = !alt;
@@ -309,7 +310,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
const auto &messages = getSampleEmoteTestMessages();
static int index = 0;
const auto &msg = messages[index++ % messages.size()];
getApp()->twitch->addFakeMessage(msg);
getIApp()->getTwitchAbstract()->addFakeMessage(msg);
return "";
});
@@ -317,7 +318,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
const auto &messages = getSampleSubMessages();
static int index = 0;
const auto &msg = messages[index++ % messages.size()];
getApp()->twitch->addFakeMessage(msg);
getIApp()->getTwitchAbstract()->addFakeMessage(msg);
return "";
});
#endif
@@ -480,8 +481,8 @@ void Window::addShortcuts()
splitContainer = this->notebook_->getOrAddSelectedPage();
}
Split *split = new Split(splitContainer);
split->setChannel(
getApp()->twitch->getOrAddChannel(si.channelName));
split->setChannel(getIApp()->getTwitchAbstract()->getOrAddChannel(
si.channelName));
split->setFilters(si.filters);
splitContainer->insertSplit(split);
splitContainer->setSelected(split);
+6 -8
View File
@@ -375,35 +375,33 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
return this->selectedChannel_;
}
auto *app = getApp();
switch (this->ui_.notebook->getSelectedIndex())
{
case TAB_TWITCH: {
if (this->ui_.twitch.channel->isChecked())
{
return app->twitch->getOrAddChannel(
return getIApp()->getTwitchAbstract()->getOrAddChannel(
this->ui_.twitch.channelName->text().trimmed());
}
else if (this->ui_.twitch.watching->isChecked())
{
return app->twitch->watchingChannel;
return getIApp()->getTwitch()->getWatchingChannel();
}
else if (this->ui_.twitch.mentions->isChecked())
{
return app->twitch->mentionsChannel;
return getIApp()->getTwitch()->getMentionsChannel();
}
else if (this->ui_.twitch.whispers->isChecked())
{
return app->twitch->whispersChannel;
return getIApp()->getTwitch()->getWhispersChannel();
}
else if (this->ui_.twitch.live->isChecked())
{
return app->twitch->liveChannel;
return getIApp()->getTwitch()->getLiveChannel();
}
else if (this->ui_.twitch.automod->isChecked())
{
return app->twitch->automodChannel;
return getIApp()->getTwitch()->getAutomodChannel();
}
}
break;
+7 -5
View File
@@ -298,21 +298,23 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
menu->addAction(
"Open channel in a new popup window", this,
[loginName] {
auto *app = getApp();
auto *app = getIApp();
auto &window = app->getWindows()->createWindow(
WindowType::Popup, true);
auto *split = window.getNotebook()
.getOrAddSelectedPage()
->appendNewSplit(false);
split->setChannel(app->twitch->getOrAddChannel(
loginName.toLower()));
split->setChannel(
app->getTwitchAbstract()->getOrAddChannel(
loginName.toLower()));
});
menu->addAction(
"Open channel in a new tab", this, [loginName] {
ChannelPtr channel =
getApp()->twitch->getOrAddChannel(
loginName);
getIApp()
->getTwitchAbstract()
->getOrAddChannel(loginName);
auto &nb = getApp()
->getWindows()
->getMainWindow()
@@ -21,7 +21,8 @@ NewPopupItem::NewPopupItem(const QString &channelName)
void NewPopupItem::action()
{
auto channel = getApp()->twitch->getOrAddChannel(this->channelName_);
auto channel =
getIApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_);
getIApp()->getWindows()->openInPopup(channel);
}
+2 -1
View File
@@ -26,7 +26,8 @@ void NewTabItem::action()
SplitContainer *container = nb.addPage(true);
Split *split = new Split(container);
split->setChannel(getApp()->twitch->getOrAddChannel(this->channelName_));
split->setChannel(
getIApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_));
container->insertSplit(split);
}
+12 -9
View File
@@ -1383,17 +1383,20 @@ MessageElementFlags ChannelView::getFlags() const
{
flags.set(MessageElementFlag::ModeratorTools);
}
if (this->underlyingChannel_ == app->twitch->mentionsChannel ||
this->underlyingChannel_ == app->twitch->liveChannel ||
this->underlyingChannel_ == app->twitch->automodChannel)
if (this->underlyingChannel_ ==
getIApp()->getTwitch()->getMentionsChannel() ||
this->underlyingChannel_ ==
getIApp()->getTwitch()->getLiveChannel() ||
this->underlyingChannel_ ==
getIApp()->getTwitch()->getAutomodChannel())
{
flags.set(MessageElementFlag::ChannelName);
flags.unset(MessageElementFlag::ChannelPointReward);
}
}
if (this->sourceChannel_ == app->twitch->mentionsChannel ||
this->sourceChannel_ == app->twitch->automodChannel)
if (this->sourceChannel_ == getIApp()->getTwitch()->getMentionsChannel() ||
this->sourceChannel_ == getIApp()->getTwitch()->getAutomodChannel())
{
flags.set(MessageElementFlag::ChannelName);
}
@@ -1546,8 +1549,8 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area)
.canvasWidth = this->width(),
.isWindowFocused = this->window() == QApplication::activeWindow(),
.isMentions =
this->underlyingChannel_ == getApp()->twitch->mentionsChannel,
.isMentions = this->underlyingChannel_ ==
getIApp()->getTwitch()->getMentionsChannel(),
.y = int(-(messagesSnapshot[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1)))),
@@ -2707,8 +2710,8 @@ void ChannelView::showUserInfoPopup(const QString &userName,
auto *userPopup =
new UserInfoPopup(getSettings()->autoCloseUserPopup, this->split_);
auto contextChannel =
getApp()->twitch->getChannelOrEmpty(alternativePopoutChannel);
auto contextChannel = getIApp()->getTwitchAbstract()->getChannelOrEmpty(
alternativePopoutChannel);
auto openingChannel = this->hasSourceChannel() ? this->sourceChannel_
: this->underlyingChannel_;
userPopup->setData(userName, contextChannel, openingChannel);
+1 -1
View File
@@ -570,7 +570,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
// as an official description from 7TV devs is best
s.showUnlistedSevenTVEmotes.connect(
[]() {
getApp()->twitch->forEachChannelAndSpecialChannels(
getIApp()->getTwitch()->forEachChannelAndSpecialChannels(
[](const auto &c) {
if (c->isTwitchChannel())
{
+1 -1
View File
@@ -272,7 +272,7 @@ Split::Split(QWidget *parent)
std::ignore = this->view_->openChannelIn.connect(
[this](QString twitchChannel, FromTwitchLinkOpenChannelIn openIn) {
ChannelPtr channel =
getApp()->twitch->getOrAddChannel(twitchChannel);
getIApp()->getTwitchAbstract()->getOrAddChannel(twitchChannel);
switch (openIn)
{
case FromTwitchLinkOpenChannelIn::Split: