From 96328a5e2566a0970bbedc4fce96cdbdb8113e4f Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 4 Dec 2018 08:56:07 +0100 Subject: [PATCH] fixed pausing while 1k messages are in the channel --- src/providers/twitch/TwitchServer.cpp | 5 +++++ src/widgets/helper/ChannelView.cpp | 25 +++++++++++++++---------- src/widgets/helper/ChannelView.hpp | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/providers/twitch/TwitchServer.cpp b/src/providers/twitch/TwitchServer.cpp index dc492f8f1..8aa4809cd 100644 --- a/src/providers/twitch/TwitchServer.cpp +++ b/src/providers/twitch/TwitchServer.cpp @@ -189,6 +189,11 @@ std::shared_ptr TwitchServer::getCustomChannel( static auto channel = std::make_shared("$$$", chatterino::Channel::Type::Misc); static auto timer = [&] { + for (auto i = 0; i < 1000; i++) + { + channel->addMessage(makeSystemMessage(QString::number(i + 1))); + } + auto timer = new QTimer; QObject::connect(timer, &QTimer::timeout, [] { channel->addMessage( diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index e7221fa48..3ed4afa51 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -246,16 +246,19 @@ void ChannelView::updatePauseTimer() if (this->pauses_.empty()) { /// No pauses so we can stop the timer - this->pauseEnd = boost::none; + this->pauseEnd_ = boost::none; this->pauseTimer_.stop(); + this->scrollBar_->offset(this->pauseScrollOffset_); + this->pauseScrollOffset_ = 0; + this->queueLayout(); } else if (std::any_of(this->pauses_.begin(), this->pauses_.end(), [](auto &&value) { return !value.second; })) { /// Some of the pauses are infinite - this->pauseEnd = boost::none; + this->pauseEnd_ = boost::none; this->pauseTimer_.stop(); } else @@ -266,10 +269,10 @@ void ChannelView::updatePauseTimer() [](auto &&a, auto &&b) { return a.second > b.second; }) ->second.get(); - if (max != this->pauseEnd) + if (max != this->pauseEnd_) { /// Start the timer - this->pauseEnd = max; + this->pauseEnd_ = max; this->pauseTimer_.start( duration_cast(max - SteadyClock::now())); } @@ -605,16 +608,18 @@ void ChannelView::messageAppended(MessagePtr &message, if (this->messages_.pushBack(MessageLayoutPtr(messageRef), deleted)) { - // if (!this->isPaused()) { - if (this->scrollBar_->isAtBottom()) + if (this->paused()) { - this->scrollBar_->scrollToBottom(); + if (!this->scrollBar_->isAtBottom()) + this->pauseScrollOffset_--; } else { - this->scrollBar_->offset(-1); + if (this->scrollBar_->isAtBottom()) + this->scrollBar_->scrollToBottom(); + else + this->scrollBar_->offset(-1); } - // } } if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) @@ -692,7 +697,7 @@ void ChannelView::messageRemoveFromStart(MessagePtr &message) void ChannelView::messageReplaced(size_t index, MessagePtr &replacement) { - if (index >= this->messages_.getSnapshot().size() || index < 0) + if (index >= this->messages_.getSnapshot().size()) { return; } diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 041ced77c..4fa8dd53c 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -159,7 +159,8 @@ private: QTimer pauseTimer_; std::unordered_map> pauses_; - boost::optional pauseEnd; + boost::optional pauseEnd_; + int pauseScrollOffset_ = 0; boost::optional overrideFlags_; MessageLayoutPtr lastReadMessage_;