p1: prioritize mention browser notifications
All checks were successful
CI / test (push) Successful in 21s
All checks were successful
CI / test (push) Successful in 21s
This commit is contained in:
@@ -104,7 +104,7 @@ export function useRealtime() {
|
||||
} else if (wasInserted) {
|
||||
chatStore.incrementUnread(chatId, hasMentionForUser(message.text, authStore.me?.username ?? null));
|
||||
}
|
||||
maybeShowBrowserNotification(chatId, message, chatStore.activeChatId);
|
||||
maybeShowBrowserNotification(chatId, message, chatStore.activeChatId, authStore.me?.username ?? null);
|
||||
}
|
||||
if (!chatStore.chats.some((chat) => chat.id === chatId)) {
|
||||
scheduleReloadChats();
|
||||
@@ -307,7 +307,12 @@ export function useRealtime() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function maybeShowBrowserNotification(chatId: number, message: Message, activeChatId: number | null): void {
|
||||
function maybeShowBrowserNotification(
|
||||
chatId: number,
|
||||
message: Message,
|
||||
activeChatId: number | null,
|
||||
currentUsername: string | null
|
||||
): void {
|
||||
const prefs = getAppPreferences();
|
||||
if (!prefs.webNotifications) {
|
||||
return;
|
||||
@@ -319,16 +324,18 @@ function maybeShowBrowserNotification(chatId: number, message: Message, activeCh
|
||||
return;
|
||||
}
|
||||
const chat = useChatStore.getState().chats.find((item) => item.id === chatId);
|
||||
if (chat?.type === "private" && !prefs.privateNotifications) {
|
||||
const isMention = hasMentionForUser(message.text, currentUsername);
|
||||
if (!isMention && chat?.type === "private" && !prefs.privateNotifications) {
|
||||
return;
|
||||
}
|
||||
if (chat?.type === "group" && !prefs.groupNotifications) {
|
||||
if (!isMention && chat?.type === "group" && !prefs.groupNotifications) {
|
||||
return;
|
||||
}
|
||||
if (chat?.type === "channel" && !prefs.channelNotifications) {
|
||||
if (!isMention && chat?.type === "channel" && !prefs.channelNotifications) {
|
||||
return;
|
||||
}
|
||||
const title = chat?.display_title || chat?.title || "New message";
|
||||
const titleBase = chat?.display_title || chat?.title || "New message";
|
||||
const title = isMention ? `@ Mention in ${titleBase}` : titleBase;
|
||||
const preview = buildNotificationPreview(message, prefs.messagePreview);
|
||||
|
||||
void (async () => {
|
||||
|
||||
Reference in New Issue
Block a user