Skip to content

Commit

Permalink
Update types for Event and Room emitted events
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-demydiuk committed Oct 13, 2022
1 parent cc025ea commit d2af0b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
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) => 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;
private _replacingEvent: MatrixEvent = null;
private _localRedactionEvent: MatrixEvent = null;
Expand Down Expand Up @@ -283,7 +283,7 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
*/
public verificationRequest: VerificationRequest = null;

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 @@ -129,7 +134,7 @@ export enum RoomEvent {
HistoryImportedWithinTimeline = "Room.historyImportedWithinTimeline",
}

type EmittedEvents = RoomEvent
export type RoomEmittedEvents = RoomEvent
| RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NewMember
Expand Down Expand Up @@ -166,8 +171,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 @@ -182,8 +191,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 threadNotifications: Map<string, NotificationCount> = new Map();
Expand Down

0 comments on commit d2af0b8

Please sign in to comment.