almost implemented the faekchannels, just need to fix the timer, pls help pajlada
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
#include "controllers/notifications/NotificationController.hpp"
|
#include "controllers/notifications/NotificationController.hpp"
|
||||||
|
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
|
#include "common/NetworkRequest.hpp"
|
||||||
#include "controllers/notifications/NotificationModel.hpp"
|
#include "controllers/notifications/NotificationModel.hpp"
|
||||||
|
#include "providers/twitch/TwitchApi.hpp"
|
||||||
|
#include "providers/twitch/TwitchServer.hpp"
|
||||||
#include "singletons/Toasts.hpp"
|
#include "singletons/Toasts.hpp"
|
||||||
|
#include "singletons/WindowManager.hpp"
|
||||||
|
|
||||||
#include <wintoastlib.h>
|
#include <wintoastlib.h>
|
||||||
|
|
||||||
@@ -34,6 +38,16 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
|
|||||||
this->channelMap[Platform::Mixer].getVector());
|
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(
|
void NotificationController::updateChannelNotification(
|
||||||
@@ -102,4 +116,89 @@ NotificationModel *NotificationController::createModel(QObject *parent,
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotificationController::fetchFakeChannels()
|
||||||
|
{
|
||||||
|
for (std::vector<int>::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<TwitchChannel *>(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
|
} // namespace chatterino
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Settings;
|
class Settings;
|
||||||
@@ -35,12 +37,19 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
QTimer *liveStatusTimer_;
|
||||||
|
void removeFakeChannel(const QString channelName);
|
||||||
|
std::vector<QString> fakeTwitchChannels;
|
||||||
|
void getFakeTwitchChannelLiveStatus(const QString &channelName);
|
||||||
|
|
||||||
ChatterinoSetting<std::vector<QString>> twitchSetting_ = {
|
ChatterinoSetting<std::vector<QString>> twitchSetting_ = {
|
||||||
"/notifications/twitch"};
|
"/notifications/twitch"};
|
||||||
/*
|
/*
|
||||||
ChatterinoSetting<std::vector<QString>> mixerSetting_ = {
|
ChatterinoSetting<std::vector<QString>> mixerSetting_ = {
|
||||||
"/notifications/mixer"};
|
"/notifications/mixer"};
|
||||||
*/
|
*/
|
||||||
|
private slots:
|
||||||
|
void fetchFakeChannels();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ public:
|
|||||||
"qrc:/sounds/ping3.wav"};
|
"qrc:/sounds/ping3.wav"};
|
||||||
|
|
||||||
BoolSetting notificationToast = {"/notifications/enableToast", false};
|
BoolSetting notificationToast = {"/notifications/enableToast", false};
|
||||||
BoolSetting notificationDot = {"/notifications/enableDot", false};
|
|
||||||
|
|
||||||
/// External tools
|
/// External tools
|
||||||
// Streamlink
|
// Streamlink
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ NotificationPage::NotificationPage()
|
|||||||
"Enable toasts (currently only for windows 8.x or 10)",
|
"Enable toasts (currently only for windows 8.x or 10)",
|
||||||
getApp()->settings->notificationToast));
|
getApp()->settings->notificationToast));
|
||||||
#endif
|
#endif
|
||||||
settings.append(
|
|
||||||
this->createCheckBox("Red dot next to live splits",
|
|
||||||
getApp()->settings->notificationDot));
|
|
||||||
auto customSound =
|
auto customSound =
|
||||||
layout.emplace<QHBoxLayout>().withoutMargin();
|
layout.emplace<QHBoxLayout>().withoutMargin();
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -383,9 +383,6 @@ void SplitHeader::updateChannelText()
|
|||||||
} else {
|
} else {
|
||||||
title += " (live)";
|
title += " (live)";
|
||||||
}
|
}
|
||||||
if (getSettings()->notificationDot) {
|
|
||||||
title += QByteArray(" 🔴 ");
|
|
||||||
}
|
|
||||||
if (getSettings()->showViewerCount) {
|
if (getSettings()->showViewerCount) {
|
||||||
title += " - " + QString::number(streamStatus->viewerCount) +
|
title += " - " + QString::number(streamStatus->viewerCount) +
|
||||||
" viewers";
|
" viewers";
|
||||||
|
|||||||
Reference in New Issue
Block a user