From 2dfe0f330c0fbfaae249fda03ffd965efecabeb0 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 1 Jun 2023 11:48:36 +0600 Subject: [PATCH] UBER-277 Reminders don't have notifications (#3315) Signed-off-by: Denis Bykhov --- models/calendar/src/index.ts | 10 ++++-- models/server-calendar/package.json | 2 ++ models/server-calendar/src/index.ts | 10 ++++++ plugins/notification/src/index.ts | 2 ++ .../calendar-resources/package.json | 5 ++- .../calendar-resources/src/index.ts | 36 ++++++++++++++++++- server-plugins/calendar/package.json | 1 + server-plugins/calendar/src/index.ts | 3 ++ .../notification-resources/src/index.ts | 17 +++++++-- 9 files changed, 79 insertions(+), 7 deletions(-) diff --git a/models/calendar/src/index.ts b/models/calendar/src/index.ts index 18e32499e9..105e1544c0 100644 --- a/models/calendar/src/index.ts +++ b/models/calendar/src/index.ts @@ -137,6 +137,10 @@ export function createModel (builder: Builder): void { calendar.ids.CalendarNotificationGroup ) + builder.mixin(calendar.class.Event, core.class.Class, notification.mixin.ClassCollaborators, { + fields: ['participants'] + }) + builder.createDoc( notification.class.NotificationType, core.space.Model, @@ -145,7 +149,9 @@ export function createModel (builder: Builder): void { generated: false, label: calendar.string.Reminder, group: calendar.ids.CalendarNotificationGroup, - txClasses: [], + txClasses: [core.class.TxMixin], + field: 'state', + txMatch: { 'attributes.state': 'done' }, objectClass: calendar.mixin.Reminder, allowedForAuthor: true, templates: { @@ -168,7 +174,7 @@ export function createModel (builder: Builder): void { objectClass: calendar.mixin.Reminder, icon: calendar.icon.Reminder, txClass: core.class.TxMixin, - label: calendar.string.CreatedReminder, + label: calendar.string.Reminder, component: calendar.activity.ReminderViewlet, display: 'emphasized', editable: false, diff --git a/models/server-calendar/package.json b/models/server-calendar/package.json index a4995aedff..f8696950e4 100644 --- a/models/server-calendar/package.json +++ b/models/server-calendar/package.json @@ -28,6 +28,8 @@ "@hcengineering/core": "^0.6.25", "@hcengineering/model": "^0.6.4", "@hcengineering/platform": "^0.6.9", + "@hcengineering/server-notification": "^0.6.0", + "@hcengineering/calendar": "^0.6.9", "@hcengineering/server-calendar": "^0.6.0", "@hcengineering/server-core": "^0.6.1" } diff --git a/models/server-calendar/src/index.ts b/models/server-calendar/src/index.ts index a6aa90c369..76fd3c49ea 100644 --- a/models/server-calendar/src/index.ts +++ b/models/server-calendar/src/index.ts @@ -15,13 +15,23 @@ import { Builder } from '@hcengineering/model' +import calendar from '@hcengineering/calendar' import core, { Class, Doc } from '@hcengineering/core' +import serverNotification from '@hcengineering/server-notification' import serverCalendar from '@hcengineering/server-calendar' import serverCore, { ObjectDDParticipant } from '@hcengineering/server-core' export { serverCalendarId } from '@hcengineering/server-calendar' export function createModel (builder: Builder): void { + builder.mixin(calendar.class.Event, core.class.Class, serverNotification.mixin.HTMLPresenter, { + presenter: serverCalendar.function.EventHTMLPresenter + }) + + builder.mixin(calendar.class.Event, core.class.Class, serverNotification.mixin.TextPresenter, { + presenter: serverCalendar.function.EventTextPresenter + }) + builder.mixin, ObjectDDParticipant>( core.class.Doc, core.class.Class, diff --git a/plugins/notification/src/index.ts b/plugins/notification/src/index.ts index 0e65620424..ea3960712b 100644 --- a/plugins/notification/src/index.ts +++ b/plugins/notification/src/index.ts @@ -19,6 +19,7 @@ import { AttachedDoc, Class, Doc, + DocumentQuery, Mixin, Ref, Space, @@ -103,6 +104,7 @@ export interface NotificationType extends Doc { attachedToClass?: Ref> // use for update/mixin txes field?: string + txMatch?: DocumentQuery // use for space collaborators, not object spaceSubscribe?: boolean // allowed providers and default value for it diff --git a/server-plugins/calendar-resources/package.json b/server-plugins/calendar-resources/package.json index 49468fb967..8db7173529 100644 --- a/server-plugins/calendar-resources/package.json +++ b/server-plugins/calendar-resources/package.json @@ -27,6 +27,9 @@ }, "dependencies": { "@hcengineering/core": "^0.6.25", - "@hcengineering/calendar": "^0.6.9" + "@hcengineering/platform": "^0.6.9", + "@hcengineering/calendar": "^0.6.9", + "@hcengineering/server-core": "^0.6.1", + "@hcengineering/server-notification-resources": "^0.6.0" } } diff --git a/server-plugins/calendar-resources/src/index.ts b/server-plugins/calendar-resources/src/index.ts index 236db40144..1c0a215313 100644 --- a/server-plugins/calendar-resources/src/index.ts +++ b/server-plugins/calendar-resources/src/index.ts @@ -13,8 +13,11 @@ // limitations under the License. // -import calendar from '@hcengineering/calendar' +import calendar, { Event } from '@hcengineering/calendar' import { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref } from '@hcengineering/core' +import { getResource } from '@hcengineering/platform' +import { TriggerControl } from '@hcengineering/server-core' +import { getHTMLPresenter, getTextPresenter } from '@hcengineering/server-notification-resources' /** * @public @@ -32,9 +35,40 @@ export async function FindReminders ( return result } +/** + * @public + */ +export async function EventHTMLPresenter (doc: Doc, control: TriggerControl): Promise { + const event = doc as Event + const target = (await control.findAll(event.attachedToClass, { _id: event.attachedTo }, { limit: 1 }))[0] + if (target !== undefined) { + const HTMLPresenter = getHTMLPresenter(target._class, control.hierarchy) + const htmlPart = + HTMLPresenter !== undefined ? await (await getResource(HTMLPresenter.presenter))(target, control) : undefined + return htmlPart + } +} + +/** + * @public + */ +export async function EventTextPresenter (doc: Doc, control: TriggerControl): Promise { + const event = doc as Event + const target = (await control.findAll(event.attachedToClass, { _id: event.attachedTo }, { limit: 1 }))[0] + if (target !== undefined) { + const TextPresenter = getTextPresenter(target._class, control.hierarchy) + if (TextPresenter === undefined) return + return await ( + await getResource(TextPresenter.presenter) + )(target, control) + } +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ function: { + EventHTMLPresenter, + EventTextPresenter, FindReminders } }) diff --git a/server-plugins/calendar/package.json b/server-plugins/calendar/package.json index 874ce1e048..1e7cfbccb7 100644 --- a/server-plugins/calendar/package.json +++ b/server-plugins/calendar/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "@hcengineering/core": "^0.6.25", + "@hcengineering/server-notification": "^0.6.0", "@hcengineering/platform": "^0.6.9" } } diff --git a/server-plugins/calendar/src/index.ts b/server-plugins/calendar/src/index.ts index bac22d03f4..da0e6dcbee 100644 --- a/server-plugins/calendar/src/index.ts +++ b/server-plugins/calendar/src/index.ts @@ -17,6 +17,7 @@ import { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref } from '@hcengineering/core' import type { Plugin, Resource } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform' +import { Presenter } from '@hcengineering/server-notification' /** * @public @@ -28,6 +29,8 @@ export const serverCalendarId = 'server-calendar' as Plugin */ export default plugin(serverCalendarId, { function: { + EventHTMLPresenter: '' as Resource, + EventTextPresenter: '' as Resource, FindReminders: '' as Resource< ( doc: Doc, diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index 5b7e594f24..ee21449cd8 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -38,7 +38,8 @@ import core, { TxProcessor, TxRemoveDoc, TxUpdateDoc, - generateId + generateId, + matchQuery } from '@hcengineering/core' import notification, { ClassCollaborators, @@ -159,11 +160,17 @@ async function getHtmlPart (doc: Doc, control: TriggerControl): Promise>, hierarchy: Hierarchy): HTMLPresenter | undefined { +/** + * @public + */ +export function getHTMLPresenter (_class: Ref>, hierarchy: Hierarchy): HTMLPresenter | undefined { return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.HTMLPresenter) } -function getTextPresenter (_class: Ref>, hierarchy: Hierarchy): TextPresenter | undefined { +/** + * @public + */ +export function getTextPresenter (_class: Ref>, hierarchy: Hierarchy): TextPresenter | undefined { return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.TextPresenter) } @@ -362,6 +369,10 @@ function isTypeMatched ( if (!fieldUpdated(type.field, (extractedTx as TxMixin).attributes)) return false } } + if (type.txMatch !== undefined) { + const res = matchQuery([extractedTx], type.txMatch, extractedTx._class, control.hierarchy, true) + if (res.length === 0) return false + } return true }