You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-05 00:42:10 +03:00
Fix incorrect prevEv being sent in ClientEvent.AccountData events (#2794)
This commit is contained in:
committed by
GitHub
parent
ade2e81d3d
commit
9bdeea0a8d
@@ -1602,6 +1602,46 @@ describe("MatrixClient syncing", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("user account data", () => {
|
||||
it("should include correct prevEv in the ClientEvent.AccountData emit", async () => {
|
||||
const eventA1 = new MatrixEvent({ type: "a", content: { body: "1" } });
|
||||
const eventA2 = new MatrixEvent({ type: "a", content: { body: "2" } });
|
||||
const eventB1 = new MatrixEvent({ type: "b", content: { body: "1" } });
|
||||
const eventB2 = new MatrixEvent({ type: "b", content: { body: "2" } });
|
||||
|
||||
client!.store.storeAccountDataEvents([eventA1, eventB1]);
|
||||
const fn = jest.fn();
|
||||
client!.on(ClientEvent.AccountData, fn);
|
||||
|
||||
httpBackend!.when("GET", "/sync").respond(200, {
|
||||
next_batch: "batch_token",
|
||||
rooms: {},
|
||||
presence: {},
|
||||
account_data: {
|
||||
events: [eventA2.event, eventB2.event],
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
client!.startClient(),
|
||||
httpBackend!.flushAllExpected(),
|
||||
]);
|
||||
|
||||
const eventA = client?.getAccountData("a");
|
||||
expect(eventA).not.toBe(eventA1);
|
||||
const eventB = client?.getAccountData("b");
|
||||
expect(eventB).not.toBe(eventB1);
|
||||
|
||||
expect(fn).toHaveBeenCalledWith(eventA, eventA1);
|
||||
expect(fn).toHaveBeenCalledWith(eventB, eventB1);
|
||||
|
||||
expect(eventA?.getContent().body).toBe("2");
|
||||
expect(eventB?.getContent().body).toBe("2");
|
||||
|
||||
client!.off(ClientEvent.AccountData, fn);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* waits for the MatrixClient to emit one or more 'sync' events.
|
||||
*
|
||||
|
@@ -208,7 +208,7 @@ class ExtensionAccountData implements Extension {
|
||||
private processGlobalAccountData(globalAccountData: object[]): void {
|
||||
const events = mapEvents(this.client, undefined, globalAccountData);
|
||||
const prevEventsMap = events.reduce((m, c) => {
|
||||
m[c.getId()] = this.client.store.getAccountData(c.getType());
|
||||
m[c.getType()] = this.client.store.getAccountData(c.getType());
|
||||
return m;
|
||||
}, {});
|
||||
this.client.store.storeAccountDataEvents(events);
|
||||
@@ -222,7 +222,7 @@ class ExtensionAccountData implements Extension {
|
||||
const rules = accountDataEvent.getContent<IPushRules>();
|
||||
this.client.pushRules = PushProcessor.rewriteDefaultRules(rules);
|
||||
}
|
||||
const prevEvent = prevEventsMap[accountDataEvent.getId()];
|
||||
const prevEvent = prevEventsMap[accountDataEvent.getType()];
|
||||
this.client.emit(ClientEvent.AccountData, accountDataEvent, prevEvent);
|
||||
return accountDataEvent;
|
||||
},
|
||||
|
@@ -1097,7 +1097,7 @@ export class SyncApi {
|
||||
if (Array.isArray(data.account_data?.events)) {
|
||||
const events = data.account_data.events.map(client.getEventMapper());
|
||||
const prevEventsMap = events.reduce((m, c) => {
|
||||
m[c.getId()] = client.store.getAccountData(c.getType());
|
||||
m[c.getType()] = client.store.getAccountData(c.getType());
|
||||
return m;
|
||||
}, {});
|
||||
client.store.storeAccountDataEvents(events);
|
||||
@@ -1111,7 +1111,7 @@ export class SyncApi {
|
||||
const rules = accountDataEvent.getContent<IPushRules>();
|
||||
client.pushRules = PushProcessor.rewriteDefaultRules(rules);
|
||||
}
|
||||
const prevEvent = prevEventsMap[accountDataEvent.getId()];
|
||||
const prevEvent = prevEventsMap[accountDataEvent.getType()];
|
||||
client.emit(ClientEvent.AccountData, accountDataEvent, prevEvent);
|
||||
return accountDataEvent;
|
||||
},
|
||||
|
Reference in New Issue
Block a user