Skip to content

Commit 59869ec

Browse files
committed
Prevent notification triggers when replaying chat history
1 parent 7023156 commit 59869ec

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/stores/channel.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const useChannelStore = defineStore('channel', () => {
3737
}
3838

3939
const activeTarget = ref('#general');
40-
4140
function changeActiveChannel(channel: string) {
4241
activeTarget.value = channel;
4342
}
@@ -55,10 +54,14 @@ const useChannelStore = defineStore('channel', () => {
5554
}
5655

5756
irc.client.part(channel);
58-
channelMap.delete(channel);
57+
const otherChannels = channelList.value.filter((c) => c !== channel);
58+
if (otherChannels.length > 0) {
59+
changeActiveChannel(otherChannels[0]);
60+
channelMap.delete(channel);
61+
}
5962
}
6063

61-
async function addMessageNotification(channelName: string, message: Message) {
64+
async function sendMessageNotification(channelName: string, message: Message) {
6265
const user = userList.getUser(message.nick);
6366
const channel = getChannel(channelName);
6467
channel.hasNotification = true;
@@ -163,13 +166,17 @@ const useChannelStore = defineStore('channel', () => {
163166
log.debug('new message:', newMessage);
164167
channel.messages.push(newMessage);
165168

169+
if (typeof newMessage.tags.batch === 'string') {
170+
// Don't trigger notifications on chat history playback
171+
return;
172+
}
166173
// If the user has allows for notifications on channel or keywords
167174
// Display/send notifications if user is in another channel or has browser blurred
168175
// Otherwise mark channel as read if user is actively viewing the channel
169176
const isOtherChannel = channel.name !== activeTarget.value;
170177
if (!isFocusedWindow || isOtherChannel) {
171178
if (channel.notificationsEnabled) {
172-
addMessageNotification(channel.name, newMessage);
179+
sendMessageNotification(channel.name, newMessage);
173180

174181
if (
175182
message.toLocaleLowerCase().includes(irc.currentUser.username.toLocaleLowerCase())
@@ -179,7 +186,7 @@ const useChannelStore = defineStore('channel', () => {
179186
} else if (
180187
notifications.notificationKeywords.some((keyword) => message.includes(keyword))
181188
) {
182-
addMessageNotification(channel.name, newMessage);
189+
sendMessageNotification(channel.name, newMessage);
183190
}
184191
} else {
185192
markAsRead(channel.name);
@@ -188,6 +195,7 @@ const useChannelStore = defineStore('channel', () => {
188195
},
189196
);
190197

198+
// TODO: Add addSystemMessage method
191199
return {
192200
channelList,
193201
activeChannel: computed(() => readonly(getChannel(activeTarget.value))),

src/stores/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export { default as useChannelStore } from './channel';
22
export { default as useChatStore } from './chat';
33
export { default as useIrcStore } from './irc';
4+
export { default as useLayoutStore } from './layout';
45
export { default as useNotificationsStore } from './notifications';
6+
export { default as useOperatorStore } from './operator';
57
export { default as useSettingsStore } from './settings';
68
export { default as useUserListStore } from './user-list';

src/stores/layout.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineStore } from 'pinia';
2+
3+
const useLayoutStore = defineStore('layout', () => {
4+
// TODO: Track chat layout settings here
5+
return {};
6+
});
7+
8+
export default useLayoutStore;

src/stores/operator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { defineStore } from 'pinia';
22
import { computed, ref } from 'vue';
33

4-
const userOperatorStore = defineStore('operator', () => {
4+
const useOperatorStore = defineStore('operator', () => {
55
const isOperator = ref(false);
66
// TODO: Add operator authentication, saving credentials, and operator actions here
77
return {
88
isOperator: computed(() => isOperator),
99
};
1010
});
1111

12-
export default userOperatorStore;
12+
export default useOperatorStore;

src/utils/user.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('user', () => {
1010

1111
it('parses UID from ident or former nick format', () => {
1212
expect(parseUid('AnotherUser', 'anon')).toBe('0');
13-
expect(parseUid('Someone', '~987')).toBe('987');
13+
expect(parseUid('UnverifiedUser', '~987')).toBe('987');
1414
expect(parseUid('Anonymous^456', '67890')).toBe('67890');
1515
expect(parseUid('Chatter__123^1', 'anon')).toBe('123');
1616
});

0 commit comments

Comments
 (0)