feat: add option to suppress live notifications on startup (#5388)

This commit is contained in:
nerix
2024-07-20 14:19:27 +02:00
committed by GitHub
parent 4a7a5b09ce
commit 0495fbca43
11 changed files with 398 additions and 225 deletions
+43 -83
View File
@@ -133,86 +133,6 @@ TwitchChannel::TwitchChannel(const QString &name)
});
this->threadClearTimer_.start(5 * 60 * 1000);
auto onLiveStatusChanged = [this](auto isLive) {
if (isLive)
{
qCDebug(chatterinoTwitch)
<< "[TwitchChannel" << this->getName() << "] Online";
if (getIApp()->getNotifications()->isChannelNotified(
this->getName(), Platform::Twitch))
{
if (Toasts::isEnabled())
{
getIApp()->getToasts()->sendChannelNotification(
this->getName(), this->accessStreamStatus()->title,
Platform::Twitch);
}
if (getSettings()->notificationPlaySound)
{
getIApp()->getNotifications()->playSound();
}
if (getSettings()->notificationFlashTaskbar)
{
getIApp()->getWindows()->sendAlert();
}
}
// Channel live message
MessageBuilder builder;
TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(),
&builder);
builder.message().id = this->roomId();
this->addMessage(builder.release(), MessageContext::Original);
// Message in /live channel
MessageBuilder builder2;
TwitchMessageBuilder::liveMessage(this->getDisplayName(),
&builder2);
builder2.message().id = this->roomId();
getIApp()->getTwitch()->getLiveChannel()->addMessage(
builder2.release(), MessageContext::Original);
// Notify on all channels with a ping sound
if (getSettings()->notificationOnAnyChannel &&
!(getIApp()->getStreamerMode()->isEnabled() &&
getSettings()->streamerModeSuppressLiveNotifications))
{
getIApp()->getNotifications()->playSound();
}
}
else
{
qCDebug(chatterinoTwitch)
<< "[TwitchChannel" << this->getName() << "] Offline";
// Channel offline message
MessageBuilder builder;
TwitchMessageBuilder::offlineSystemMessage(this->getDisplayName(),
&builder);
this->addMessage(builder.release(), MessageContext::Original);
// "delete" old 'CHANNEL is live' message
LimitedQueueSnapshot<MessagePtr> snapshot =
getIApp()->getTwitch()->getLiveChannel()->getMessageSnapshot();
int snapshotLength = snapshot.size();
// MSVC hates this code if the parens are not there
int end = (std::max)(0, snapshotLength - 200);
for (int i = snapshotLength - 1; i >= end; --i)
{
const auto &s = snapshot[i];
if (s->id == this->roomId())
{
s->flags.set(MessageFlag::Disabled);
break;
}
}
}
};
this->signalHolder_.managedConnect(this->liveStatusChanged,
onLiveStatusChanged);
// debugging
#if 0
for (int i = 0; i < 1000; i++) {
@@ -450,7 +370,7 @@ std::optional<ChannelPointReward> TwitchChannel::channelPointReward(
}
void TwitchChannel::updateStreamStatus(
const std::optional<HelixStream> &helixStream)
const std::optional<HelixStream> &helixStream, bool isInitialUpdate)
{
if (helixStream)
{
@@ -483,7 +403,7 @@ void TwitchChannel::updateStreamStatus(
}
if (this->setLive(true))
{
this->liveStatusChanged.invoke(true);
this->onLiveStatusChanged(true, isInitialUpdate);
}
this->streamStatusChanged.invoke();
}
@@ -491,12 +411,52 @@ void TwitchChannel::updateStreamStatus(
{
if (this->setLive(false))
{
this->liveStatusChanged.invoke(false);
this->onLiveStatusChanged(false, isInitialUpdate);
this->streamStatusChanged.invoke();
}
}
}
void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
{
// Similar code exists in NotificationController::updateFakeChannel.
// Since we're a TwitchChannel, we also send a message here.
if (isLive)
{
qCDebug(chatterinoTwitch).nospace().noquote()
<< "[TwitchChannel " << this->getName() << "] Online";
getIApp()->getNotifications()->notifyTwitchChannelLive({
.channelId = this->roomId(),
.channelName = this->getName(),
.displayName = this->getDisplayName(),
.title = this->accessStreamStatus()->title,
.isInitialUpdate = isInitialUpdate,
});
// Channel live message
MessageBuilder builder;
TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(),
&builder);
builder.message().id = this->roomId();
this->addMessage(builder.release(), MessageContext::Original);
}
else
{
qCDebug(chatterinoTwitch).nospace().noquote()
<< "[TwitchChannel " << this->getName() << "] Offline";
// Channel offline message
MessageBuilder builder;
TwitchMessageBuilder::offlineSystemMessage(this->getDisplayName(),
&builder);
this->addMessage(builder.release(), MessageContext::Original);
getIApp()->getNotifications()->notifyTwitchChannelOffline(
this->roomId());
}
};
void TwitchChannel::updateStreamTitle(const QString &title)
{
{
+4 -9
View File
@@ -238,14 +238,6 @@ public:
// Only TwitchChannel may invoke this signal
pajlada::Signals::NoArgSignal userStateChanged;
/**
* This signals fires whenever the live status is changed
*
* Streams are counted as offline by default, so if a stream does not go online
* this signal will never fire
**/
pajlada::Signals::Signal<bool> liveStatusChanged;
/**
* This signal fires whenever the stream status is changed
*
@@ -270,7 +262,8 @@ public:
const QString &rewardId) const;
// Live status
void updateStreamStatus(const std::optional<HelixStream> &helixStream);
void updateStreamStatus(const std::optional<HelixStream> &helixStream,
bool isInitialUpdate);
void updateStreamTitle(const QString &title);
/**
@@ -338,6 +331,8 @@ private:
void setDisplayName(const QString &name);
void setLocalizedName(const QString &name);
void onLiveStatusChanged(bool isLive, bool isInitialUpdate);
/**
* Returns the localized name of the user
**/