From 068397901afe6fe644678f390b604abf50484c0c Mon Sep 17 00:00:00 2001 From: Salihu Date: Sun, 8 Mar 2026 19:50:46 +0100 Subject: [PATCH] bug fixes --- app/scenes/Settings/Notifications.tsx | 7 ++----- .../Settings/components/ChannelSelector.tsx | 18 +++++++++++------- patches/chat+4.15.0.patch | 18 +++--------------- server/models/User.ts | 4 ++-- server/models/helpers/NotificationHelper.ts | 9 ++++++++- ...cessor.ts => SlackNotificationProcessor.ts} | 2 +- shared/types.ts | 1 + 7 files changed, 28 insertions(+), 31 deletions(-) rename server/queues/processors/{SlackProcessor.ts => SlackNotificationProcessor.ts} (98%) diff --git a/app/scenes/Settings/Notifications.tsx b/app/scenes/Settings/Notifications.tsx index c8fadd969a..18ffd5d66f 100644 --- a/app/scenes/Settings/Notifications.tsx +++ b/app/scenes/Settings/Notifications.tsx @@ -176,12 +176,9 @@ function Notifications() { NotificationChannelType.Slack, ]) { const shouldEnable = channels.includes(channel); - const currentlyEnabled = user.subscribedToEventType( - eventType, - channel - ); + const enabled = user.subscribedToEventType(eventType, channel); - if (shouldEnable !== currentlyEnabled) { + if (shouldEnable !== enabled) { await user.setNotificationEventType( eventType, shouldEnable, diff --git a/app/scenes/Settings/components/ChannelSelector.tsx b/app/scenes/Settings/components/ChannelSelector.tsx index 62bf63a872..9ddcbb4083 100644 --- a/app/scenes/Settings/components/ChannelSelector.tsx +++ b/app/scenes/Settings/components/ChannelSelector.tsx @@ -19,21 +19,25 @@ type Props = { function ChannelSelector({ value, onChange, slackDisabled = false }: Props) { const { t } = useTranslation(); - const channels = React.useMemo( - () => [ + const channels = React.useMemo(() => { + const availableChannels = [ { key: NotificationChannelType.Email, label: t("Email"), icon: , }, - { + ]; + + if (!slackDisabled) { + availableChannels.push({ key: NotificationChannelType.Slack, label: t("Slack"), icon: , - }, - ], - [t, slackDisabled] - ); + }); + } + + return availableChannels; + }, [t, slackDisabled]); const handleToggle = React.useCallback( (channelType: NotificationChannelType) => { diff --git a/patches/chat+4.15.0.patch b/patches/chat+4.15.0.patch index 36c888eab3..d3252fe13e 100644 --- a/patches/chat+4.15.0.patch +++ b/patches/chat+4.15.0.patch @@ -1,8 +1,8 @@ diff --git a/node_modules/chat/package.json b/node_modules/chat/package.json -index 89e4e44..24b552d 100644 +index 89e4e44..7cfcb8f 100644 --- a/node_modules/chat/package.json +++ b/node_modules/chat/package.json -@@ -9,15 +9,18 @@ +@@ -9,7 +9,8 @@ "exports": { ".": { "types": "./dist/index.d.ts", @@ -12,19 +12,7 @@ index 89e4e44..24b552d 100644 }, "./jsx-runtime": { "types": "./dist/jsx-runtime.d.ts", -- "import": "./dist/jsx-runtime.js" -+ "import": "./dist/jsx-runtime.js", -+ "default": "./dist/jsx-runtime.js" - }, - "./jsx-dev-runtime": { - "types": "./dist/jsx-runtime.d.ts", -- "import": "./dist/jsx-runtime.js" -+ "import": "./dist/jsx-runtime.js", -+ "default": "./dist/jsx-runtime.js" - } - }, - "files": [ -@@ -68,4 +71,4 @@ +@@ -68,4 +69,4 @@ "typecheck": "tsc --noEmit", "clean": "rm -rf dist docs" } diff --git a/server/models/User.ts b/server/models/User.ts index 94729efef6..e0464ee71e 100644 --- a/server/models/User.ts +++ b/server/models/User.ts @@ -44,6 +44,7 @@ import { NotificationEventDefaults, UserRole, DocumentPermission, + IntegrationType, } from "@shared/types"; import { UserRoleHelper } from "@shared/utils/UserRoleHelper"; import { stringToColor } from "@shared/utils/color"; @@ -74,6 +75,7 @@ import IsUrlOrRelativePath from "./validators/IsUrlOrRelativePath"; import Length from "./validators/Length"; import NotContainsUrl from "./validators/NotContainsUrl"; import { SkipChangeset } from "./decorators/Changeset"; +import Integration from "./Integration"; /** * Flags that are available for setting on the user. @@ -416,8 +418,6 @@ class User extends ParanoidModel< * @returns The Slack user ID or null. */ public getSlackUserId = async (): Promise => { - const { Integration } = await import("./index"); - const { IntegrationType } = await import("@shared/types"); const integration = await Integration.findOne({ where: { userId: this.id, diff --git a/server/models/helpers/NotificationHelper.ts b/server/models/helpers/NotificationHelper.ts index 951732ad0d..3c5ea52b7d 100644 --- a/server/models/helpers/NotificationHelper.ts +++ b/server/models/helpers/NotificationHelper.ts @@ -4,6 +4,7 @@ import { NotificationEventType, MentionType, SubscriptionType, + NotificationChannelType, } from "@shared/types"; import Logger from "@server/logging/Logger"; import type { Document, Collection } from "@server/models"; @@ -159,11 +160,13 @@ export default class NotificationHelper { notificationType, actorId, disableAccessCheck = false, + channel = NotificationChannelType.Email, }: { document: Document; notificationType: NotificationEventType; actorId: string; disableAccessCheck?: boolean; + channel?: NotificationChannelType; }): Promise => { let recipients: User[]; @@ -175,7 +178,11 @@ export default class NotificationHelper { }, teamId: document.teamId, notificationSettings: { - [notificationType]: true, + [Op.and]: { + [notificationType]: { + [channel]: true, + }, + }, }, }, }); diff --git a/server/queues/processors/SlackProcessor.ts b/server/queues/processors/SlackNotificationProcessor.ts similarity index 98% rename from server/queues/processors/SlackProcessor.ts rename to server/queues/processors/SlackNotificationProcessor.ts index 40b38040fa..80c0d2dc2e 100644 --- a/server/queues/processors/SlackProcessor.ts +++ b/server/queues/processors/SlackNotificationProcessor.ts @@ -15,7 +15,7 @@ import { paragraph, root, strong, text, link } from "chat"; * Listens for notification.create events and sends Slack DMs to users * who have linked their Slack accounts and enabled Slack notifications. */ -export default class SlackNotificationsProcessor extends BaseProcessor { +export default class SlackNotificationProcessor extends BaseProcessor { static applicableEvents: Event["name"][] = ["notifications.create"]; async perform(event: NotificationEvent) { diff --git a/shared/types.ts b/shared/types.ts index 6a7d17a4bd..30be2b7c39 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -508,6 +508,7 @@ export enum NotificationChannelType { App = "app", Email = "email", Chat = "chat", + Slack = "slack", } export type NotificationData = {