Skip to content

Commit

Permalink
Add missing tags for ClearChat and UserNotice (#309)
Browse files Browse the repository at this point in the history
* Add missing tags for `ClearChat` and `UserNotice`

* Update following d-fischer's feedback

Co-authored-by: Romybron <>
  • Loading branch information
Romybron committed Nov 9, 2021
1 parent 975f90a commit 621ba2c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/chat/src/ChatClient.ts
Expand Up @@ -183,17 +183,20 @@ export class ChatClient extends IrcClient {
* @param channel The channel the user is timed out from.
* @param user The timed out user.
* @param duration The duration of the timeout, in seconds.
* @param msg The full message object containing all message and user information.
*/
readonly onTimeout: EventBinder<[channel: string, user: string, duration: number]> = this.registerEvent();
readonly onTimeout: EventBinder<[channel: string, user: string, duration: number, msg: ClearChat]> =
this.registerEvent();

/**
* Fires when a user is permanently banned from a channel.
*
* @eventListener
* @param channel The channel the user is banned from.
* @param user The banned user.
* @param msg The full message object containing all message and user information.
*/
readonly onBan: EventBinder<[channel: string, user: string]> = this.registerEvent();
readonly onBan: EventBinder<[channel: string, user: string, msg: ClearChat]> = this.registerEvent();

/**
* Fires when a user upgrades their bits badge in a channel.
Expand All @@ -213,8 +216,9 @@ export class ChatClient extends IrcClient {
*
* @eventListener
* @param channel The channel whose chat is cleared.
* @param msg The full message object containing all message and user information.
*/
readonly onChatClear: EventBinder<[channel: string]> = this.registerEvent();
readonly onChatClear: EventBinder<[channel: string, msg: ClearChat]> = this.registerEvent();

/**
* Fires when emote-only mode is toggled in a channel.
Expand Down Expand Up @@ -831,20 +835,24 @@ export class ChatClient extends IrcClient {
}
});

this.onTypedMessage(ClearChat, ({ params: { channel, user }, tags }) => {
this.onTypedMessage(ClearChat, msg => {
const {
params: { channel, user },
tags
} = msg;
if (user) {
const duration = tags.get('ban-duration');
if (duration === undefined) {
// ban
this.emit(this.onBan, channel, user);
this.emit(this.onBan, channel, user, msg);
} else {
// timeout
this.emit(this.onTimeout, channel, user, Number(duration));
this.emit(this.onTimeout, channel, user, Number(duration), msg);
this.emit(this._onTimeoutResult, channel, user, Number(duration));
}
} else {
// full chat clear
this.emit(this.onChatClear, channel);
this.emit(this.onChatClear, channel, msg);
}
});

Expand Down
Expand Up @@ -14,4 +14,12 @@ export class ClearChat extends Message<ClearChat> {
optional: true
})
user!: MessageParam;

get channelId(): string {
return this._tags.get('room-id')!;
}

get targetUserId(): string | null {
return this._tags.get('target-user-id') ?? null;
}
}
Expand Up @@ -18,6 +18,10 @@ export class UserNotice extends Message<UserNotice> {
})
message!: MessageParam;

get id(): string {
return this._tags.get('id')!;
}

get userInfo(): ChatUser {
return new ChatUser(this._tags.get('login')!, this._tags);
}
Expand Down

0 comments on commit 621ba2c

Please sign in to comment.