+void ChatWidget::viewportChanged(int newPos) {
+ const int REQUEST_COUNT = 50;
+ QAbstractSlider *vbar = verticalScrollBar();
+ if(!vbar)
+ return;
+
+ int relativePos = 100;
+ if(vbar->maximum() - vbar->minimum() != 0)
+ relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum());
+
+ if(relativePos < 20) {
+ Buffer *buffer = Client::buffer(bufferId);
+ Q_CHECK_PTR(buffer);
+ if(buffer->contents().isEmpty())
+ return;
+ MsgId msgId = buffer->contents().first()->msgId();
+ if(!lastBacklogOffset.isValid() || msgId < lastBacklogOffset && lastBacklogSize + REQUEST_COUNT <= buffer->contents().count()) {
+ Client::backlogManager()->requestBacklog(bufferId, REQUEST_COUNT, msgId.toInt());
+ lastBacklogOffset = msgId;
+ lastBacklogSize = buffer->contents().size();
+ }
+ }
+}