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 = static auto channel =
std::make_shared<Channel>("$$$", chatterino::Channel::Type::Misc); std::make_shared<Channel>("$$$", chatterino::Channel::Type::Misc);
static auto timer = [&] { static auto timer = [&] {
for (auto i = 0; i < 1000; i++)
{
channel->addMessage(makeSystemMessage(QString::number(i + 1)));
}
auto timer = new QTimer; auto timer = new QTimer;
QObject::connect(timer, &QTimer::timeout, [] { QObject::connect(timer, &QTimer::timeout, [] {
channel->addMessage( channel->addMessage(

View file

@ -246,16 +246,19 @@ void ChannelView::updatePauseTimer()
if (this->pauses_.empty()) if (this->pauses_.empty())
{ {
/// No pauses so we can stop the timer /// No pauses so we can stop the timer
this->pauseEnd = boost::none; this->pauseEnd_ = boost::none;
this->pauseTimer_.stop(); this->pauseTimer_.stop();
this->scrollBar_->offset(this->pauseScrollOffset_);
this->pauseScrollOffset_ = 0;
this->queueLayout(); this->queueLayout();
} }
else if (std::any_of(this->pauses_.begin(), this->pauses_.end(), else if (std::any_of(this->pauses_.begin(), this->pauses_.end(),
[](auto &&value) { return !value.second; })) [](auto &&value) { return !value.second; }))
{ {
/// Some of the pauses are infinite /// Some of the pauses are infinite
this->pauseEnd = boost::none; this->pauseEnd_ = boost::none;
this->pauseTimer_.stop(); this->pauseTimer_.stop();
} }
else else
@ -266,10 +269,10 @@ void ChannelView::updatePauseTimer()
[](auto &&a, auto &&b) { return a.second > b.second; }) [](auto &&a, auto &&b) { return a.second > b.second; })
->second.get(); ->second.get();
if (max != this->pauseEnd) if (max != this->pauseEnd_)
{ {
/// Start the timer /// Start the timer
this->pauseEnd = max; this->pauseEnd_ = max;
this->pauseTimer_.start( this->pauseTimer_.start(
duration_cast<milliseconds>(max - SteadyClock::now())); duration_cast<milliseconds>(max - SteadyClock::now()));
} }
@ -605,16 +608,18 @@ void ChannelView::messageAppended(MessagePtr &message,
if (this->messages_.pushBack(MessageLayoutPtr(messageRef), deleted)) if (this->messages_.pushBack(MessageLayoutPtr(messageRef), deleted))
{ {
// if (!this->isPaused()) { if (this->paused())
if (this->scrollBar_->isAtBottom())
{ {
this->scrollBar_->scrollToBottom(); if (!this->scrollBar_->isAtBottom())
this->pauseScrollOffset_--;
} }
else else
{ {
if (this->scrollBar_->isAtBottom())
this->scrollBar_->scrollToBottom();
else
this->scrollBar_->offset(-1); this->scrollBar_->offset(-1);
} }
// }
} }
if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) if (!messageFlags->has(MessageFlag::DoNotTriggerNotification))
@ -692,7 +697,7 @@ void ChannelView::messageRemoveFromStart(MessagePtr &message)
void ChannelView::messageReplaced(size_t index, MessagePtr &replacement) void ChannelView::messageReplaced(size_t index, MessagePtr &replacement)
{ {
if (index >= this->messages_.getSnapshot().size() || index < 0) if (index >= this->messages_.getSnapshot().size())
{ {
return; return;
} }

View file

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