Automatically load recent messages on reconnect (#3878)

* Add working reconnect recent messages

* Rename method to messagesUpdated

* Use audo declarations

* Add docs to new LimitedQueue methods

* Add more documentation, try atomic loading flag

* Update CHANGELOG.md

* Remove unused include

* Rename 'reconnected' signal to 'connected'

* Reserve before filtering on arbitrary update

* Extract recent messages fetching to own class

* Use std::atomic_flag instead of std::atomic_bool

* Add PostToThread include

* Add chatterino.recentmessages logging

* Remove unneeded parameters, lambda move capture

* Remove TwitchChannel::buildRecentMessages

* Add documentation, use more clear method name

* Reword changelog entry

I think it sounds better like this :)

* Rework how filling in missing messages is handled

This should hopefully prevent issues with filtered channels with old messages
that no longer exist in the underlying channel

* Check existing messages when looking for reply

* Clean up string distribution in file

* Try to improve documentation

* Use std::function for RecentMessagesApi

* Only trigger filledInMessages if we inserted

* Remove old unused lines

* Use make_shared<MessageLayout> instead of new MessageLayout

* Alphabetize QLogging categories

* Reorder CHANGELOG.md
This commit is contained in:
Daniel Sage
2022-08-06 12:18:34 -04:00
committed by GitHub
parent 2dd37ca210
commit 46f43f3ce8
15 changed files with 580 additions and 174 deletions
+57 -1
View File
@@ -187,15 +187,18 @@ public:
*
* @param[in] needle the item to search for
* @param[in] replacement the item to replace needle with
* @tparam Equality function object to use for comparison
* @return the index of the replaced item, or -1 if no replacement took place
*/
template <typename Equals = std::equal_to<T>>
int replaceItem(const T &needle, const T &replacement)
{
std::unique_lock lock(this->mutex_);
Equals eq;
for (int i = 0; i < this->buffer_.size(); ++i)
{
if (this->buffer_[i] == needle)
if (eq(this->buffer_[i], needle))
{
this->buffer_[i] = replacement;
return i;
@@ -224,6 +227,59 @@ public:
return true;
}
/**
* @brief Inserts the given item before another item
*
* @param[in] needle the item to use as positional reference
* @param[in] item the item to insert before needle
* @tparam Equality function object to use for comparison
* @return true if an insertion took place
*/
template <typename Equals = std::equal_to<T>>
bool insertBefore(const T &needle, const T &item)
{
std::unique_lock lock(this->mutex_);
Equals eq;
for (auto it = this->buffer_.begin(); it != this->buffer_.end(); ++it)
{
if (eq(*it, needle))
{
this->buffer_.insert(it, item);
return true;
}
}
return false;
}
/**
* @brief Inserts the given item after another item
*
* @param[in] needle the item to use as positional reference
* @param[in] item the item to insert after needle
* @tparam Equality function object to use for comparison
* @return true if an insertion took place
*/
template <typename Equals = std::equal_to<T>>
bool insertAfter(const T &needle, const T &item)
{
std::unique_lock lock(this->mutex_);
Equals eq;
for (auto it = this->buffer_.begin(); it != this->buffer_.end(); ++it)
{
if (eq(*it, needle))
{
++it; // advance to insert after it
this->buffer_.insert(it, item);
return true;
}
}
return false;
}
[[nodiscard]] LimitedQueueSnapshot<T> getSnapshot() const
{
std::shared_lock lock(this->mutex_);