mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 09:30:47 +03:00
Lazy load initial timeline events
This commit is contained in:
parent
36d25951dc
commit
26dfbfd08c
4 changed files with 14 additions and 10 deletions
|
@ -44,7 +44,7 @@ public:
|
|||
void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl);
|
||||
void fetchOwnAvatar(const QUrl &avatar_url);
|
||||
void downloadImage(const QString &event_id, const QUrl &url);
|
||||
void messages(const QString &room_id, const QString &from_token) noexcept;
|
||||
void messages(const QString &room_id, const QString &from_token, int limit = 20) noexcept;
|
||||
|
||||
inline QUrl getHomeServer();
|
||||
inline int transactionId();
|
||||
|
|
|
@ -541,7 +541,7 @@ void MatrixClient::initialSync() noexcept
|
|||
};
|
||||
|
||||
QJsonObject filter{{"room",
|
||||
QJsonObject{{"timeline", QJsonObject{{"limit", 70}}},
|
||||
QJsonObject{{"timeline", QJsonObject{{"limit", 20}}},
|
||||
{"ephemeral", QJsonObject{{"limit", 0}}}}},
|
||||
{"presence", QJsonObject{{"not_types", excluded_presence}}}};
|
||||
|
||||
|
@ -677,12 +677,13 @@ void MatrixClient::fetchOwnAvatar(const QUrl &avatar_url)
|
|||
reply->setProperty("endpoint", static_cast<int>(Endpoint::GetOwnAvatar));
|
||||
}
|
||||
|
||||
void MatrixClient::messages(const QString &room_id, const QString &from_token) noexcept
|
||||
void MatrixClient::messages(const QString &room_id, const QString &from_token, int limit) noexcept
|
||||
{
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("access_token", token_);
|
||||
query.addQueryItem("from", from_token);
|
||||
query.addQueryItem("dir", "b");
|
||||
query.addQueryItem("limit", QString::number(limit));
|
||||
|
||||
QUrl endpoint(server_);
|
||||
endpoint.setPath(api_url_ + QString("/rooms/%1/messages").arg(room_id));
|
||||
|
|
|
@ -76,7 +76,7 @@ void TimelineView::scrollDown()
|
|||
|
||||
// The first time we enter the room move the scroll bar to the bottom.
|
||||
if (!isInitialized) {
|
||||
scroll_area_->ensureVisible(0, scroll_widget_->size().height(), 0, 0);
|
||||
scroll_area_->verticalScrollBar()->setValue(max);
|
||||
isInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
@ -226,11 +226,6 @@ int TimelineView::addEvents(const Timeline &timeline)
|
|||
QSettings settings;
|
||||
QString localUser = settings.value("auth/user_id").toString();
|
||||
|
||||
if (isInitialSync) {
|
||||
prev_batch_token_ = timeline.previousBatch();
|
||||
isInitialSync = false;
|
||||
}
|
||||
|
||||
for (const auto &event : timeline.events()) {
|
||||
TimelineItem *item = parseMessageEvent(event.toObject(), TimelineDirection::Bottom);
|
||||
auto sender = event.toObject().value("sender").toString();
|
||||
|
@ -243,6 +238,13 @@ int TimelineView::addEvents(const Timeline &timeline)
|
|||
}
|
||||
}
|
||||
|
||||
if (isInitialSync) {
|
||||
prev_batch_token_ = timeline.previousBatch();
|
||||
isInitialSync = false;
|
||||
|
||||
client_->messages(room_id_, prev_batch_token_);
|
||||
}
|
||||
|
||||
return message_count;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,9 +119,10 @@ void TimelineViewManager::setHistoryView(const QString &room_id)
|
|||
|
||||
active_room_ = room_id;
|
||||
auto widget = views_.value(room_id);
|
||||
widget->scrollDown();
|
||||
|
||||
setCurrentWidget(widget.data());
|
||||
|
||||
widget->scrollDown();
|
||||
}
|
||||
|
||||
QMap<QString, QString> TimelineViewManager::NICK_COLORS;
|
||||
|
|
Loading…
Reference in a new issue