From d8e69eb6bcdb4191cf68d5ecc3618c0663272390 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 24 May 2023 13:09:11 +0600 Subject: [PATCH] UBER-220 TG/GMAIL new message inbox notifications (#3246) Signed-off-by: Denis Bykhov --- models/gmail/package.json | 2 ++ models/gmail/src/index.ts | 29 +++++++++++++++++++ models/gmail/src/plugin.ts | 4 ++- models/server-chunter/src/index.ts | 4 +-- models/server-gmail/package.json | 4 ++- models/server-gmail/src/index.ts | 6 ++++ models/server-telegram/package.json | 4 ++- models/server-telegram/src/index.ts | 11 +++++++ models/telegram/package.json | 2 ++ models/telegram/src/index.ts | 29 +++++++++++++++++++ models/telegram/src/plugin.ts | 7 +++-- plugins/gmail/package.json | 1 + plugins/gmail/src/index.ts | 4 +++ plugins/telegram-assets/lang/en.json | 1 + plugins/telegram-assets/lang/ru.json | 1 + plugins/telegram/package.json | 1 + plugins/telegram/src/index.ts | 4 +++ server-plugins/chunter-resources/src/index.ts | 8 ++--- server-plugins/chunter/src/index.ts | 4 +-- server-plugins/gmail-resources/src/index.ts | 18 +++++++++++- server-plugins/gmail/package.json | 1 + server-plugins/gmail/src/index.ts | 2 ++ .../telegram-resources/src/index.ts | 18 +++++++++++- server-plugins/telegram/package.json | 1 + server-plugins/telegram/src/index.ts | 2 ++ 25 files changed, 153 insertions(+), 15 deletions(-) diff --git a/models/gmail/package.json b/models/gmail/package.json index 0c8e9dd8bd..25ef92ca12 100644 --- a/models/gmail/package.json +++ b/models/gmail/package.json @@ -36,6 +36,8 @@ "@hcengineering/gmail-resources": "^0.6.0", "@hcengineering/model-attachment": "^0.6.0", "@hcengineering/model-view": "^0.6.0", + "@hcengineering/notification": "^0.6.12", + "@hcengineering/model-notification": "^0.6.0", "@hcengineering/view": "^0.6.6", "@hcengineering/setting": "^0.6.7", "@hcengineering/ui": "^0.6.8" diff --git a/models/gmail/src/index.ts b/models/gmail/src/index.ts index 5c8496823a..0321c5046a 100644 --- a/models/gmail/src/index.ts +++ b/models/gmail/src/index.ts @@ -31,6 +31,7 @@ import { import attachment from '@hcengineering/model-attachment' import contact from '@hcengineering/model-contact' import core, { TAttachedDoc, TDoc } from '@hcengineering/model-core' +import notification from '@hcengineering/model-notification' import view, { createAction } from '@hcengineering/model-view' import setting from '@hcengineering/setting' import gmail from './plugin' @@ -213,6 +214,34 @@ export function createModel (builder: Builder): void { gmail.action.WriteEmail ) + builder.createDoc( + notification.class.NotificationGroup, + core.space.Model, + { + label: gmail.string.Email, + icon: contact.icon.Email + }, + gmail.ids.EmailNotificationGroup + ) + + builder.createDoc( + notification.class.NotificationType, + core.space.Model, + { + label: gmail.string.NewMessage, + generated: false, + hidden: false, + txClasses: [core.class.TxCreateDoc], + objectClass: gmail.class.Message, + group: gmail.ids.EmailNotificationGroup, + allowedForAuthor: true, + providers: { + [notification.providers.PlatformNotification]: true + } + }, + gmail.ids.EmailNotification + ) + builder.mixin(gmail.class.Message, core.class.Class, core.mixin.FullTextSearchContext, { parentPropagate: false }) diff --git a/models/gmail/src/plugin.ts b/models/gmail/src/plugin.ts index 5e90ee4ff4..411b7fd19d 100644 --- a/models/gmail/src/plugin.ts +++ b/models/gmail/src/plugin.ts @@ -21,6 +21,7 @@ import gmail from '@hcengineering/gmail-resources/src/plugin' import type { AnyComponent } from '@hcengineering/ui' import type { TxViewlet } from '@hcengineering/activity' import { Action } from '@hcengineering/view' +import { NotificationGroup } from '@hcengineering/notification' export default mergeIds(gmailId, gmail, { action: { @@ -42,7 +43,8 @@ export default mergeIds(gmailId, gmail, { ConfigDescription: '' as IntlString }, ids: { - TxSharedCreate: '' as Ref + TxSharedCreate: '' as Ref, + EmailNotificationGroup: '' as Ref }, activity: { TxSharedCreate: '' as AnyComponent, diff --git a/models/server-chunter/src/index.ts b/models/server-chunter/src/index.ts index 3b981820e1..55b43c4c41 100644 --- a/models/server-chunter/src/index.ts +++ b/models/server-chunter/src/index.ts @@ -46,7 +46,7 @@ export function createModel (builder: Builder): void { }) builder.mixin(chunter.ids.DMNotification, notification.class.NotificationType, serverNotification.mixin.TypeMatch, { - func: serverChunter.function.IsDirectMessagee + func: serverChunter.function.IsDirectMessage }) builder.mixin( @@ -54,7 +54,7 @@ export function createModel (builder: Builder): void { notification.class.NotificationType, serverNotification.mixin.TypeMatch, { - func: serverChunter.function.IsChannelMessagee + func: serverChunter.function.IsChannelMessage } ) } diff --git a/models/server-gmail/package.json b/models/server-gmail/package.json index f29d441289..c4db651352 100644 --- a/models/server-gmail/package.json +++ b/models/server-gmail/package.json @@ -31,6 +31,8 @@ "@hcengineering/contact": "^0.6.16", "@hcengineering/platform": "^0.6.9", "@hcengineering/server-gmail": "^0.6.0", - "@hcengineering/server-core": "^0.6.1" + "@hcengineering/server-core": "^0.6.1", + "@hcengineering/notification": "^0.6.12", + "@hcengineering/server-notification": "^0.6.0" } } diff --git a/models/server-gmail/src/index.ts b/models/server-gmail/src/index.ts index 287ae35ac8..0b23b70542 100644 --- a/models/server-gmail/src/index.ts +++ b/models/server-gmail/src/index.ts @@ -18,8 +18,10 @@ import { Builder } from '@hcengineering/model' import contact from '@hcengineering/contact' import core, { Class, Doc } from '@hcengineering/core' import gmail from '@hcengineering/gmail' +import notification from '@hcengineering/notification' import serverCore, { ObjectDDParticipant } from '@hcengineering/server-core' import serverGmail from '@hcengineering/server-gmail' +import serverNotification from '@hcengineering/server-notification' export { serverGmailId } from '@hcengineering/server-gmail' export function createModel (builder: Builder): void { @@ -40,4 +42,8 @@ export function createModel (builder: Builder): void { 'tx._class': core.class.TxCreateDoc } }) + + builder.mixin(gmail.ids.EmailNotification, notification.class.NotificationType, serverNotification.mixin.TypeMatch, { + func: serverGmail.function.IsIncomingMessage + }) } diff --git a/models/server-telegram/package.json b/models/server-telegram/package.json index 1feae51044..92600c308d 100644 --- a/models/server-telegram/package.json +++ b/models/server-telegram/package.json @@ -31,6 +31,8 @@ "@hcengineering/platform": "^0.6.9", "@hcengineering/server-telegram": "^0.6.0", "@hcengineering/server-core": "^0.6.1", - "@hcengineering/telegram": "^0.6.9" + "@hcengineering/telegram": "^0.6.9", + "@hcengineering/notification": "^0.6.12", + "@hcengineering/server-notification": "^0.6.0" } } diff --git a/models/server-telegram/src/index.ts b/models/server-telegram/src/index.ts index 32f7787983..2f08f7a4fb 100644 --- a/models/server-telegram/src/index.ts +++ b/models/server-telegram/src/index.ts @@ -20,6 +20,8 @@ import core, { Class, Doc } from '@hcengineering/core' import serverCore, { ObjectDDParticipant } from '@hcengineering/server-core' import serverTelegram from '@hcengineering/server-telegram' import telegram from '@hcengineering/telegram' +import notification from '@hcengineering/notification' +import serverNotification from '@hcengineering/server-notification' export { serverTelegramId } from '@hcengineering/server-telegram' @@ -41,4 +43,13 @@ export function createModel (builder: Builder): void { 'tx._class': core.class.TxCreateDoc } }) + + builder.mixin( + telegram.ids.NewMessageNotification, + notification.class.NotificationType, + serverNotification.mixin.TypeMatch, + { + func: serverTelegram.function.IsIncomingMessage + } + ) } diff --git a/models/telegram/package.json b/models/telegram/package.json index 6badb8a210..69fc9c7497 100644 --- a/models/telegram/package.json +++ b/models/telegram/package.json @@ -31,6 +31,8 @@ "@hcengineering/platform": "^0.6.9", "@hcengineering/model-core": "^0.6.0", "@hcengineering/model-attachment": "^0.6.0", + "@hcengineering/model-notification": "^0.6.0", + "@hcengineering/notification": "^0.6.12", "@hcengineering/model-contact": "^0.6.1", "@hcengineering/view": "^0.6.6", "@hcengineering/contact": "^0.6.16", diff --git a/models/telegram/src/index.ts b/models/telegram/src/index.ts index d52abc1117..b2771c89e0 100644 --- a/models/telegram/src/index.ts +++ b/models/telegram/src/index.ts @@ -41,6 +41,7 @@ import type { import templates from '@hcengineering/templates' import view from '@hcengineering/view' import telegram from './plugin' +import notification from '@hcengineering/model-notification' export { telegramId } from '@hcengineering/telegram' export { telegramOperation } from './migration' @@ -175,6 +176,34 @@ export function createModel (builder: Builder): void { telegram.ids.TxSharedCreate ) + builder.createDoc( + notification.class.NotificationGroup, + core.space.Model, + { + label: telegram.string.Telegram, + icon: contact.icon.Telegram + }, + telegram.ids.NotificationGroup + ) + + builder.createDoc( + notification.class.NotificationType, + core.space.Model, + { + label: telegram.string.NewMessage, + generated: false, + allowedForAuthor: true, + hidden: false, + txClasses: [core.class.TxCreateDoc], + objectClass: telegram.class.Message, + group: telegram.ids.NotificationGroup, + providers: { + [notification.providers.PlatformNotification]: true + } + }, + telegram.ids.NewMessageNotification + ) + builder.mixin(telegram.class.Message, core.class.Class, core.mixin.FullTextSearchContext, { parentPropagate: false }) diff --git a/models/telegram/src/plugin.ts b/models/telegram/src/plugin.ts index 6a8d2a0ff2..cba20d01fa 100644 --- a/models/telegram/src/plugin.ts +++ b/models/telegram/src/plugin.ts @@ -21,6 +21,7 @@ import telegram from '@hcengineering/telegram-resources/src/plugin' import type { AnyComponent } from '@hcengineering/ui' import type { TxViewlet } from '@hcengineering/activity' import { TemplateFieldFunc } from '@hcengineering/templates' +import { NotificationGroup } from '@hcengineering/notification' export default mergeIds(telegramId, telegram, { string: { @@ -33,11 +34,13 @@ export default mergeIds(telegramId, telegram, { TelegramIntegrationDesc: '' as IntlString, Status: '' as IntlString, ConfigLabel: '' as IntlString, - ConfigDescription: '' as IntlString + ConfigDescription: '' as IntlString, + NewMessage: '' as IntlString }, ids: { TxMessage: '' as Ref, - TxSharedCreate: '' as Ref + TxSharedCreate: '' as Ref, + NotificationGroup: '' as Ref }, function: { GetCurrentEmployeeTG: '' as Resource, diff --git a/plugins/gmail/package.json b/plugins/gmail/package.json index c8b1e5dc30..4d0157a2fa 100644 --- a/plugins/gmail/package.json +++ b/plugins/gmail/package.json @@ -30,6 +30,7 @@ "@hcengineering/core": "^0.6.25", "@hcengineering/ui": "^0.6.8", "@hcengineering/contact": "^0.6.16", + "@hcengineering/notification": "^0.6.12", "@hcengineering/setting": "^0.6.7" }, "repository": "https://github.com/hcengineering/anticrm", diff --git a/plugins/gmail/src/index.ts b/plugins/gmail/src/index.ts index ad8c10cea5..396753ad73 100644 --- a/plugins/gmail/src/index.ts +++ b/plugins/gmail/src/index.ts @@ -17,6 +17,7 @@ import { ChannelItem } from '@hcengineering/contact' import type { Account, AttachedDoc, Class, Doc, Ref, Space, Timestamp } from '@hcengineering/core' import type { Plugin } from '@hcengineering/platform' import { Metadata, plugin } from '@hcengineering/platform' +import { NotificationType } from '@hcengineering/notification' import type { Handler, IntegrationType } from '@hcengineering/setting' import type { AnyComponent } from '@hcengineering/ui' @@ -99,6 +100,9 @@ export default plugin(gmailId, { SharedMessages: '' as Ref>, SharedMessage: '' as Ref> }, + ids: { + EmailNotification: '' as Ref + }, space: { Gmail: '' as Ref }, diff --git a/plugins/telegram-assets/lang/en.json b/plugins/telegram-assets/lang/en.json index cddd267e9a..d1d275a0c2 100644 --- a/plugins/telegram-assets/lang/en.json +++ b/plugins/telegram-assets/lang/en.json @@ -19,6 +19,7 @@ "Content": "Content", "Incoming": "Incoming", "Messages": "Messages", + "NewMessage": "New message", "Telegram": "Telegram", "TelegramIntegrationDesc": "Use telegram integration", "Status": "Status", diff --git a/plugins/telegram-assets/lang/ru.json b/plugins/telegram-assets/lang/ru.json index a0f9262168..7cdddb70a7 100644 --- a/plugins/telegram-assets/lang/ru.json +++ b/plugins/telegram-assets/lang/ru.json @@ -19,6 +19,7 @@ "Content": "Содержимое", "Incoming": "Входящее", "Messages": "Сообщения", + "NewMessage": "Новое сообщение", "Telegram": "Telegram", "TelegramIntegrationDesc": "Подключить Telegram", "Status": "Статус", diff --git a/plugins/telegram/package.json b/plugins/telegram/package.json index 43c20fedfa..00331d7803 100644 --- a/plugins/telegram/package.json +++ b/plugins/telegram/package.json @@ -30,6 +30,7 @@ "@hcengineering/core": "^0.6.25", "@hcengineering/ui": "^0.6.8", "@hcengineering/contact": "^0.6.16", + "@hcengineering/notification": "^0.6.12", "@hcengineering/templates": "^0.6.4", "@hcengineering/setting": "^0.6.7" }, diff --git a/plugins/telegram/src/index.ts b/plugins/telegram/src/index.ts index 458027f483..f4600c0437 100644 --- a/plugins/telegram/src/index.ts +++ b/plugins/telegram/src/index.ts @@ -15,6 +15,7 @@ import { ChannelItem } from '@hcengineering/contact' import type { AttachedDoc, Class, Doc, Ref, Space, Timestamp } from '@hcengineering/core' +import { NotificationType } from '@hcengineering/notification' import type { Plugin } from '@hcengineering/platform' import { Metadata, plugin } from '@hcengineering/platform' import type { Handler, IntegrationType } from '@hcengineering/setting' @@ -75,6 +76,9 @@ export default plugin(telegramId, { handler: { DisconnectHandler: '' as Handler }, + ids: { + NewMessageNotification: '' as Ref + }, class: { Message: '' as Ref>, NewMessage: '' as Ref>, diff --git a/server-plugins/chunter-resources/src/index.ts b/server-plugins/chunter-resources/src/index.ts index 586c6db707..1a2a55ba36 100644 --- a/server-plugins/chunter-resources/src/index.ts +++ b/server-plugins/chunter-resources/src/index.ts @@ -207,7 +207,7 @@ export async function ChunterTrigger (tx: Tx, control: TriggerControl): Promise< /** * @public */ -export async function IsDirectMessagee ( +export async function IsDirectMessage ( tx: Tx, doc: Doc, user: Ref, @@ -221,7 +221,7 @@ export async function IsDirectMessagee ( /** * @public */ -export async function IsChannelMessagee ( +export async function IsChannelMessage ( tx: Tx, doc: Doc, user: Ref, @@ -241,7 +241,7 @@ export default async () => ({ CommentRemove, ChannelHTMLPresenter: channelHTMLPresenter, ChannelTextPresenter: channelTextPresenter, - IsDirectMessagee, - IsChannelMessagee + IsDirectMessage, + IsChannelMessage } }) diff --git a/server-plugins/chunter/src/index.ts b/server-plugins/chunter/src/index.ts index 3d829555be..3c4d7be7e0 100644 --- a/server-plugins/chunter/src/index.ts +++ b/server-plugins/chunter/src/index.ts @@ -45,7 +45,7 @@ export default plugin(serverChunterId, { >, ChannelHTMLPresenter: '' as Resource, ChannelTextPresenter: '' as Resource, - IsDirectMessagee: '' as TypeMatchFunc, - IsChannelMessagee: '' as TypeMatchFunc + IsDirectMessage: '' as TypeMatchFunc, + IsChannelMessage: '' as TypeMatchFunc } }) diff --git a/server-plugins/gmail-resources/src/index.ts b/server-plugins/gmail-resources/src/index.ts index 66d64ee17c..0a6c7f07d8 100644 --- a/server-plugins/gmail-resources/src/index.ts +++ b/server-plugins/gmail-resources/src/index.ts @@ -15,6 +15,7 @@ import contact, { Channel } from '@hcengineering/contact' import { + Account, Class, Doc, DocumentQuery, @@ -29,7 +30,7 @@ import { } from '@hcengineering/core' import gmail, { Message } from '@hcengineering/gmail' import { TriggerControl } from '@hcengineering/server-core' -import notification from '@hcengineering/notification' +import notification, { NotificationType } from '@hcengineering/notification' /** * @public @@ -115,9 +116,24 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise return res } +/** + * @public + */ +export async function IsIncomingMessage ( + tx: Tx, + doc: Doc, + user: Ref, + type: NotificationType, + control: TriggerControl +): Promise { + const message = doc as Message + return message.incoming +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ trigger: { + IsIncomingMessage, OnMessageCreate }, function: { diff --git a/server-plugins/gmail/package.json b/server-plugins/gmail/package.json index f57a8a5e20..fa3bfad5d0 100644 --- a/server-plugins/gmail/package.json +++ b/server-plugins/gmail/package.json @@ -29,6 +29,7 @@ "dependencies": { "@hcengineering/core": "^0.6.25", "@hcengineering/platform": "^0.6.9", + "@hcengineering/server-notification": "^0.6.0", "@hcengineering/server-core": "^0.6.1" } } diff --git a/server-plugins/gmail/src/index.ts b/server-plugins/gmail/src/index.ts index 761b0c28d9..89007b3d50 100644 --- a/server-plugins/gmail/src/index.ts +++ b/server-plugins/gmail/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 { TypeMatchFunc } from '@hcengineering/server-notification' import { TriggerFunc } from '@hcengineering/server-core' /** @@ -32,6 +33,7 @@ export default plugin(serverGmailId, { OnMessageCreate: '' as Resource }, function: { + IsIncomingMessage: '' as TypeMatchFunc, FindMessages: '' as Resource< ( doc: Doc, diff --git a/server-plugins/telegram-resources/src/index.ts b/server-plugins/telegram-resources/src/index.ts index 356cdc6a8c..c79bd852ff 100644 --- a/server-plugins/telegram-resources/src/index.ts +++ b/server-plugins/telegram-resources/src/index.ts @@ -15,6 +15,7 @@ import contact, { Channel } from '@hcengineering/contact' import { + Account, Class, Doc, DocumentQuery, @@ -29,7 +30,7 @@ import { } from '@hcengineering/core' import { TriggerControl } from '@hcengineering/server-core' import telegram, { TelegramMessage } from '@hcengineering/telegram' -import notification from '@hcengineering/notification' +import notification, { NotificationType } from '@hcengineering/notification' /** * @public @@ -113,12 +114,27 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise return res } +/** + * @public + */ +export async function IsIncomingMessage ( + tx: Tx, + doc: Doc, + user: Ref, + type: NotificationType, + control: TriggerControl +): Promise { + const message = doc as TelegramMessage + return message.incoming +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ trigger: { OnMessageCreate }, function: { + IsIncomingMessage, FindMessages } }) diff --git a/server-plugins/telegram/package.json b/server-plugins/telegram/package.json index d5b183e21f..ebe03ccc89 100644 --- a/server-plugins/telegram/package.json +++ b/server-plugins/telegram/package.json @@ -29,6 +29,7 @@ "dependencies": { "@hcengineering/core": "^0.6.25", "@hcengineering/platform": "^0.6.9", + "@hcengineering/server-notification": "^0.6.0", "@hcengineering/server-core": "^0.6.1" } } diff --git a/server-plugins/telegram/src/index.ts b/server-plugins/telegram/src/index.ts index d58b4131a6..89fe3265b6 100644 --- a/server-plugins/telegram/src/index.ts +++ b/server-plugins/telegram/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 { TypeMatchFunc } from '@hcengineering/server-notification' import { TriggerFunc } from '@hcengineering/server-core' /** @@ -32,6 +33,7 @@ export default plugin(serverTelegramId, { OnMessageCreate: '' as Resource }, function: { + IsIncomingMessage: '' as TypeMatchFunc, FindMessages: '' as Resource< ( doc: Doc,