fixed pausing while 1k messages are in the channel

This commit is contained in:
fourtf 2018-12-04 08:56:07 +01:00
parent a618b01c03
commit 96328a5e25
3 changed files with 22 additions and 11 deletions

View file

@ -189,6 +189,11 @@ std::shared_ptr<Channel> TwitchServer::getCustomChannel(
static auto channel =
std::make_shared<Channel>("$$$", 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(

View file

@ -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<milliseconds>(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
{
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;
}

View file

@ -159,7 +159,8 @@ private:
QTimer pauseTimer_;
std::unordered_map<PauseReason, boost::optional<SteadyClock::time_point>>
pauses_;
boost::optional<SteadyClock::time_point> pauseEnd;
boost::optional<SteadyClock::time_point> pauseEnd_;
int pauseScrollOffset_ = 0;
boost::optional<MessageElementFlags> overrideFlags_;
MessageLayoutPtr lastReadMessage_;