mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
almost implemented the faekchannels, just need to fix the timer, pls help pajlada
This commit is contained in:
parent
8f77dccb91
commit
c4679bf048
|
@ -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 <wintoastlib.h>
|
||||
|
||||
|
@ -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<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
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "common/SignalVector.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Settings;
|
||||
|
@ -35,12 +37,19 @@ public:
|
|||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
QTimer *liveStatusTimer_;
|
||||
void removeFakeChannel(const QString channelName);
|
||||
std::vector<QString> fakeTwitchChannels;
|
||||
void getFakeTwitchChannelLiveStatus(const QString &channelName);
|
||||
|
||||
ChatterinoSetting<std::vector<QString>> twitchSetting_ = {
|
||||
"/notifications/twitch"};
|
||||
/*
|
||||
ChatterinoSetting<std::vector<QString>> mixerSetting_ = {
|
||||
"/notifications/mixer"};
|
||||
*/
|
||||
private slots:
|
||||
void fetchFakeChannels();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -150,7 +150,6 @@ public:
|
|||
"qrc:/sounds/ping3.wav"};
|
||||
|
||||
BoolSetting notificationToast = {"/notifications/enableToast", false};
|
||||
BoolSetting notificationDot = {"/notifications/enableDot", false};
|
||||
|
||||
/// External tools
|
||||
// Streamlink
|
||||
|
|
|
@ -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<QHBoxLayout>().withoutMargin();
|
||||
{
|
||||
|
|
|
@ -383,9 +383,6 @@ void SplitHeader::updateChannelText()
|
|||
} else {
|
||||
title += " (live)";
|
||||
}
|
||||
if (getSettings()->notificationDot) {
|
||||
title += QByteArray(" 🔴 ");
|
||||
}
|
||||
if (getSettings()->showViewerCount) {
|
||||
title += " - " + QString::number(streamStatus->viewerCount) +
|
||||
" viewers";
|
||||
|
|
Loading…
Reference in a new issue