Skip to content

Commit

Permalink
Connection: support members lazy-loading
Browse files Browse the repository at this point in the history
This should cover the Connection-related part of #253.

Connection gained lazyLoading/setLazyLoading accessors and the respective Q_PROPERTY.
When lazy loading is on, sync() adds lazy_load_members: true to its filter.
  • Loading branch information
KitsuneRal committed Dec 8, 2018
1 parent 1135c04 commit a4d6a37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Connection::Private
bool cacheState = true;
bool cacheToBinary = SettingsGroup("libqmatrixclient")
.value("cache_type").toString() != "json";
bool lazyLoading;

void connectWithToken(const QString& user, const QString& accessToken,
const QString& deviceId);
Expand Down Expand Up @@ -287,11 +288,11 @@ void Connection::sync(int timeout)
if (d->syncJob)
return;

// Raw string: http://en.cppreference.com/w/cpp/language/string_literal
const auto filter =
QStringLiteral(R"({"room": { "timeline": { "limit": 100 } } })");
Filter filter;
filter.room->timeline->limit = 100;
filter.room->state->lazyLoadMembers = d->lazyLoading;
auto job = d->syncJob = callApi<SyncJob>(BackgroundRequest,
d->data->lastEvent(), filter, timeout);
d->data->lastEvent(), filter, timeout);
connect( job, &SyncJob::success, this, [this, job] {
onSyncSuccess(job->takeData());
d->syncJob = nullptr;
Expand Down Expand Up @@ -1181,6 +1182,20 @@ void Connection::setCacheState(bool newValue)
}
}

bool QMatrixClient::Connection::lazyLoading() const
{
return d->lazyLoading;
}

void QMatrixClient::Connection::setLazyLoading(bool newValue)
{
if (d->lazyLoading != newValue)
{
d->lazyLoading = newValue;
emit lazyLoadingChanged();
}
}

void Connection::getTurnServers()
{
auto job = callApi<GetTurnServerJob>();
Expand Down
6 changes: 6 additions & 0 deletions lib/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ namespace QMatrixClient
Q_PROPERTY(QByteArray accessToken READ accessToken NOTIFY stateChanged)
Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver NOTIFY homeserverChanged)
Q_PROPERTY(bool cacheState READ cacheState WRITE setCacheState NOTIFY cacheStateChanged)
Q_PROPERTY(bool lazyLoading READ lazyLoading WRITE setLazyLoading NOTIFY lazyLoadingChanged)

public:
// Room ids, rather than room pointers, are used in the direct chat
// map types because the library keeps Invite rooms separate from
Expand Down Expand Up @@ -308,6 +310,9 @@ namespace QMatrixClient
bool cacheState() const;
void setCacheState(bool newValue);

bool lazyLoading() const;
void setLazyLoading(bool newValue);

/** Start a job of a specified type with specified arguments and policy
*
* This is a universal method to start a job of a type passed
Expand Down Expand Up @@ -655,6 +660,7 @@ namespace QMatrixClient
IgnoredUsersList removals);

void cacheStateChanged();
void lazyLoadingChanged();
void turnServersChanged(const QJsonObject& servers);

protected:
Expand Down

0 comments on commit a4d6a37

Please sign in to comment.