From 74960bf419d47a46285caa7c9e294d7db0235524 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 19 Jun 2021 19:27:31 +0200 Subject: [PATCH] Communicate streams that went offline through /live (#2880) Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/providers/twitch/TwitchChannel.cpp | 22 +++++++++++++++++++ src/providers/twitch/TwitchMessageBuilder.cpp | 3 +++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 227776dc9..125b0e93e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Major: Added username autocompletion popup menu when typing usernames with an @ prefix. (#1979, #2866) - Major: Added ability to toggle visibility of Channel Tabs - This can be done by right-clicking the tab area or pressing the keyboard shortcut (default: Ctrl+U). (#2600) +- Minor: The /live split now shows channels going offline. (#2880) - Minor: Restore automod functionality for moderators (#2817, #2887) - Minor: Add setting for username style (#2889, #2891) - Minor: Searching for users in the viewer list now searches anywhere in the user's name. (#2861) diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 1105e593d..2e49f5d2b 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -607,10 +607,32 @@ void TwitchChannel::setLive(bool newLiveStatus) } else { + // Channel offline message MessageBuilder builder; TwitchMessageBuilder::offlineSystemMessage( this->getDisplayName(), &builder); this->addMessage(builder.release()); + + // "delete" old 'CHANNEL is live' message + LimitedQueueSnapshot snapshot = + getApp()->twitch2->liveChannel->getMessageSnapshot(); + int snapshotLength = snapshot.size(); + + // MSVC hates this code if the parens are not there + int end = (std::max)(0, snapshotLength - 200); + auto liveMessageSearchText = + QString("%1 is live!").arg(this->getDisplayName()); + + for (int i = snapshotLength - 1; i >= end; --i) + { + auto &s = snapshot[i]; + + if (s->messageText == liveMessageSearchText) + { + s->flags.set(MessageFlag::Disabled); + break; + } + } } guard->live = newLiveStatus; } diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index b6f041c38..ba430a105 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1309,6 +1309,9 @@ void TwitchMessageBuilder::liveMessage(const QString &channelName, ->setLink({Link::UserInfo, channelName}); builder->emplace("is live!", MessageElementFlag::Text, MessageColor::Text); + auto text = channelName + " is live!"; + builder->message().searchText = text; + builder->message().messageText = text; } void TwitchMessageBuilder::liveSystemMessage(const QString &channelName,