thelounge/server/models/client-tags.ts
Raito Bezarius ab678f1ef5 feat(irc framework): support (client) tags
It is now possible to receive, send and process client tags
in general using the IRC framework.

This is useful for many client-oriented IRCv3 features: typing,
reacts, replies, channel contexts, etc.
2023-08-12 13:49:22 +02:00

37 lines
989 B
TypeScript

import _ from "lodash";
export enum ClientTagKey {
// https://ircv3.net/specs/client-tags/reply
DRAFT_REPLY = "draft/reply",
// https://ircv3.net/specs/client-tags/react
DRAFT_REACT = "draft/react",
// https://ircv3.net/specs/client-tags/channel-context
DRAFT_CHANNEL_CONTEXT = "draft/channel-context",
// https://ircv3.net/specs/client-tags/typing.html
TYPING = "typing",
}
export class ClientTags {
reaction?: string;
repliedTo?: string;
channelContext?: string;
rawTags: Record<string, string>;
public constructor(rawClientTags: Record<string, string>) {
this.rawTags = rawClientTags;
this.reaction = this.get(ClientTagKey.DRAFT_REACT);
this.repliedTo = this.get(ClientTagKey.DRAFT_REPLY);
this.channelContext = this.get(ClientTagKey.DRAFT_CHANNEL_CONTEXT);
}
public get(key: string): string | undefined {
return this.rawTags[`+${key}`];
}
public has(key: string): boolean {
return Object.prototype.hasOwnProperty.call(this.rawTags, `+${key}`);
}
}