1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

prototype support for lazily loading members in matrixclient

This commit is contained in:
Bruno Windels
2018-07-10 17:17:27 +02:00
parent 2b5925b893
commit 2c5cad71ee
3 changed files with 44 additions and 0 deletions

View File

@@ -417,6 +417,18 @@ MatrixBaseApis.prototype.roomState = function(roomId, callback) {
return this._http.authedRequest(callback, "GET", path); return this._http.authedRequest(callback, "GET", path);
}; };
/**
* @param {string} roomId
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixBaseApis.prototype.joinedMembers = function(roomId, callback) {
const path = utils.encodeUri("/rooms/$roomId/joined_members", {$roomId: roomId});
return this._http.authedRequest(callback, "GET", path);
};
/** /**
* @param {string} groupId * @param {string} groupId
* @return {module:client.Promise} Resolves: Group summary object * @return {module:client.Promise} Resolves: Group summary object

View File

@@ -757,6 +757,20 @@ MatrixClient.prototype.getRoom = function(roomId) {
return this.store.getRoom(roomId); return this.store.getRoom(roomId);
}; };
/**
* Preloads the member list for the given room id,
* in case lazy loading of memberships is in use.
* @param {string} roomId The room ID
*/
MatrixClient.prototype.loadRoomMembersIfNeeded = function(roomId) {
const room = this.getRoom(roomId);
if (!room || !room.membersNeedLoading()) {
return;
}
const membersPromise = this.joinedMembers(roomId);
room.setLazilyLoadedMembers(membersPromise);
}
/** /**
* Retrieve all known rooms. * Retrieve all known rooms.
* @return {Room[]} A list of rooms, or an empty list if there is no data store. * @return {Room[]} A list of rooms, or an empty list if there is no data store.

View File

@@ -171,7 +171,10 @@ function Room(roomId, opts) {
// read by megolm; boolean value - null indicates "use global value" // read by megolm; boolean value - null indicates "use global value"
this._blacklistUnverifiedDevices = null; this._blacklistUnverifiedDevices = null;
// in case of lazy loading, to keep track of loading state
this._membersNeedLoading = true;
} }
utils.inherits(Room, EventEmitter); utils.inherits(Room, EventEmitter);
/** /**
@@ -212,7 +215,22 @@ Room.prototype.getPendingEvents = function() {
Room.prototype.getLiveTimeline = function() { Room.prototype.getLiveTimeline = function() {
return this.getUnfilteredTimelineSet().getLiveTimeline(); return this.getUnfilteredTimelineSet().getLiveTimeline();
}; };
/**
* Get the lazy loading state, whether loading is needed or not.
*/
Room.prototype.membersNeedLoading = function() {
return this._membersNeedLoading;
}
/**
*
*/
Room.prototype.setLazilyLoadedMembers = async function(joinedMembersPromise) {
this._membersNeedLoading = false;
const members = await joinedMembersPromise;
this.currentState.setJoinedMembers(members.joined);
//for all timelines > room state, call setJoinedMembers?
}
/** /**
* Reset the live timeline of all timelineSets, and start new ones. * Reset the live timeline of all timelineSets, and start new ones.