You've already forked matrix-js-sdk
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:
@@ -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
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user