From af73876255f10d32e4e0c6bcb4963d61ffd2d9da Mon Sep 17 00:00:00 2001 From: Oleg Solodkov <94829167+sol-0@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:52:07 +0700 Subject: [PATCH] [UBER-783, UBERF-61] Messsage thread notification fixes (#3640) Signed-off-by: Oleg Solodkov --- models/chunter/src/index.ts | 4 +- models/server-chunter/src/index.ts | 17 +++++-- plugins/chunter-assets/lang/en.json | 1 + plugins/chunter-assets/lang/ru.json | 1 + .../src/components/MessagePresenter.svelte | 21 +++++---- .../src/components/Replies.svelte | 26 ++++++++++- .../src/components/ThreadView.svelte | 5 +- plugins/chunter-resources/src/plugin.ts | 3 +- .../src/components/Inbox.svelte | 46 +++++++++++++------ .../src/components/Workbench.svelte | 2 +- server-plugins/chunter-resources/src/index.ts | 29 ++++++++++-- server-plugins/chunter/src/index.ts | 1 + 12 files changed, 121 insertions(+), 35 deletions(-) diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index fec0e9ddb6..cf1cd313d3 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -721,7 +721,7 @@ export function createModel (builder: Builder, options = { addApplication: true }, group: chunter.ids.ChunterNotificationGroup }, - chunter.ids.ThreadNotification + chunter.ids.ChannelNotification ) builder.createDoc( @@ -738,7 +738,7 @@ export function createModel (builder: Builder, options = { addApplication: true }, group: chunter.ids.ChunterNotificationGroup }, - chunter.ids.ChannelNotification + chunter.ids.ThreadNotification ) createAction(builder, { diff --git a/models/server-chunter/src/index.ts b/models/server-chunter/src/index.ts index 7937d578a9..27390bf7d7 100644 --- a/models/server-chunter/src/index.ts +++ b/models/server-chunter/src/index.ts @@ -58,10 +58,6 @@ export function createModel (builder: Builder): void { } }) - builder.mixin(chunter.ids.DMNotification, notification.class.NotificationType, serverNotification.mixin.TypeMatch, { - func: serverChunter.function.IsDirectMessage - }) - builder.mixin( chunter.ids.MentionNotification, notification.class.NotificationType, @@ -71,6 +67,19 @@ export function createModel (builder: Builder): void { } ) + builder.mixin(chunter.ids.DMNotification, notification.class.NotificationType, serverNotification.mixin.TypeMatch, { + func: serverChunter.function.IsDirectMessage + }) + + builder.mixin( + chunter.ids.ThreadNotification, + notification.class.NotificationType, + serverNotification.mixin.TypeMatch, + { + func: serverChunter.function.IsThreadMessage + } + ) + builder.mixin( chunter.ids.ChannelNotification, notification.class.NotificationType, diff --git a/plugins/chunter-assets/lang/en.json b/plugins/chunter-assets/lang/en.json index 9510a44b63..477eef243e 100644 --- a/plugins/chunter-assets/lang/en.json +++ b/plugins/chunter-assets/lang/en.json @@ -23,6 +23,7 @@ "Comment": "Comment", "Message": "Message", "MessageOn": "Message on", + "On": "on", "Reference": "Reference", "Chat": "Chat", "In": "In", diff --git a/plugins/chunter-assets/lang/ru.json b/plugins/chunter-assets/lang/ru.json index 976ef2292d..53c032ef16 100644 --- a/plugins/chunter-assets/lang/ru.json +++ b/plugins/chunter-assets/lang/ru.json @@ -23,6 +23,7 @@ "Comment": "Комментарий", "Message": "Сообщение", "MessageOn": "Сообщение в", + "On": "в", "MentionNotification": "Упомянул", "Reference": "Ссылка", "Chat": "Чат", diff --git a/plugins/chunter-resources/src/components/MessagePresenter.svelte b/plugins/chunter-resources/src/components/MessagePresenter.svelte index c8d25c64a2..ac63fd8ea2 100644 --- a/plugins/chunter-resources/src/components/MessagePresenter.svelte +++ b/plugins/chunter-resources/src/components/MessagePresenter.svelte @@ -20,11 +20,14 @@ import { AttributeModel } from '@hcengineering/view' import { getObjectPresenter } from '@hcengineering/view-resources' + import chunterResources from '../plugin' + export let value: Message export let inline: boolean = false export let disabled = false const client = getClient() + const isThreadMessage = client.getHierarchy().isDerived(value._class, chunter.class.ThreadMessage) let presenter: AttributeModel | undefined getObjectPresenter(client, value.attachedToClass, { key: '' }).then((p) => { @@ -40,14 +43,16 @@ {#if inline} {#if presenter && doc} -
-
- -
- - -   +
+ {#if isThreadMessage} +
+ +
+ + +   + {/if}
{/if} diff --git a/plugins/chunter-resources/src/components/Replies.svelte b/plugins/chunter-resources/src/components/Replies.svelte index 0b0e3bf61b..ec31e933a6 100644 --- a/plugins/chunter-resources/src/components/Replies.svelte +++ b/plugins/chunter-resources/src/components/Replies.svelte @@ -16,20 +16,33 @@ import { Message } from '@hcengineering/chunter' import { Person } from '@hcengineering/contact' import { personByIdStore } from '@hcengineering/contact-resources' - import { IdMap, Ref } from '@hcengineering/core' + import { Doc, IdMap, Ref } from '@hcengineering/core' import { Avatar } from '@hcengineering/contact-resources' import { Label, TimeSince } from '@hcengineering/ui' + import { NotificationClientImpl } from '@hcengineering/notification-resources' + import { DocUpdates } from '@hcengineering/notification' + import chunter from '../plugin' export let message: Message $: lastReply = message.lastReply ?? new Date().getTime() $: employees = new Set(message.replies) + const notificationClient = NotificationClientImpl.getClient() + const docUpdates = notificationClient.docUpdatesStore + const shown: number = 4 let showReplies: Person[] = [] + $: hasNew = checkNewReplies(message, $docUpdates) $: updateQuery(employees, $personByIdStore) + function checkNewReplies (message: Message, docUpdates: Map, DocUpdates>): boolean { + const docUpdate = docUpdates.get(message._id) + if (docUpdate === undefined) return false + return docUpdate.txes.filter((tx) => tx.isNew).length > 0 + } + function updateQuery (employees: Set>, map: IdMap) { showReplies = [] for (const employee of employees) { @@ -55,6 +68,9 @@
+ {#if hasNew} +
+ {/if} {#if (message.replies?.length ?? 0) > 1}
- {#if asideId} + {#if asideId && currentSpace} {@const asideComponent = navigatorModel?.aside ?? currentApplication?.aside} {#if asideComponent !== undefined}
diff --git a/server-plugins/chunter-resources/src/index.ts b/server-plugins/chunter-resources/src/index.ts index 5e83731919..fc4ee79ef9 100644 --- a/server-plugins/chunter-resources/src/index.ts +++ b/server-plugins/chunter-resources/src/index.ts @@ -13,7 +13,15 @@ // limitations under the License. // -import chunter, { Backlink, chunterId, ChunterSpace, Comment, Message, ThreadMessage } from '@hcengineering/chunter' +import chunter, { + Backlink, + chunterId, + ChunterSpace, + Comment, + DirectMessage, + Message, + ThreadMessage +} from '@hcengineering/chunter' import contact, { Employee, PersonAccount } from '@hcengineering/contact' import core, { Account, @@ -455,8 +463,8 @@ export async function IsDirectMessage ( type: NotificationType, control: TriggerControl ): Promise { - const space = (await control.findAll(chunter.class.DirectMessage, { _id: doc.space }))[0] - return space !== undefined + const dm = (await control.findAll(chunter.class.DirectMessage, { _id: doc._id as Ref }))[0] + return dm !== undefined } function isBacklink (ptx: TxCollectionCUD, hierarchy: Hierarchy): boolean { @@ -508,6 +516,20 @@ export async function IsChannelMessage ( return space !== undefined } +/** + * @public + */ +export async function IsThreadMessage ( + tx: Tx, + doc: Doc, + user: Ref, + type: NotificationType, + control: TriggerControl +): Promise { + const space = (await control.findAll(chunter.class.DirectMessage, { _id: doc.space }))[0] + return space !== undefined +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ trigger: { @@ -520,6 +542,7 @@ export default async () => ({ ChannelHTMLPresenter: channelHTMLPresenter, ChannelTextPresenter: channelTextPresenter, IsDirectMessage, + IsThreadMessage, IsMeMentioned, IsChannelMessage } diff --git a/server-plugins/chunter/src/index.ts b/server-plugins/chunter/src/index.ts index ebcca7bdd1..88c64b52bc 100644 --- a/server-plugins/chunter/src/index.ts +++ b/server-plugins/chunter/src/index.ts @@ -49,6 +49,7 @@ export default plugin(serverChunterId, { ChannelTextPresenter: '' as Resource, IsDirectMessage: '' as TypeMatchFunc, IsChannelMessage: '' as TypeMatchFunc, + IsThreadMessage: '' as TypeMatchFunc, IsMeMentioned: '' as TypeMatchFunc } })