UBER-277 Reminders don't have notifications (#3315)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-06-01 11:48:36 +06:00 committed by GitHub
parent 58ba8fbe07
commit 2dfe0f330c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 7 deletions

View File

@ -137,6 +137,10 @@ export function createModel (builder: Builder): void {
calendar.ids.CalendarNotificationGroup calendar.ids.CalendarNotificationGroup
) )
builder.mixin(calendar.class.Event, core.class.Class, notification.mixin.ClassCollaborators, {
fields: ['participants']
})
builder.createDoc( builder.createDoc(
notification.class.NotificationType, notification.class.NotificationType,
core.space.Model, core.space.Model,
@ -145,7 +149,9 @@ export function createModel (builder: Builder): void {
generated: false, generated: false,
label: calendar.string.Reminder, label: calendar.string.Reminder,
group: calendar.ids.CalendarNotificationGroup, group: calendar.ids.CalendarNotificationGroup,
txClasses: [], txClasses: [core.class.TxMixin],
field: 'state',
txMatch: { 'attributes.state': 'done' },
objectClass: calendar.mixin.Reminder, objectClass: calendar.mixin.Reminder,
allowedForAuthor: true, allowedForAuthor: true,
templates: { templates: {
@ -168,7 +174,7 @@ export function createModel (builder: Builder): void {
objectClass: calendar.mixin.Reminder, objectClass: calendar.mixin.Reminder,
icon: calendar.icon.Reminder, icon: calendar.icon.Reminder,
txClass: core.class.TxMixin, txClass: core.class.TxMixin,
label: calendar.string.CreatedReminder, label: calendar.string.Reminder,
component: calendar.activity.ReminderViewlet, component: calendar.activity.ReminderViewlet,
display: 'emphasized', display: 'emphasized',
editable: false, editable: false,

View File

@ -28,6 +28,8 @@
"@hcengineering/core": "^0.6.25", "@hcengineering/core": "^0.6.25",
"@hcengineering/model": "^0.6.4", "@hcengineering/model": "^0.6.4",
"@hcengineering/platform": "^0.6.9", "@hcengineering/platform": "^0.6.9",
"@hcengineering/server-notification": "^0.6.0",
"@hcengineering/calendar": "^0.6.9",
"@hcengineering/server-calendar": "^0.6.0", "@hcengineering/server-calendar": "^0.6.0",
"@hcengineering/server-core": "^0.6.1" "@hcengineering/server-core": "^0.6.1"
} }

View File

@ -15,13 +15,23 @@
import { Builder } from '@hcengineering/model' import { Builder } from '@hcengineering/model'
import calendar from '@hcengineering/calendar'
import core, { Class, Doc } from '@hcengineering/core' import core, { Class, Doc } from '@hcengineering/core'
import serverNotification from '@hcengineering/server-notification'
import serverCalendar from '@hcengineering/server-calendar' import serverCalendar from '@hcengineering/server-calendar'
import serverCore, { ObjectDDParticipant } from '@hcengineering/server-core' import serverCore, { ObjectDDParticipant } from '@hcengineering/server-core'
export { serverCalendarId } from '@hcengineering/server-calendar' export { serverCalendarId } from '@hcengineering/server-calendar'
export function createModel (builder: Builder): void { 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<Class<Doc>, ObjectDDParticipant>( builder.mixin<Class<Doc>, ObjectDDParticipant>(
core.class.Doc, core.class.Doc,
core.class.Class, core.class.Class,

View File

@ -19,6 +19,7 @@ import {
AttachedDoc, AttachedDoc,
Class, Class,
Doc, Doc,
DocumentQuery,
Mixin, Mixin,
Ref, Ref,
Space, Space,
@ -103,6 +104,7 @@ export interface NotificationType extends Doc {
attachedToClass?: Ref<Class<Doc>> attachedToClass?: Ref<Class<Doc>>
// use for update/mixin txes // use for update/mixin txes
field?: string field?: string
txMatch?: DocumentQuery<Tx>
// use for space collaborators, not object // use for space collaborators, not object
spaceSubscribe?: boolean spaceSubscribe?: boolean
// allowed providers and default value for it // allowed providers and default value for it

View File

@ -27,6 +27,9 @@
}, },
"dependencies": { "dependencies": {
"@hcengineering/core": "^0.6.25", "@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"
} }
} }

View File

@ -13,8 +13,11 @@
// limitations under the License. // 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 { 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 * @public
@ -32,9 +35,40 @@ export async function FindReminders (
return result return result
} }
/**
* @public
*/
export async function EventHTMLPresenter (doc: Doc, control: TriggerControl): Promise<string | undefined> {
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<string | undefined> {
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 // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({ export default async () => ({
function: { function: {
EventHTMLPresenter,
EventTextPresenter,
FindReminders FindReminders
} }
}) })

View File

@ -28,6 +28,7 @@
}, },
"dependencies": { "dependencies": {
"@hcengineering/core": "^0.6.25", "@hcengineering/core": "^0.6.25",
"@hcengineering/server-notification": "^0.6.0",
"@hcengineering/platform": "^0.6.9" "@hcengineering/platform": "^0.6.9"
} }
} }

View File

@ -17,6 +17,7 @@
import { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref } from '@hcengineering/core' import { Class, Doc, DocumentQuery, FindOptions, FindResult, Hierarchy, Ref } from '@hcengineering/core'
import type { Plugin, Resource } from '@hcengineering/platform' import type { Plugin, Resource } from '@hcengineering/platform'
import { plugin } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform'
import { Presenter } from '@hcengineering/server-notification'
/** /**
* @public * @public
@ -28,6 +29,8 @@ export const serverCalendarId = 'server-calendar' as Plugin
*/ */
export default plugin(serverCalendarId, { export default plugin(serverCalendarId, {
function: { function: {
EventHTMLPresenter: '' as Resource<Presenter>,
EventTextPresenter: '' as Resource<Presenter>,
FindReminders: '' as Resource< FindReminders: '' as Resource<
( (
doc: Doc, doc: Doc,

View File

@ -38,7 +38,8 @@ import core, {
TxProcessor, TxProcessor,
TxRemoveDoc, TxRemoveDoc,
TxUpdateDoc, TxUpdateDoc,
generateId generateId,
matchQuery
} from '@hcengineering/core' } from '@hcengineering/core'
import notification, { import notification, {
ClassCollaborators, ClassCollaborators,
@ -159,11 +160,17 @@ async function getHtmlPart (doc: Doc, control: TriggerControl): Promise<string |
return htmlPart return htmlPart
} }
function getHTMLPresenter (_class: Ref<Class<Doc>>, hierarchy: Hierarchy): HTMLPresenter | undefined { /**
* @public
*/
export function getHTMLPresenter (_class: Ref<Class<Doc>>, hierarchy: Hierarchy): HTMLPresenter | undefined {
return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.HTMLPresenter) return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.HTMLPresenter)
} }
function getTextPresenter (_class: Ref<Class<Doc>>, hierarchy: Hierarchy): TextPresenter | undefined { /**
* @public
*/
export function getTextPresenter (_class: Ref<Class<Doc>>, hierarchy: Hierarchy): TextPresenter | undefined {
return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.TextPresenter) return hierarchy.classHierarchyMixin(_class, serverNotification.mixin.TextPresenter)
} }
@ -362,6 +369,10 @@ function isTypeMatched (
if (!fieldUpdated(type.field, (extractedTx as TxMixin<Doc, Doc>).attributes)) return false if (!fieldUpdated(type.field, (extractedTx as TxMixin<Doc, Doc>).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 return true
} }