diff --git a/app/actions/definitions/collections.tsx b/app/actions/definitions/collections.tsx index 3db4970c20..ee97fd7b33 100644 --- a/app/actions/definitions/collections.tsx +++ b/app/actions/definitions/collections.tsx @@ -233,7 +233,7 @@ export const subscribeCollection = createAction({ await collection?.subscribe(); - toast.success(t("Subscribed to collection notifications")); + toast.success(t("Subscribed to document notifications")); }, }); @@ -263,7 +263,7 @@ export const unsubscribeCollection = createAction({ await collection?.unsubscribe(); - toast.success(t("Unsubscribed from collection notifications")); + toast.success(t("Unsubscribed from document notifications")); }, }); @@ -393,5 +393,7 @@ export const rootCollectionActions = [ createCollection, starCollection, unstarCollection, + subscribeCollection, + unsubscribeCollection, deleteCollection, ]; diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index c47312b044..c271fc7370 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -348,9 +348,9 @@ export const unsubscribeDocument = createAction({ const document = stores.documents.get(activeDocumentId); return ( - !document?.collection?.isSubscribed && - !!document?.isSubscribed && - stores.policies.abilities(activeDocumentId).unsubscribe + !!document?.collection?.isSubscribed || + (!!document?.isSubscribed && + stores.policies.abilities(activeDocumentId).unsubscribe) ); }, perform: async ({ activeDocumentId, stores, currentUserId, t }) => { diff --git a/app/components/ContextMenu/Template.tsx b/app/components/ContextMenu/Template.tsx index cb4bf7c191..9dafb79759 100644 --- a/app/components/ContextMenu/Template.tsx +++ b/app/components/ContextMenu/Template.tsx @@ -20,6 +20,7 @@ import { MenuHeading, MenuItem as TMenuItem, } from "~/types"; +import Tooltip from "../Tooltip"; import Header from "./Header"; import MenuItem, { MenuAnchor } from "./MenuItem"; import MouseSafeArea from "./MouseSafeArea"; @@ -167,7 +168,7 @@ function Template({ items, actions, context, showIcons, ...menu }: Props) { } if (item.type === "button") { - return ( + const menuItem = ( ); + + return item.tooltip ? ( + +
{menuItem}
+
+ ) : ( + <>{menuItem} + ); } if (item.type === "submenu") { diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx index 04932d878a..89d996b988 100644 --- a/app/menus/DocumentMenu.tsx +++ b/app/menus/DocumentMenu.tsx @@ -57,7 +57,7 @@ import useMobile from "~/hooks/useMobile"; import usePolicy from "~/hooks/usePolicy"; import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; -import { MenuItem } from "~/types"; +import { MenuItem, MenuItemButton } from "~/types"; import { documentEditPath } from "~/utils/routeHelpers"; import { MenuContext, useMenuContext } from "./MenuContext"; @@ -257,8 +257,20 @@ const MenuContent: React.FC = observer(function MenuContent_({ }, actionToMenuItem(starDocument, context), actionToMenuItem(unstarDocument, context), - actionToMenuItem(subscribeDocument, context), - actionToMenuItem(unsubscribeDocument, context), + { + ...actionToMenuItem(subscribeDocument, context), + disabled: collection?.isSubscribed, + tooltip: collection?.isSubscribed + ? t("Subscription inherited from collection") + : undefined, + } as MenuItemButton, + { + ...actionToMenuItem(unsubscribeDocument, context), + disabled: collection?.isSubscribed, + tooltip: collection?.isSubscribed + ? t("Subscription inherited from collection") + : undefined, + } as MenuItemButton, { type: "button", title: `${t("Find and replace")}…`, diff --git a/app/types.ts b/app/types.ts index 8431e63ad4..8068fd7361 100644 --- a/app/types.ts +++ b/app/types.ts @@ -27,6 +27,7 @@ export type MenuItemButton = { selected?: boolean; disabled?: boolean; icon?: React.ReactNode; + tooltip?: React.ReactChild; }; export type MenuItemWithChildren = { diff --git a/server/models/helpers/NotificationHelper.ts b/server/models/helpers/NotificationHelper.ts index 53a220d0e1..4d0839f200 100644 --- a/server/models/helpers/NotificationHelper.ts +++ b/server/models/helpers/NotificationHelper.ts @@ -168,12 +168,10 @@ export default class NotificationHelper { attributes: ["userId"], where: { userId: recipients.map((recipient) => recipient.id), + event: SubscriptionType.Document, [Op.or]: [ - { - collectionId: document.collectionId, - event: SubscriptionType.Document, - }, - { documentId: document.id, event: SubscriptionType.Document }, + { collectionId: document.collectionId }, + { documentId: document.id }, ], }, }); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 0ed180d10a..78f10e6a30 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -12,9 +12,9 @@ "Star": "Star", "Unstar": "Unstar", "Subscribe": "Subscribe", - "Subscribed to collection notifications": "Subscribed to collection notifications", + "Subscribed to document notifications": "Subscribed to document notifications", "Unsubscribe": "Unsubscribe", - "Unsubscribed from collection notifications": "Unsubscribed from collection notifications", + "Unsubscribed from document notifications": "Unsubscribed from document notifications", "Archive": "Archive", "Archive collection": "Archive collection", "Collection archived": "Collection archived", @@ -47,8 +47,6 @@ "Publish document": "Publish document", "Unpublish": "Unpublish", "Unpublished {{ documentName }}": "Unpublished {{ documentName }}", - "Subscribed to document notifications": "Subscribed to document notifications", - "Unsubscribed from document notifications": "Unsubscribed from document notifications", "Share this document": "Share this document", "HTML": "HTML", "PDF": "PDF", @@ -534,6 +532,7 @@ "{{ documentName }} restored": "{{ documentName }} restored", "Document options": "Document options", "Choose a collection": "Choose a collection", + "Subscription inherited from collection": "Subscription inherited from collection", "Enable embeds": "Enable embeds", "Export options": "Export options", "Group members": "Group members",