From c4679bf048146c8535e5fe3dc37b24dc98c86e11 Mon Sep 17 00:00:00 2001 From: apa420 Date: Sat, 25 Aug 2018 14:13:26 +0200 Subject: [PATCH] almost implemented the faekchannels, just need to fix the timer, pls help pajlada --- .../notifications/NotificationController.cpp | 99 +++++++++++++++++++ .../notifications/NotificationController.hpp | 9 ++ src/singletons/Settings.hpp | 1 - .../settingspages/NotificationPage.cpp | 3 - src/widgets/splits/SplitHeader.cpp | 3 - 5 files changed, 108 insertions(+), 7 deletions(-) diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 325e92998..54a964cfb 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -1,8 +1,12 @@ #include "controllers/notifications/NotificationController.hpp" #include "Application.hpp" +#include "common/NetworkRequest.hpp" #include "controllers/notifications/NotificationModel.hpp" +#include "providers/twitch/TwitchApi.hpp" +#include "providers/twitch/TwitchServer.hpp" #include "singletons/Toasts.hpp" +#include "singletons/WindowManager.hpp" #include @@ -34,6 +38,16 @@ void NotificationController::initialize(Settings &settings, Paths &paths) this->channelMap[Platform::Mixer].getVector()); }); */ + + /* + connect(liveStatusTimer_, SIGNAL(timeout()), this, SLOT()); + liveStatusTimer_.start(60 * 1000); + */ + liveStatusTimer_ = new QTimer(); + QObject::connect(liveStatusTimer_, this, SIGNAL(timeout()), + SLOT(fetchFakeChannels())); + connect(liveStatusTimer_, SIGNAL(timeout()), SLOT(fetchFakeChannels())); + liveStatusTimer_->start(1000); } void NotificationController::updateChannelNotification( @@ -102,4 +116,89 @@ NotificationModel *NotificationController::createModel(QObject *parent, return model; } +void NotificationController::fetchFakeChannels() +{ + for (std::vector::size_type i = 0; + i != channelMap[Platform::Twitch].getVector().size(); i++) { + auto chan = getApp()->twitch.server->getChannelOrEmpty( + channelMap[Platform::Twitch].getVector()[i]); + + /* + auto chan = getApp()->twitch.server->getChannelOrEmpty(chanName); + if (auto *twitchChannel = dynamic_cast(chan.get())) { + if (channelMap[Platform::Twitch].getVector()[i].toLower() == + channelName.toLower()) { channelMap[Platform::Twitch].removeItem(i); + i--; + } + }*/ + } +} + +void NotificationController::getFakeTwitchChannelLiveStatus( + const QString &channelName) +{ + TwitchApi::findUserId(channelName, [channelName, this](QString roomID) { + if (roomID.isEmpty()) { + Log("[TwitchChannel:{}] Refreshing live status (Missing ID)", + channelName); + removeFakeChannel(channelName); + return; + } + Log("[TwitchChannel:{}] Refreshing live status", channelName); + + QString url("https://api.twitch.tv/kraken/streams/" + roomID); + auto request = NetworkRequest::twitchRequest(url); + request.setCaller(QThread::currentThread()); + + request.onSuccess([this, channelName](auto result) -> Outcome { + rapidjson::Document document = result.parseRapidJson(); + if (!document.IsObject()) { + Log("[TwitchChannel:refreshLiveStatus] root is not an object"); + return Failure; + } + + if (!document.HasMember("stream")) { + Log("[TwitchChannel:refreshLiveStatus] Missing stream in root"); + return Failure; + } + + const auto &stream = document["stream"]; + + if (!stream.IsObject()) { + // Stream is offline (stream is most likely null) + removeFakeChannel(channelName); + return Failure; + } + // Stream is live + auto i = std::find(fakeTwitchChannels.begin(), + fakeTwitchChannels.end(), channelName); + if (i != fakeTwitchChannels.end()) { + fakeTwitchChannels.push_back(channelName); + if (Toasts::isEnabled()) { + getApp()->toasts->sendChannelNotification(channelName, + Platform::Twitch); + } + if (getApp()->settings->notificationPlaySound) { + getApp()->notifications->playSound(); + } + if (getApp()->settings->notificationFlashTaskbar) { + QApplication::alert( + getApp()->windows->getMainWindow().window(), 2500); + } + } + }); + + request.execute(); + }); +} + +void NotificationController::removeFakeChannel(const QString channelName) +{ + auto i = std::find(fakeTwitchChannels.begin(), fakeTwitchChannels.end(), + channelName); + if (i != fakeTwitchChannels.end()) { + fakeTwitchChannels.erase(i); + } +} + } // namespace chatterino diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index da5bcd03a..a7cdbaf41 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -3,6 +3,8 @@ #include "common/SignalVector.hpp" #include "singletons/Settings.hpp" +#include + namespace chatterino { class Settings; @@ -35,12 +37,19 @@ public: private: bool initialized_ = false; + QTimer *liveStatusTimer_; + void removeFakeChannel(const QString channelName); + std::vector fakeTwitchChannels; + void getFakeTwitchChannelLiveStatus(const QString &channelName); + ChatterinoSetting> twitchSetting_ = { "/notifications/twitch"}; /* ChatterinoSetting> mixerSetting_ = { "/notifications/mixer"}; */ +private slots: + void fetchFakeChannels(); }; } // namespace chatterino diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 1105470cb..9a286ab33 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -150,7 +150,6 @@ public: "qrc:/sounds/ping3.wav"}; BoolSetting notificationToast = {"/notifications/enableToast", false}; - BoolSetting notificationDot = {"/notifications/enableDot", false}; /// External tools // Streamlink diff --git a/src/widgets/settingspages/NotificationPage.cpp b/src/widgets/settingspages/NotificationPage.cpp index e5ef7b9f0..62b9650e9 100644 --- a/src/widgets/settingspages/NotificationPage.cpp +++ b/src/widgets/settingspages/NotificationPage.cpp @@ -42,9 +42,6 @@ NotificationPage::NotificationPage() "Enable toasts (currently only for windows 8.x or 10)", getApp()->settings->notificationToast)); #endif - settings.append( - this->createCheckBox("Red dot next to live splits", - getApp()->settings->notificationDot)); auto customSound = layout.emplace().withoutMargin(); { diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 5cc4d85fe..aa28bb18c 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -383,9 +383,6 @@ void SplitHeader::updateChannelText() } else { title += " (live)"; } - if (getSettings()->notificationDot) { - title += QByteArray(" 🔴 "); - } if (getSettings()->showViewerCount) { title += " - " + QString::number(streamStatus->viewerCount) + " viewers";