Prefer RoomStateEvent.Update where possible as it fires far less (#7878)

This commit is contained in:
Michael Telatynski 2022-02-24 14:39:25 +00:00 committed by GitHub
parent 36ae0ea49d
commit c257bc3f7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 223 additions and 190 deletions

View file

@ -20,13 +20,14 @@ limitations under the License.
import React, { useCallback, useContext, useEffect, useState } from 'react';
import classNames from 'classnames';
import { ResizeMethod } from 'matrix-js-sdk/src/@types/partials';
import { ClientEvent } from "matrix-js-sdk/src/client";
import * as AvatarLogic from '../../../Avatar';
import SettingsStore from "../../../settings/SettingsStore";
import AccessibleButton from '../elements/AccessibleButton';
import RoomContext from "../../../contexts/RoomContext";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { useEventEmitter } from "../../../hooks/useEventEmitter";
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
import { toPx } from "../../../utils/units";
import { _t } from '../../../languageHandler';
@ -92,7 +93,7 @@ const useImageUrl = ({ url, urls }): [string, () => void] => {
setIndex(0);
}
}, []);
useEventEmitter(cli, "sync", onClientSync);
useTypedEventEmitter(cli, ClientEvent.Sync, onClientSync);
const imageUrl = imageUrls[urlsIndex];
return [imageUrl, onError];

View file

@ -20,6 +20,7 @@ import { ResizeMethod } from 'matrix-js-sdk/src/@types/partials';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import classNames from "classnames";
import { EventType } from "matrix-js-sdk/src/@types/event";
import BaseAvatar from './BaseAvatar';
import ImageView from '../elements/ImageView';
@ -86,10 +87,7 @@ export default class RoomAvatar extends React.Component<IProps, IState> {
}
private onRoomStateEvents = (ev: MatrixEvent) => {
if (!this.props.room ||
ev.getRoomId() !== this.props.room.roomId ||
ev.getType() !== 'm.room.avatar'
) return;
if (ev.getRoomId() !== this.props.room?.roomId || ev.getType() !== EventType.RoomAvatar) return;
this.setState({
urls: RoomAvatar.getImageUrls(this.props),