refactor: simplify uses of getMessageSnapshot (#6607)

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2025-11-29 12:40:06 +01:00
committed by GitHub
parent 6756374b5b
commit 041674b7f6
9 changed files with 31 additions and 28 deletions
@@ -6,6 +6,8 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "util/Twitch.hpp"
#include <ranges>
namespace chatterino::commands {
QString sendReply(const CommandContext &ctx)
@@ -32,9 +34,8 @@ QString sendReply(const CommandContext &ctx)
stripChannelName(username);
auto snapshot = ctx.twitchChannel->getMessageSnapshot();
for (auto it = snapshot.rbegin(); it != snapshot.rend(); ++it)
for (const auto &msg : snapshot | std::views::reverse)
{
const auto &msg = *it;
if (msg->loginName.compare(username, Qt::CaseInsensitive) == 0)
{
// found most recent message by user
@@ -16,6 +16,8 @@
#include <QUrl>
#include <ranges>
namespace ranges = std::ranges;
namespace chatterino {
@@ -154,19 +156,10 @@ void NotificationController::notifyTwitchChannelLive(
void NotificationController::notifyTwitchChannelOffline(const QString &id) const
{
// "delete" old 'CHANNEL is live' message
const std::vector<MessagePtr> snapshot =
auto snapshot =
getApp()->getTwitch()->getLiveChannel()->getMessageSnapshot(200);
// Guard against empty snapshot to prevent underflow and invalid access
if (snapshot.size() == 0)
for (const auto &s : snapshot | std::views::reverse)
{
return;
}
for (size_t i = snapshot.size() - 1; i >= 0; --i)
{
const auto &s = snapshot[i];
if (s->id == id)
{
s->flags.set(MessageFlag::Disabled);