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:
@@ -657,6 +657,17 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
|
||||
this->channel_->replaceMessage(index, replacement);
|
||||
});
|
||||
|
||||
this->channelConnections_.managedConnect(
|
||||
underlyingChannel->filledInMessages, [this](const auto &messages) {
|
||||
std::vector<MessagePtr> filtered;
|
||||
filtered.reserve(messages.size());
|
||||
std::copy_if(messages.begin(), messages.end(),
|
||||
std::back_inserter(filtered), [this](MessagePtr msg) {
|
||||
return this->shouldIncludeMessage(msg);
|
||||
});
|
||||
this->channel_->fillInMissingMessages(filtered);
|
||||
});
|
||||
|
||||
//
|
||||
// Standard channel connections
|
||||
//
|
||||
@@ -688,11 +699,17 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
|
||||
this->messageReplaced(index, replacement);
|
||||
});
|
||||
|
||||
// on messages filled in
|
||||
this->channelConnections_.managedConnect(this->channel_->filledInMessages,
|
||||
[this](const auto &) {
|
||||
this->messagesUpdated();
|
||||
});
|
||||
|
||||
auto snapshot = underlyingChannel->getMessageSnapshot();
|
||||
|
||||
for (const auto &msg : snapshot)
|
||||
{
|
||||
auto messageLayout = new MessageLayout(msg);
|
||||
auto messageLayout = std::make_shared<MessageLayout>(msg);
|
||||
|
||||
if (this->lastMessageHasAlternateBackground_)
|
||||
{
|
||||
@@ -706,7 +723,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
|
||||
messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights);
|
||||
}
|
||||
|
||||
this->messages_.pushBack(MessageLayoutPtr(messageLayout));
|
||||
this->messages_.pushBack(messageLayout);
|
||||
if (this->showScrollbarHighlights())
|
||||
{
|
||||
this->scrollBar_->addHighlight(msg->getScrollBarHighlight());
|
||||
@@ -787,7 +804,7 @@ void ChannelView::messageAppended(MessagePtr &message,
|
||||
messageFlags = overridingFlags.get_ptr();
|
||||
}
|
||||
|
||||
auto messageRef = new MessageLayout(message);
|
||||
auto messageRef = std::make_shared<MessageLayout>(message);
|
||||
|
||||
if (this->lastMessageHasAlternateBackground_)
|
||||
{
|
||||
@@ -812,7 +829,7 @@ void ChannelView::messageAppended(MessagePtr &message,
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
if (this->messages_.pushBack(MessageLayoutPtr(messageRef)))
|
||||
if (this->messages_.pushBack(messageRef))
|
||||
{
|
||||
if (this->paused())
|
||||
{
|
||||
@@ -863,7 +880,7 @@ void ChannelView::messageAddedAtStart(std::vector<MessagePtr> &messages)
|
||||
for (size_t i = 0; i < messages.size(); i++)
|
||||
{
|
||||
auto message = messages.at(i);
|
||||
auto layout = new MessageLayout(message);
|
||||
auto layout = std::make_shared<MessageLayout>(message);
|
||||
|
||||
// alternate color
|
||||
if (!this->lastMessageHasAlternateBackgroundReverse_)
|
||||
@@ -871,7 +888,7 @@ void ChannelView::messageAddedAtStart(std::vector<MessagePtr> &messages)
|
||||
this->lastMessageHasAlternateBackgroundReverse_ =
|
||||
!this->lastMessageHasAlternateBackgroundReverse_;
|
||||
|
||||
messageRefs.at(i) = MessageLayoutPtr(layout);
|
||||
messageRefs.at(i) = std::move(layout);
|
||||
}
|
||||
|
||||
/// Add the messages at the start
|
||||
@@ -926,7 +943,7 @@ void ChannelView::messageReplaced(size_t index, MessagePtr &replacement)
|
||||
|
||||
auto message = *oMessage;
|
||||
|
||||
MessageLayoutPtr newItem(new MessageLayout(replacement));
|
||||
auto newItem = std::make_shared<MessageLayout>(replacement);
|
||||
|
||||
if (message->flags.has(MessageLayoutFlag::AlternateBackground))
|
||||
{
|
||||
@@ -940,6 +957,41 @@ void ChannelView::messageReplaced(size_t index, MessagePtr &replacement)
|
||||
this->queueLayout();
|
||||
}
|
||||
|
||||
void ChannelView::messagesUpdated()
|
||||
{
|
||||
auto snapshot = this->channel_->getMessageSnapshot();
|
||||
|
||||
this->messages_.clear();
|
||||
this->scrollBar_->clearHighlights();
|
||||
this->lastMessageHasAlternateBackground_ = false;
|
||||
this->lastMessageHasAlternateBackgroundReverse_ = true;
|
||||
|
||||
for (const auto &msg : snapshot)
|
||||
{
|
||||
auto messageLayout = std::make_shared<MessageLayout>(msg);
|
||||
|
||||
if (this->lastMessageHasAlternateBackground_)
|
||||
{
|
||||
messageLayout->flags.set(MessageLayoutFlag::AlternateBackground);
|
||||
}
|
||||
this->lastMessageHasAlternateBackground_ =
|
||||
!this->lastMessageHasAlternateBackground_;
|
||||
|
||||
if (this->channel_->shouldIgnoreHighlights())
|
||||
{
|
||||
messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights);
|
||||
}
|
||||
|
||||
this->messages_.pushBack(messageLayout);
|
||||
if (this->showScrollbarHighlights())
|
||||
{
|
||||
this->scrollBar_->addHighlight(msg->getScrollBarHighlight());
|
||||
}
|
||||
}
|
||||
|
||||
this->queueLayout();
|
||||
}
|
||||
|
||||
void ChannelView::updateLastReadMessage()
|
||||
{
|
||||
if (auto lastMessage = this->messages_.last())
|
||||
|
||||
Reference in New Issue
Block a user