feat: add option to suppress live notifications on startup (#5388)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "util/QCompareCaseInsensitive.hpp"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
@@ -10,6 +11,7 @@ namespace chatterino {
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
struct HelixStream;
|
||||
|
||||
class NotificationModel;
|
||||
|
||||
@@ -17,34 +19,58 @@ enum class Platform : uint8_t {
|
||||
Twitch, // 0
|
||||
};
|
||||
|
||||
class NotificationController final : public Singleton, private QObject
|
||||
class NotificationController final : public Singleton
|
||||
{
|
||||
public:
|
||||
void initialize(Settings &settings, const Paths &paths) override;
|
||||
|
||||
bool isChannelNotified(const QString &channelName, Platform p);
|
||||
bool isChannelNotified(const QString &channelName, Platform p) const;
|
||||
void updateChannelNotification(const QString &channelName, Platform p);
|
||||
void addChannelNotification(const QString &channelName, Platform p);
|
||||
void removeChannelNotification(const QString &channelName, Platform p);
|
||||
|
||||
void playSound();
|
||||
struct NotificationPayload {
|
||||
QString channelId;
|
||||
QString channelName;
|
||||
QString displayName;
|
||||
QString title;
|
||||
bool isInitialUpdate = false;
|
||||
};
|
||||
|
||||
SignalVector<QString> getVector(Platform p);
|
||||
/// @brief Sends out notifications for a channel that has gone live
|
||||
///
|
||||
/// This doesn't check for duplicate notifications.
|
||||
void notifyTwitchChannelLive(const NotificationPayload &payload) const;
|
||||
|
||||
std::map<Platform, SignalVector<QString>> channelMap;
|
||||
/// @brief Sends out notifications for a channel that has gone offline
|
||||
///
|
||||
/// This doesn't check for duplicate notifications.
|
||||
void notifyTwitchChannelOffline(const QString &id) const;
|
||||
|
||||
void playSound() const;
|
||||
|
||||
NotificationModel *createModel(QObject *parent, Platform p);
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
|
||||
void fetchFakeChannels();
|
||||
void removeFakeChannel(const QString channelName);
|
||||
void checkStream(bool live, QString channelName);
|
||||
void removeFakeChannel(const QString &channelName);
|
||||
void updateFakeChannel(const QString &channelName,
|
||||
const std::optional<HelixStream> &stream);
|
||||
|
||||
// fakeTwitchChannels is a list of streams who are live that we have already sent out a notification for
|
||||
std::vector<QString> fakeTwitchChannels;
|
||||
QTimer *liveStatusTimer_;
|
||||
struct FakeChannel {
|
||||
QString id;
|
||||
bool isLive = false;
|
||||
};
|
||||
|
||||
/// @brief This map tracks channels without an associated TwitchChannel
|
||||
///
|
||||
/// These channels won't be tracked in LiveController.
|
||||
/// Channels are identified by their login name (case insensitive).
|
||||
std::map<QString, FakeChannel, QCompareCaseInsensitive> fakeChannels_;
|
||||
|
||||
QTimer liveStatusTimer_;
|
||||
|
||||
std::map<Platform, SignalVector<QString>> channelMap;
|
||||
|
||||
ChatterinoSetting<std::vector<QString>> twitchSetting_ = {
|
||||
"/notifications/twitch"};
|
||||
|
||||
Reference in New Issue
Block a user