feat(plugins): Added message read/update methods to the Channel API. (#6650)
This PR adds methods to read and update messages in a channel. Specifically, it adds: - message_snapshot - last_message - replace_message/replace_message_at - clear_messages - find_message_by_id - has_messages - count_messages Reviewed-by: Mm2PL <mm2pl+gh@kotmisia.pl>
This commit is contained in:
@@ -75,6 +75,11 @@ bool Channel::hasMessages() const
|
||||
return !this->messages_.empty();
|
||||
}
|
||||
|
||||
size_t Channel::countMessages() const
|
||||
{
|
||||
return this->messages_.size();
|
||||
}
|
||||
|
||||
std::vector<MessagePtr> Channel::getMessageSnapshot() const
|
||||
{
|
||||
return this->messages_.getSnapshot();
|
||||
@@ -85,6 +90,13 @@ std::vector<MessagePtr> Channel::getMessageSnapshot(size_t nItems) const
|
||||
return this->messages_.lastN(nItems);
|
||||
}
|
||||
|
||||
std::vector<MessagePtrMut> Channel::getMessageSnapshotMut(size_t nItems) const
|
||||
{
|
||||
return this->messages_.lastNBy<MessagePtrMut>(nItems, [](const auto &msg) {
|
||||
return std::const_pointer_cast<Message>(msg);
|
||||
});
|
||||
}
|
||||
|
||||
MessagePtr Channel::getLastMessage() const
|
||||
{
|
||||
auto last = this->messages_.last();
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace chatterino {
|
||||
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
using MessagePtrMut = std::shared_ptr<Message>;
|
||||
|
||||
class Channel : public std::enable_shared_from_this<Channel>, public MessageSink
|
||||
{
|
||||
@@ -87,6 +88,12 @@ public:
|
||||
std::vector<MessagePtr> getMessageSnapshot() const;
|
||||
std::vector<MessagePtr> getMessageSnapshot(size_t nItems) const;
|
||||
|
||||
/// Essentially the same as #getMessageSnapshot(size_t), but the returned
|
||||
/// vector holds `std::shared_ptr<Message>`. This should only be used in
|
||||
/// plugins, because they take messages as `Message` but check that they're
|
||||
/// frozen.
|
||||
std::vector<MessagePtrMut> getMessageSnapshotMut(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;
|
||||
@@ -122,6 +129,8 @@ public:
|
||||
|
||||
bool hasMessages() const;
|
||||
|
||||
size_t countMessages() const;
|
||||
|
||||
void applySimilarityFilters(const MessagePtr &message) const final;
|
||||
|
||||
MessageSinkTraits sinkTraits() const final;
|
||||
|
||||
Reference in New Issue
Block a user