Skip to content

Commit 5bd7939

Browse files
committed
Add typing status updates via tagmsg
1 parent e9bec5b commit 5bd7939

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

src/stores/channel.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ const useChannelStore = defineStore('channel', () => {
8282
channel.hasNotification = false;
8383
}
8484

85+
function getTargetChannel(nick: string, target: string) {
86+
const username = parseNick(nick);
87+
if (target.startsWith('#')) {
88+
return getChannel(target);
89+
}
90+
return getChannel(username);
91+
}
92+
8593
function highlightKeywords(message: string): string {
8694
if (notifications.notificationKeywords.length === 0) {
8795
return message;
@@ -104,9 +112,25 @@ const useChannelStore = defineStore('channel', () => {
104112

105113
client
106114
.on('tagmsg', (event) => {
107-
log.debug('TAGMSG', event);
108-
// TODO: Use '+typing' client-tag
109115
// See https://ircv3.net/specs/client-tags/typing
116+
const typing = event.tags['+typing'];
117+
if (typeof typing !== 'string') {
118+
return;
119+
}
120+
121+
const username = parseNick(event.nick);
122+
const channel = getTargetChannel(event.nick, event.target);
123+
switch (typing) {
124+
case 'active':
125+
channel.usersTyping.add(username);
126+
break;
127+
128+
case 'paused':
129+
case 'done':
130+
default:
131+
channel.usersTyping.delete(username);
132+
break;
133+
}
110134
})
111135
.on('action', (event) => {
112136
log.debug('ACTION', event);
@@ -118,9 +142,9 @@ const useChannelStore = defineStore('channel', () => {
118142
log.debug('PRIVMSG', event);
119143
const { message, nick, target, tags } = event;
120144
const username = parseNick(nick);
121-
const isPrivateMessage =
122-
!target.startsWith('#') && irc.currentUser.username === parseNick(target);
123-
const channel = isPrivateMessage ? getChannel(username) : getChannel(target);
145+
const channel = getTargetChannel(nick, target);
146+
// Remove typing status if user sent something
147+
channel.usersTyping.delete(username);
124148

125149
const highlightedMessage = highlightKeywords(message);
126150
const newMessage: Message = {

0 commit comments

Comments
 (0)