Prefer RoomStateEvent.Update where possible as it fires far less (#7878)
This commit is contained in:
parent
36ae0ea49d
commit
c257bc3f7a
40 changed files with 223 additions and 190 deletions
|
@ -18,6 +18,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|||
import { User, UserEvent } from "matrix-js-sdk/src/models/user";
|
||||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||
import { throttle } from "lodash";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
|
||||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
|
||||
|
@ -102,9 +103,7 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
|||
this.monitoredUser.removeListener(UserEvent.DisplayName, this.onProfileUpdate);
|
||||
this.monitoredUser.removeListener(UserEvent.AvatarUrl, this.onProfileUpdate);
|
||||
}
|
||||
if (this.matrixClient) {
|
||||
this.matrixClient.removeListener(RoomStateEvent.Events, this.onStateEvents);
|
||||
}
|
||||
this.matrixClient?.removeListener(RoomStateEvent.Events, this.onStateEvents);
|
||||
await this.reset({});
|
||||
}
|
||||
|
||||
|
@ -127,7 +126,7 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
|||
// we don't actually do anything here
|
||||
}
|
||||
|
||||
private onProfileUpdate = async () => {
|
||||
private onProfileUpdate = throttle(async () => {
|
||||
// We specifically do not use the User object we stored for profile info as it
|
||||
// could easily be wrong (such as per-room instead of global profile).
|
||||
const profileInfo = await this.matrixClient.getProfileInfo(this.matrixClient.getUserId());
|
||||
|
@ -147,12 +146,12 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
|||
avatarUrl: profileInfo.avatar_url,
|
||||
fetchedAt: Date.now(),
|
||||
});
|
||||
};
|
||||
}, 200, { trailing: true, leading: true });
|
||||
|
||||
private onStateEvents = throttle(async (ev: MatrixEvent) => {
|
||||
private onStateEvents = async (ev: MatrixEvent) => {
|
||||
const myUserId = MatrixClientPeg.get().getUserId();
|
||||
if (ev.getType() === 'm.room.member' && ev.getSender() === myUserId && ev.getStateKey() === myUserId) {
|
||||
if (ev.getType() === EventType.RoomMember && ev.getSender() === myUserId && ev.getStateKey() === myUserId) {
|
||||
await this.onProfileUpdate();
|
||||
}
|
||||
}, 200, { trailing: true, leading: true });
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue