You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
fix room not having access to event mapper + tests
This commit is contained in:
@@ -1274,6 +1274,35 @@ describe("Room", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("loadOutOfBandMembers", function() {
|
describe("loadOutOfBandMembers", function() {
|
||||||
|
const memberEvent = utils.mkMembership({
|
||||||
|
user: "@user_a:bar", mship: "join",
|
||||||
|
room: roomId, event: true, name: "User A",
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should apply member events", async function() {
|
||||||
|
const room = new Room(roomId);
|
||||||
|
await room.loadOutOfBandMembers(Promise.resolve([memberEvent]));
|
||||||
|
const memberA = room.getMember("@user_a:bar");
|
||||||
|
expect(memberA.name).toEqual("User A");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should apply first call, not first resolved promise", async function() {
|
||||||
|
const memberEvent2 = utils.mkMembership({
|
||||||
|
user: "@user_a:bar", mship: "join",
|
||||||
|
room: roomId, event: true, name: "Ms A",
|
||||||
|
});
|
||||||
|
const room = new Room(roomId);
|
||||||
|
|
||||||
|
const promise2 = Promise.resolve([memberEvent2])
|
||||||
|
const promise1 = promise2.then(() => [memberEvent]);
|
||||||
|
|
||||||
|
await room.loadOutOfBandMembers(promise1);
|
||||||
|
await room.loadOutOfBandMembers(promise2);
|
||||||
|
|
||||||
|
const memberA = room.getMember("@user_a:bar");
|
||||||
|
expect(memberA.name).toEqual("User A");
|
||||||
|
});
|
||||||
|
|
||||||
it("should revert needs loading on error", async function() {
|
it("should revert needs loading on error", async function() {
|
||||||
const room = new Room(roomId);
|
const room = new Room(roomId);
|
||||||
let hasThrown = false;
|
let hasThrown = false;
|
||||||
|
|||||||
@@ -770,7 +770,9 @@ MatrixClient.prototype.loadRoomMembersIfNeeded = async function(roomId) {
|
|||||||
|
|
||||||
const lastEventId = room.getLastEventId();
|
const lastEventId = room.getLastEventId();
|
||||||
const responsePromise = this.members(roomId, "join", "leave", lastEventId);
|
const responsePromise = this.members(roomId, "join", "leave", lastEventId);
|
||||||
const eventsPromise = responsePromise.then((response) => response.chunk);
|
const eventsPromise = responsePromise.then((response) => {
|
||||||
|
return response.chunk.map(this.getEventMapper())
|
||||||
|
});
|
||||||
await room.loadOutOfBandMembers(eventsPromise);
|
await room.loadOutOfBandMembers(eventsPromise);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -232,21 +232,20 @@ Room.prototype.needsOutOfBandMembers = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the out-of-band members from the promise passed in
|
* Loads the out-of-band members from the promise passed in
|
||||||
* @param {Promise} eventsPromise promise with array with state events
|
* @param {Promise<[MatrixEvent]>} eventsPromise state events for members
|
||||||
*/
|
*/
|
||||||
Room.prototype.loadOutOfBandMembers = async function(eventsPromise) {
|
Room.prototype.loadOutOfBandMembers = async function(eventsPromise) {
|
||||||
if (!this.membersNeedLoading()) {
|
if (!this.needsOutOfBandMembers()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.currentState.markOutOfBandMembersStarted();
|
this.currentState.markOutOfBandMembersStarted();
|
||||||
let eventPojos = null;
|
let events = null;
|
||||||
try {
|
try {
|
||||||
eventPojos = await eventsPromise;
|
events = await eventsPromise;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.currentState.markOutOfBandMembersFailed();
|
this.currentState.markOutOfBandMembersFailed();
|
||||||
throw err; //rethrow so calling code is aware operation failed
|
throw err; //rethrow so calling code is aware operation failed
|
||||||
}
|
}
|
||||||
const events = eventPojos.map(this.client.getEventMapper());
|
|
||||||
this.currentState.setOutOfBandMembers(events);
|
this.currentState.setOutOfBandMembers(events);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user