+
+void ChatScene::setIsFetchingBacklog(bool fetch) {
+ if(!isBacklogFetchingEnabled()) return;
+
+ if(!fetch) {
+ _fetchingBacklog = false;
+ } else {
+ _fetchingBacklog = true;
+ requestBacklogIfNeeded();
+ }
+}
+
+void ChatScene::requestBacklogIfNeeded() {
+ const int REQUEST_COUNT = 50;
+
+ if(!isBacklogFetchingEnabled() || !isFetchingBacklog() || !model()->rowCount()) return;
+
+ MsgId msgId = model()->data(model()->index(0, 0), ChatLineModel::MsgIdRole).value<MsgId>();
+ if(!_lastBacklogOffset.isValid() || (msgId < _lastBacklogOffset && _lastBacklogSize + REQUEST_COUNT <= model()->rowCount())) {
+ Client::backlogManager()->requestBacklog(bufferForBacklogFetching(), REQUEST_COUNT, msgId.toInt());
+ _lastBacklogOffset = msgId;
+ _lastBacklogSize = model()->rowCount();
+ }
+}