Skip to content

Commit 81afd6f

Browse files
committed
Update types for Event and Room emitted events
1 parent 12a4d2a commit 81afd6f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/models/event.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export enum MatrixEventEvent {
188188
RelationsCreated = "Event.relationsCreated",
189189
}
190190

191-
type EmittedEvents = MatrixEventEvent | ThreadEvent.Update;
191+
export type MatrixEventEmittedEvents = MatrixEventEvent | ThreadEvent.Update;
192192

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

203-
export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHandlerMap> {
203+
export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap> {
204204
private pushActions: IActionsObject | null = null;
205205
private _replacingEvent: MatrixEvent | null = null;
206206
private _localRedactionEvent: MatrixEvent | null = null;
@@ -283,7 +283,7 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
283283
*/
284284
public verificationRequest?: VerificationRequest;
285285

286-
private readonly reEmitter: TypedReEmitter<EmittedEvents, MatrixEventHandlerMap>;
286+
private readonly reEmitter: TypedReEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap>;
287287

288288
/**
289289
* Construct a Matrix Event object

src/models/room.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ limitations under the License.
1818
* @module models/room
1919
*/
2020

21-
import { EventTimelineSet, DuplicateStrategy, IAddLiveEventOptions } from "./event-timeline-set";
21+
import {
22+
EventTimelineSet,
23+
DuplicateStrategy,
24+
IAddLiveEventOptions,
25+
EventTimelineSetHandlerMap,
26+
} from "./event-timeline-set";
2227
import { Direction, EventTimeline } from "./event-timeline";
2328
import { getHttpUriForMxc } from "../content-repo";
2429
import * as utils from "../utils";
@@ -130,7 +135,7 @@ export enum RoomEvent {
130135
UnreadNotifications = "Room.UnreadNotifications",
131136
}
132137

133-
type EmittedEvents = RoomEvent
138+
export type RoomEmittedEvents = RoomEvent
134139
| RoomStateEvent.Events
135140
| RoomStateEvent.Members
136141
| RoomStateEvent.NewMember
@@ -171,8 +176,12 @@ export type RoomEventHandlerMap = {
171176
) => void;
172177
[RoomEvent.TimelineRefresh]: (room: Room, eventTimelineSet: EventTimelineSet) => void;
173178
[ThreadEvent.New]: (thread: Thread, toStartOfTimeline: boolean) => void;
174-
} & ThreadHandlerMap
175-
& MatrixEventHandlerMap
179+
} & Pick<
180+
ThreadHandlerMap,
181+
ThreadEvent.Update | ThreadEvent.NewReply
182+
>
183+
& EventTimelineSetHandlerMap
184+
& Pick<MatrixEventHandlerMap, MatrixEventEvent.BeforeRedaction>
176185
& Pick<
177186
RoomStateEventHandlerMap,
178187
RoomStateEvent.Events
@@ -187,8 +196,8 @@ export type RoomEventHandlerMap = {
187196
BeaconEvent.Update | BeaconEvent.Destroy | BeaconEvent.LivenessChange
188197
>;
189198

190-
export class Room extends ReadReceipt<EmittedEvents, RoomEventHandlerMap> {
191-
public readonly reEmitter: TypedReEmitter<EmittedEvents, RoomEventHandlerMap>;
199+
export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
200+
public readonly reEmitter: TypedReEmitter<RoomEmittedEvents, RoomEventHandlerMap>;
192201
private txnToEvent: Record<string, MatrixEvent> = {}; // Pending in-flight requests { string: MatrixEvent }
193202
private notificationCounts: NotificationCount = {};
194203
private readonly threadNotifications = new Map<string, NotificationCount>();

0 commit comments

Comments
 (0)