refactor: simplify uses of getMessageSnapshot (#6607)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
+12
-6
@@ -81,6 +81,16 @@ std::vector<MessagePtr> Channel::getMessageSnapshot(size_t nItems) const
|
||||
return this->messages_.lastN(nItems);
|
||||
}
|
||||
|
||||
MessagePtr Channel::getLastMessage() const
|
||||
{
|
||||
auto last = this->messages_.last();
|
||||
if (last)
|
||||
{
|
||||
return *std::move(last);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Channel::addMessage(MessagePtr message, MessageContext context,
|
||||
std::optional<MessageFlags> overridingFlags)
|
||||
{
|
||||
@@ -146,19 +156,15 @@ void Channel::addOrReplaceClearChat(MessagePtr message, const QDateTime &now)
|
||||
|
||||
void Channel::disableAllMessages()
|
||||
{
|
||||
std::vector<MessagePtr> snapshot = this->getMessageSnapshot();
|
||||
int snapshotLength = snapshot.size();
|
||||
for (int i = 0; i < snapshotLength; i++)
|
||||
for (const auto &message : this->getMessageSnapshot())
|
||||
{
|
||||
const auto &message = snapshot[i];
|
||||
if (message->flags.hasAny({MessageFlag::System, MessageFlag::Timeout,
|
||||
MessageFlag::Whisper}))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// FOURTF: disabled for now
|
||||
const_cast<Message *>(message.get())->flags.set(MessageFlag::Disabled);
|
||||
message->flags.set(MessageFlag::Disabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +79,14 @@ public:
|
||||
virtual const QString &getLocalizedName() const;
|
||||
bool isTwitchChannel() const;
|
||||
virtual bool isEmpty() const;
|
||||
|
||||
std::vector<MessagePtr> getMessageSnapshot() const;
|
||||
std::vector<MessagePtr> getMessageSnapshot(size_t nItems) const;
|
||||
|
||||
/// Returns the last message (the one at the bottom). If the channel has no
|
||||
/// messages, this will return an empty shared pointer.
|
||||
MessagePtr getLastMessage() const;
|
||||
|
||||
// MESSAGES
|
||||
// overridingFlags can be filled in with flags that should be used instead
|
||||
// of the message's flags. This is useful in case a flag is specific to a
|
||||
|
||||
Reference in New Issue
Block a user