Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export types for MatrixEvent and Room emitted events, and make event handler map types stricter #2750

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export enum MatrixEventEvent {
RelationsCreated = "Event.relationsCreated",
}

type EmittedEvents = MatrixEventEvent | ThreadEvent.Update;
export type MatrixEventEmittedEvents = MatrixEventEvent | ThreadEvent.Update;

export type MatrixEventHandlerMap = {
[MatrixEventEvent.Decrypted]: (event: MatrixEvent, err?: Error) => void;
Expand All @@ -198,9 +198,9 @@ export type MatrixEventHandlerMap = {
[MatrixEventEvent.Status]: (event: MatrixEvent, status: EventStatus | null) => void;
[MatrixEventEvent.Replaced]: (event: MatrixEvent) => void;
[MatrixEventEvent.RelationsCreated]: (relationType: string, eventType: string) => void;
} & ThreadEventHandlerMap;
} & Pick<ThreadEventHandlerMap, ThreadEvent.Update>;

export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHandlerMap> {
export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap> {
private pushActions: IActionsObject | null = null;
private _replacingEvent: MatrixEvent | null = null;
private _localRedactionEvent: MatrixEvent | null = null;
Expand Down Expand Up @@ -283,7 +283,7 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
*/
public verificationRequest?: VerificationRequest;

private readonly reEmitter: TypedReEmitter<EmittedEvents, MatrixEventHandlerMap>;
private readonly reEmitter: TypedReEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap>;

/**
* Construct a Matrix Event object
Expand Down
21 changes: 15 additions & 6 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ limitations under the License.
* @module models/room
*/

import { EventTimelineSet, DuplicateStrategy, IAddLiveEventOptions } from "./event-timeline-set";
import {
EventTimelineSet,
DuplicateStrategy,
IAddLiveEventOptions,
EventTimelineSetHandlerMap,
} from "./event-timeline-set";
import { Direction, EventTimeline } from "./event-timeline";
import { getHttpUriForMxc } from "../content-repo";
import * as utils from "../utils";
Expand Down Expand Up @@ -130,7 +135,7 @@ export enum RoomEvent {
UnreadNotifications = "Room.UnreadNotifications",
}

type EmittedEvents = RoomEvent
export type RoomEmittedEvents = RoomEvent
| RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NewMember
Expand Down Expand Up @@ -171,8 +176,12 @@ export type RoomEventHandlerMap = {
) => void;
[RoomEvent.TimelineRefresh]: (room: Room, eventTimelineSet: EventTimelineSet) => void;
[ThreadEvent.New]: (thread: Thread, toStartOfTimeline: boolean) => void;
} & ThreadHandlerMap
& MatrixEventHandlerMap
} & Pick<
ThreadHandlerMap,
ThreadEvent.Update | ThreadEvent.NewReply
>
& EventTimelineSetHandlerMap
& Pick<MatrixEventHandlerMap, MatrixEventEvent.BeforeRedaction>
& Pick<
RoomStateEventHandlerMap,
RoomStateEvent.Events
Expand All @@ -187,8 +196,8 @@ export type RoomEventHandlerMap = {
BeaconEvent.Update | BeaconEvent.Destroy | BeaconEvent.LivenessChange
>;

export class Room extends ReadReceipt<EmittedEvents, RoomEventHandlerMap> {
public readonly reEmitter: TypedReEmitter<EmittedEvents, RoomEventHandlerMap>;
export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
public readonly reEmitter: TypedReEmitter<RoomEmittedEvents, RoomEventHandlerMap>;
private txnToEvent: Record<string, MatrixEvent> = {}; // Pending in-flight requests { string: MatrixEvent }
private notificationCounts: NotificationCount = {};
private readonly threadNotifications = new Map<string, NotificationCount>();
Expand Down