refactor: simplify uses of getMessageSnapshot (#6607)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user