Improve typing around event emitter handlers (#7816)
This commit is contained in:
parent
213b32bf14
commit
7fa01ffb06
79 changed files with 548 additions and 471 deletions
|
@ -16,16 +16,17 @@ limitations under the License.
|
|||
|
||||
import React, { createRef, ReactNode, SyntheticEvent } from 'react';
|
||||
import ReactDOM from "react-dom";
|
||||
import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { EventTimelineSet, IRoomTimelineData } from "matrix-js-sdk/src/models/event-timeline-set";
|
||||
import { Direction, EventTimeline } from "matrix-js-sdk/src/models/event-timeline";
|
||||
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
|
||||
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
|
||||
import { SyncState } from 'matrix-js-sdk/src/sync';
|
||||
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
|
||||
import { RoomMember, RoomMemberEvent } from 'matrix-js-sdk/src/models/room-member';
|
||||
import { debounce } from 'lodash';
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ClientEvent } from "matrix-js-sdk/src/client";
|
||||
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
import { Layout } from "../../settings/enums/Layout";
|
||||
|
@ -276,22 +277,22 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
|
||||
this.dispatcherRef = dis.register(this.onAction);
|
||||
const cli = MatrixClientPeg.get();
|
||||
cli.on("Room.timeline", this.onRoomTimeline);
|
||||
cli.on("Room.timelineReset", this.onRoomTimelineReset);
|
||||
cli.on("Room.redaction", this.onRoomRedaction);
|
||||
cli.on(RoomEvent.Timeline, this.onRoomTimeline);
|
||||
cli.on(RoomEvent.TimelineReset, this.onRoomTimelineReset);
|
||||
cli.on(RoomEvent.Redaction, this.onRoomRedaction);
|
||||
if (SettingsStore.getValue("feature_msc3531_hide_messages_pending_moderation")) {
|
||||
// Make sure that events are re-rendered when their visibility-pending-moderation changes.
|
||||
cli.on("Event.visibilityChange", this.onEventVisibilityChange);
|
||||
cli.on("RoomMember.powerLevel", this.onVisibilityPowerLevelChange);
|
||||
cli.on(MatrixEventEvent.VisibilityChange, this.onEventVisibilityChange);
|
||||
cli.on(RoomMemberEvent.PowerLevel, this.onVisibilityPowerLevelChange);
|
||||
}
|
||||
// same event handler as Room.redaction as for both we just do forceUpdate
|
||||
cli.on("Room.redactionCancelled", this.onRoomRedaction);
|
||||
cli.on("Room.receipt", this.onRoomReceipt);
|
||||
cli.on("Room.localEchoUpdated", this.onLocalEchoUpdated);
|
||||
cli.on("Room.accountData", this.onAccountData);
|
||||
cli.on("Event.decrypted", this.onEventDecrypted);
|
||||
cli.on("Event.replaced", this.onEventReplaced);
|
||||
cli.on("sync", this.onSync);
|
||||
cli.on(RoomEvent.RedactionCancelled, this.onRoomRedaction);
|
||||
cli.on(RoomEvent.Receipt, this.onRoomReceipt);
|
||||
cli.on(RoomEvent.LocalEchoUpdated, this.onLocalEchoUpdated);
|
||||
cli.on(RoomEvent.AccountData, this.onAccountData);
|
||||
cli.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
cli.on(MatrixEventEvent.Replaced, this.onEventReplaced);
|
||||
cli.on(ClientEvent.Sync, this.onSync);
|
||||
}
|
||||
|
||||
// TODO: [REACT-WARNING] Move into constructor
|
||||
|
@ -353,18 +354,18 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
|
||||
const client = MatrixClientPeg.get();
|
||||
if (client) {
|
||||
client.removeListener("Room.timeline", this.onRoomTimeline);
|
||||
client.removeListener("Room.timelineReset", this.onRoomTimelineReset);
|
||||
client.removeListener("Room.redaction", this.onRoomRedaction);
|
||||
client.removeListener("Room.redactionCancelled", this.onRoomRedaction);
|
||||
client.removeListener("Room.receipt", this.onRoomReceipt);
|
||||
client.removeListener("Room.localEchoUpdated", this.onLocalEchoUpdated);
|
||||
client.removeListener("Room.accountData", this.onAccountData);
|
||||
client.removeListener("RoomMember.powerLevel", this.onVisibilityPowerLevelChange);
|
||||
client.removeListener("Event.decrypted", this.onEventDecrypted);
|
||||
client.removeListener("Event.replaced", this.onEventReplaced);
|
||||
client.removeListener("Event.visibilityChange", this.onEventVisibilityChange);
|
||||
client.removeListener("sync", this.onSync);
|
||||
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
|
||||
client.removeListener(RoomEvent.TimelineReset, this.onRoomTimelineReset);
|
||||
client.removeListener(RoomEvent.Redaction, this.onRoomRedaction);
|
||||
client.removeListener(RoomEvent.RedactionCancelled, this.onRoomRedaction);
|
||||
client.removeListener(RoomEvent.Receipt, this.onRoomReceipt);
|
||||
client.removeListener(RoomEvent.LocalEchoUpdated, this.onLocalEchoUpdated);
|
||||
client.removeListener(RoomEvent.AccountData, this.onAccountData);
|
||||
client.removeListener(RoomMemberEvent.PowerLevel, this.onVisibilityPowerLevelChange);
|
||||
client.removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
client.removeListener(MatrixEventEvent.Replaced, this.onEventReplaced);
|
||||
client.removeListener(MatrixEventEvent.VisibilityChange, this.onEventVisibilityChange);
|
||||
client.removeListener(ClientEvent.Sync, this.onSync);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,11 +674,11 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
this.forceUpdate();
|
||||
};
|
||||
|
||||
private onEventReplaced = (replacedEvent: MatrixEvent, room: Room): void => {
|
||||
private onEventReplaced = (replacedEvent: MatrixEvent): void => {
|
||||
if (this.unmounted) return;
|
||||
|
||||
// ignore events for other rooms
|
||||
if (room !== this.props.timelineSet.room) return;
|
||||
if (replacedEvent.getRoomId() !== this.props.timelineSet.room.roomId) return;
|
||||
|
||||
// we could skip an update if the event isn't in our timeline,
|
||||
// but that's probably an early optimisation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue