diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index cc19aad515..bc153081f6 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -194,6 +194,10 @@ export function createModel (builder: Builder, options = { addApplication: true presenter: chunter.component.DmPresenter }) + builder.mixin(chunter.class.Message, core.class.Class, view.mixin.ObjectPresenter, { + presenter: chunter.component.MessagePresenter + }) + builder.mixin(chunter.class.Channel, core.class.Class, view.mixin.ObjectPresenter, { presenter: chunter.component.ChannelPresenter }) @@ -442,6 +446,22 @@ export function createModel (builder: Builder, options = { addApplication: true chunter.ids.TxCommentRemove ) + builder.createDoc( + activity.class.TxViewlet, + core.space.Model, + { + objectClass: chunter.class.Message, + icon: chunter.icon.Chunter, + txClass: core.class.TxCreateDoc, + component: chunter.activity.TxMessageCreate, + label: notification.string.DMNotification, + display: 'content', + editable: true, + hideOnRemove: true + }, + chunter.ids.TxMessageCreate + ) + builder.createDoc( activity.class.TxViewlet, core.space.Model, diff --git a/models/chunter/src/plugin.ts b/models/chunter/src/plugin.ts index 3c296214cd..15381e1187 100644 --- a/models/chunter/src/plugin.ts +++ b/models/chunter/src/plugin.ts @@ -26,6 +26,7 @@ export default mergeIds(chunterId, chunter, { component: { CommentPresenter: '' as AnyComponent, ChannelPresenter: '' as AnyComponent, + MessagePresenter: '' as AnyComponent, DmPresenter: '' as AnyComponent, Threads: '' as AnyComponent, ThreadView: '' as AnyComponent, @@ -78,12 +79,14 @@ export default mergeIds(chunterId, chunter, { TxCommentCreate: '' as Ref, TxBacklinkCreate: '' as Ref, TxCommentRemove: '' as Ref, - TxBacklinkRemove: '' as Ref + TxBacklinkRemove: '' as Ref, + TxMessageCreate: '' as Ref }, activity: { TxCommentCreate: '' as AnyComponent, TxBacklinkCreate: '' as AnyComponent, - TxBacklinkReference: '' as AnyComponent + TxBacklinkReference: '' as AnyComponent, + TxMessageCreate: '' as AnyComponent }, space: { General: '' as Ref, diff --git a/models/notification/src/index.ts b/models/notification/src/index.ts index 21847b0215..65f84655d2 100644 --- a/models/notification/src/index.ts +++ b/models/notification/src/index.ts @@ -137,6 +137,18 @@ export function createModel (builder: Builder): void { notification.ids.MentionNotification ) + builder.createDoc( + notification.class.NotificationType, + core.space.Model, + { + label: notification.string.DMNotification, + textTemplate: '{sender} has send you a message: {doc} {data}', + htmlTemplate: '

{sender} has send you a message {doc}

{data}', + subjectTemplate: 'You have new DM message in {doc}' + }, + notification.ids.DMNotification + ) + builder.createDoc( notification.class.NotificationProvider, core.space.Model, diff --git a/models/notification/src/plugin.ts b/models/notification/src/plugin.ts index af039114d3..6c9eb1ec7e 100644 --- a/models/notification/src/plugin.ts +++ b/models/notification/src/plugin.ts @@ -21,6 +21,7 @@ import { AnyComponent } from '@hcengineering/ui' export default mergeIds(notificationId, notification, { string: { LastView: '' as IntlString, + DMNotification: '' as IntlString, MentionNotification: '' as IntlString, PlatformNotification: '' as IntlString, BrowserNotification: '' as IntlString, diff --git a/models/server-chunter/src/index.ts b/models/server-chunter/src/index.ts index c610b21902..45b90eb9ee 100644 --- a/models/server-chunter/src/index.ts +++ b/models/server-chunter/src/index.ts @@ -42,4 +42,8 @@ export function createModel (builder: Builder): void { builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverChunter.trigger.ChunterTrigger }) + + builder.createDoc(serverCore.class.Trigger, core.space.Model, { + trigger: serverChunter.trigger.DMTrigger + }) } diff --git a/plugins/chunter-resources/src/components/MessagePresenter.svelte b/plugins/chunter-resources/src/components/MessagePresenter.svelte new file mode 100644 index 0000000000..7639280570 --- /dev/null +++ b/plugins/chunter-resources/src/components/MessagePresenter.svelte @@ -0,0 +1,35 @@ + + +{#if dm} + {#await getDmName(client, dm) then name} + goto()}> + {name} + +
+ {/await} +{/if} diff --git a/plugins/chunter-resources/src/components/activity/TxMessageCreate.svelte b/plugins/chunter-resources/src/components/activity/TxMessageCreate.svelte new file mode 100644 index 0000000000..1c7231a422 --- /dev/null +++ b/plugins/chunter-resources/src/components/activity/TxMessageCreate.svelte @@ -0,0 +1,10 @@ + + +
+ {tx.attributes.content} +
diff --git a/plugins/chunter-resources/src/index.ts b/plugins/chunter-resources/src/index.ts index e23ce9498a..20271ed96c 100644 --- a/plugins/chunter-resources/src/index.ts +++ b/plugins/chunter-resources/src/index.ts @@ -31,8 +31,10 @@ import { getCurrentLocation, navigate, showPopup } from '@hcengineering/ui' import TxBacklinkCreate from './components/activity/TxBacklinkCreate.svelte' import TxBacklinkReference from './components/activity/TxBacklinkReference.svelte' import TxCommentCreate from './components/activity/TxCommentCreate.svelte' +import TxMessageCreate from './components/activity/TxMessageCreate.svelte' import ChannelPresenter from './components/ChannelPresenter.svelte' import DmPresenter from './components/DmPresenter.svelte' +import MessagePresenter from './components/MessagePresenter.svelte' import ChannelView from './components/ChannelView.svelte' import ChannelHeader from './components/ChannelHeader.svelte' import DmHeader from './components/DmHeader.svelte' @@ -229,6 +231,7 @@ export default async (): Promise => ({ CommentPresenter, CommentsPresenter, ChannelPresenter, + MessagePresenter, ChunterBrowser, DmHeader, DmPresenter, @@ -244,7 +247,8 @@ export default async (): Promise => ({ activity: { TxCommentCreate, TxBacklinkCreate, - TxBacklinkReference + TxBacklinkReference, + TxMessageCreate }, actionImpl: { MarkUnread, diff --git a/plugins/notification-assets/lang/en.json b/plugins/notification-assets/lang/en.json index 67448d896c..944c02ba64 100644 --- a/plugins/notification-assets/lang/en.json +++ b/plugins/notification-assets/lang/en.json @@ -5,6 +5,7 @@ "Notifications": "Notifications", "NoNotifications": "No notifications", "MentionNotification": "Mentioned", + "DMNotification": "Sent you a message", "EmailNotification": "by email", "PlatformNotification": "in platform", "Track": "Track", @@ -15,4 +16,4 @@ "MarkAllAsRead": "Mark all notifications as read", "MarkAsRead": "Mark as read" } -} \ No newline at end of file +} diff --git a/plugins/notification-assets/lang/ru.json b/plugins/notification-assets/lang/ru.json index 16efc694d5..adc71a6379 100644 --- a/plugins/notification-assets/lang/ru.json +++ b/plugins/notification-assets/lang/ru.json @@ -5,6 +5,7 @@ "Notifications": "Уведомления", "NoNotifications": "Нет уведомлений", "MentionNotification": "Упомянул", + "DMNotification": "Отправил сообщение", "EmailNotification": "по email", "PlatformNotification": "в системе", "Track": "Отслеживать", @@ -15,4 +16,4 @@ "MarkAllAsRead": "Отметить все нотификации как прочитанные", "MarkAsRead": "Отметить нотификация прочитанной" } -} \ No newline at end of file +} diff --git a/plugins/notification/src/index.ts b/plugins/notification/src/index.ts index 3276bafb3a..ed8c757f45 100644 --- a/plugins/notification/src/index.ts +++ b/plugins/notification/src/index.ts @@ -156,6 +156,7 @@ const notification = plugin(notificationId, { }, ids: { MentionNotification: '' as Ref, + DMNotification: '' as Ref, PlatformNotification: '' as Ref, BrowserNotification: '' as Ref, EmailNotification: '' as Ref, diff --git a/server-plugins/chunter-resources/package.json b/server-plugins/chunter-resources/package.json index d4a6e72dcf..05d34d7e0a 100644 --- a/server-plugins/chunter-resources/package.json +++ b/server-plugins/chunter-resources/package.json @@ -33,6 +33,7 @@ "@hcengineering/chunter": "^0.6.2", "@hcengineering/view": "^0.6.2", "@hcengineering/login": "^0.6.1", - "@hcengineering/workbench": "^0.6.2" + "@hcengineering/workbench": "^0.6.2", + "@hcengineering/notification": "^0.6.5" } } diff --git a/server-plugins/chunter-resources/src/index.ts b/server-plugins/chunter-resources/src/index.ts index dfe94d641c..0c1ce10480 100644 --- a/server-plugins/chunter-resources/src/index.ts +++ b/server-plugins/chunter-resources/src/index.ts @@ -13,7 +13,14 @@ // limitations under the License. // -import chunter, { chunterId, ChunterSpace, Comment, Message, ThreadMessage } from '@hcengineering/chunter' +import chunter, { + chunterId, + ChunterMessage, + ChunterSpace, + Comment, + Message, + ThreadMessage +} from '@hcengineering/chunter' import { EmployeeAccount } from '@hcengineering/contact' import core, { Class, @@ -35,6 +42,9 @@ import login from '@hcengineering/login' import { getMetadata } from '@hcengineering/platform' import { TriggerControl } from '@hcengineering/server-core' import { workbenchId } from '@hcengineering/workbench' +import { getEmployeeAccountById } from '../../notification' +import { createNotificationTxes } from '../../notification-resources' +import notification from '@hcengineering/notification' /** * @public @@ -261,10 +271,51 @@ export async function ChunterTrigger (tx: Tx, control: TriggerControl): Promise< return res.flat() } +/** + * @public + */ +export async function DMTrigger (tx: Tx, control: TriggerControl): Promise { + if (tx._class !== core.class.TxCollectionCUD) return [] + const hierarchy = control.hierarchy + const ctx = tx as TxCollectionCUD + if (!hierarchy.isDerived(ctx.tx.objectClass, chunter.class.Message)) { + return [] + } + const actualTx = TxProcessor.extractTx(tx) + if (actualTx._class !== core.class.TxCreateDoc) { + return [] + } + const doc = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc) + const dms = await control.findAll(chunter.class.DirectMessage, { _id: doc.space }) + if (dms.total === 0) { + return [] + } + const sender = await getEmployeeAccountById(ctx.tx.modifiedBy, control) + if (sender === undefined) return [] + const res: Tx[] = [] + for (const member of dms[0].members) { + const receiver = await getEmployeeAccountById(member, control) + if (receiver === undefined) continue + if (receiver._id === sender._id) continue + const createNotificationTx = await createNotificationTxes( + control, + ctx, + notification.ids.DMNotification, + doc, + sender, + receiver, + doc.content + ) + res.push(...createNotificationTx) + } + return res +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ trigger: { - ChunterTrigger + ChunterTrigger, + DMTrigger }, function: { CommentRemove, diff --git a/server-plugins/chunter/src/index.ts b/server-plugins/chunter/src/index.ts index 182e80e139..dd6d93f39a 100644 --- a/server-plugins/chunter/src/index.ts +++ b/server-plugins/chunter/src/index.ts @@ -29,7 +29,8 @@ export const serverChunterId = 'server-chunter' as Plugin */ export default plugin(serverChunterId, { trigger: { - ChunterTrigger: '' as Resource + ChunterTrigger: '' as Resource, + DMTrigger: '' as Resource }, function: { CommentRemove: '' as Resource<