Skip to content

Commit 33c4f8c

Browse files
committed
feat: new event chat for event emitter
1 parent 51a27df commit 33c4f8c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/masterchat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export interface Events {
9595
data: (data: ChatResponse, mc: Masterchat) => void;
9696
actions: (actions: Action[], mc: Masterchat) => void;
9797
chats: (chats: AddChatItemAction[], mc: Masterchat) => void;
98+
chat: (chat: AddChatItemAction, mc: Masterchat) => void;
9899
end: (reason: EndReason) => void;
99100
error: (error: MasterchatError | Error) => void;
100101
}
@@ -505,12 +506,13 @@ export class Masterchat extends EventEmitter {
505506
this.emit("actions", actions, this);
506507

507508
// only normal chats
508-
if (this.listenerCount("chats") > 0) {
509+
if (this.listenerCount("chats") > 0 || this.listenerCount("chat") > 0) {
509510
const chats = actions.filter(
510511
(action): action is AddChatItemAction =>
511512
action.type === "addChatItemAction"
512513
);
513514
this.emit("chats", chats, this);
515+
chats.forEach((chat) => this.emit("chat", chat, this));
514516
}
515517
}
516518
};

0 commit comments

Comments
 (0)