From bbe2e4e9ce5ccd744cab4c3c4b430ce8db1f00f4 Mon Sep 17 00:00:00 2001 From: Kristina Date: Mon, 23 Sep 2024 10:36:08 +0400 Subject: [PATCH] Add chat fixes (#6682) Signed-off-by: Kristina Fefelova --- packages/ui/src/utils.ts | 2 +- .../components/ActivityMessageActions.svelte | 2 +- .../src/components/ChannelScrollView.svelte | 5 ++-- .../chat/specials/SavedMessages.svelte | 8 +++--- .../threads/ThreadParentPresenter.svelte | 9 ++++++- .../src/components/threads/Threads.svelte | 20 ++++++++++----- plugins/chunter-resources/src/utils.ts | 10 ++------ .../components/sidebar/SidebarExpanded.svelte | 25 +++++++++++++++++-- .../activity-resources/src/references.ts | 2 +- .../notification-resources/src/index.ts | 8 +++--- 10 files changed, 62 insertions(+), 29 deletions(-) diff --git a/packages/ui/src/utils.ts b/packages/ui/src/utils.ts index fb056b68bc..e769f24194 100644 --- a/packages/ui/src/utils.ts +++ b/packages/ui/src/utils.ts @@ -111,7 +111,7 @@ export function addNotification ( title, subTitle, severity, - position: NotificationPosition.TopRight, + position: NotificationPosition.BottomLeft, component, closeTimeout, params diff --git a/plugins/activity-resources/src/components/ActivityMessageActions.svelte b/plugins/activity-resources/src/components/ActivityMessageActions.svelte index 62129d1bf8..5a28faa06e 100644 --- a/plugins/activity-resources/src/components/ActivityMessageActions.svelte +++ b/plugins/activity-resources/src/components/ActivityMessageActions.svelte @@ -39,7 +39,7 @@ $: void updateInlineActions(message, excludedActions) savedMessagesStore.subscribe(() => { - void updateInlineActions(message) + void updateInlineActions(message, excludedActions) }) function handleActionMenuOpened (): void { diff --git a/plugins/chunter-resources/src/components/ChannelScrollView.svelte b/plugins/chunter-resources/src/components/ChannelScrollView.svelte index 6b5644d56b..d02a25591e 100644 --- a/plugins/chunter-resources/src/components/ChannelScrollView.svelte +++ b/plugins/chunter-resources/src/components/ChannelScrollView.svelte @@ -387,7 +387,7 @@ return messageRect.top >= containerRect.top && messageRect.bottom - messageRect.height / 2 <= containerRect.bottom } - const messagesToReadAccumulator: DisplayActivityMessage[] = [] + const messagesToReadAccumulator: Set = new Set() let messagesToReadAccumulatorTimer: any function readViewportMessages (): void { @@ -407,13 +407,14 @@ } if (messageInView(msgElement, containerRect)) { - messagesToReadAccumulator.push(message) + messagesToReadAccumulator.add(message) } } clearTimeout(messagesToReadAccumulatorTimer) messagesToReadAccumulatorTimer = setTimeout(() => { const messagesToRead = [...messagesToReadAccumulator] + messagesToReadAccumulator.clear() void readChannelMessages(sortActivityMessages(messagesToRead), notifyContext) }, 500) } diff --git a/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte b/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte index 54a3d3d5ee..d1855f0b59 100644 --- a/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte +++ b/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte @@ -37,14 +37,14 @@ $: savedMessages = $savedMessagesStore $: savedAttachments = $savedAttachmentsStore - async function openAttachment (attach?: Attachment) { + async function openAttachment (attach?: Attachment): Promise { if (attach === undefined) { return } const messageId: Ref = attach.attachedTo as Ref await client.findOne(activity.class.ActivityMessage, { _id: messageId }).then((res) => { if (res !== undefined) { - openMessageFromSpecial(res) + void openMessageFromSpecial(res) } }) } @@ -62,8 +62,8 @@ } } } - function handleMessageClicked (message?: ActivityMessage) { - openMessageFromSpecial(message) + function handleMessageClicked (message?: ActivityMessage): void { + void openMessageFromSpecial(message) } diff --git a/plugins/chunter-resources/src/components/threads/ThreadParentPresenter.svelte b/plugins/chunter-resources/src/components/threads/ThreadParentPresenter.svelte index 0f9403890f..c0436d5e95 100644 --- a/plugins/chunter-resources/src/components/threads/ThreadParentPresenter.svelte +++ b/plugins/chunter-resources/src/components/threads/ThreadParentPresenter.svelte @@ -19,4 +19,11 @@ export let message: ActivityMessage - + diff --git a/plugins/chunter-resources/src/components/threads/Threads.svelte b/plugins/chunter-resources/src/components/threads/Threads.svelte index 73c954fba3..3e3a0cc68c 100644 --- a/plugins/chunter-resources/src/components/threads/Threads.svelte +++ b/plugins/chunter-resources/src/components/threads/Threads.svelte @@ -19,6 +19,8 @@ import activity, { ActivityMessage } from '@hcengineering/activity' import { PersonAccount } from '@hcengineering/contact' import { ActivityMessagePresenter } from '@hcengineering/activity-resources' + import notification from '@hcengineering/notification' + import attachment from '@hcengineering/attachment' import chunter from '../../plugin' import Header from '../Header.svelte' @@ -32,15 +34,21 @@ $: threadsQuery.query( activity.class.ActivityMessage, { - replies: { $exists: true } + replies: { $exists: true }, + [`${notification.mixin.Collaborators}.collaborators`]: me._id }, (res) => { - threads = res.filter( - ({ createdBy, repliedPersons, replies }) => - (replies !== undefined && replies > 0 && createdBy === me._id) || repliedPersons?.includes(me.person) - ) + threads = res.filter(({ replies }) => (replies ?? 0) > 0) }, - { sort: { modifiedOn: SortingOrder.Descending } } + { + sort: { modifiedOn: SortingOrder.Descending }, + lookup: { + _id: { + attachments: attachment.class.Attachment, + reactions: activity.class.Reaction + } + } + } ) diff --git a/plugins/chunter-resources/src/utils.ts b/plugins/chunter-resources/src/utils.ts index 87b75edcc7..950ea5ec1a 100644 --- a/plugins/chunter-resources/src/utils.ts +++ b/plugins/chunter-resources/src/utils.ts @@ -430,11 +430,7 @@ export async function readChannelMessages ( messages: DisplayActivityMessage[], context: DocNotifyContext | undefined ): Promise { - if (messages.length === 0) { - return - } - - if (context === undefined) { + if (messages.length === 0 || context === undefined) { return } @@ -442,9 +438,7 @@ export async function readChannelMessages ( const client = getClient().apply(undefined, 'readViewportMessages') try { - const readMessages = get(chatReadMessagesStore) - const allIds = getAllIds(messages).filter((id) => !readMessages.has(id)) - + const allIds = getAllIds(messages) const notifications = get(inboxClient.activityInboxNotifications) .filter(({ attachedTo, $lookup, isViewed }) => { if (isViewed) return false diff --git a/plugins/workbench-resources/src/components/sidebar/SidebarExpanded.svelte b/plugins/workbench-resources/src/components/sidebar/SidebarExpanded.svelte index ef3285a94a..7209b04357 100644 --- a/plugins/workbench-resources/src/components/sidebar/SidebarExpanded.svelte +++ b/plugins/workbench-resources/src/components/sidebar/SidebarExpanded.svelte @@ -21,7 +21,8 @@ location as locationStore, Location, Header, - Breadcrumbs + Breadcrumbs, + getCurrentLocation } from '@hcengineering/ui' import { onDestroy } from 'svelte' @@ -45,13 +46,33 @@ $: widgetState = widget !== undefined ? $sidebarStore.widgetsState.get(widget._id) : undefined $: tabId = widgetState?.tab - $: tabs = widgetState?.tabs ?? [] + $: tabs = getTabs(widget, widgetState) $: tab = tabId !== undefined ? tabs.find((it) => it.id === tabId) ?? tabs[0] : tabs[0] $: if ($sidebarStore.widget === undefined) { sidebarStore.update((s) => ({ ...s, variant: SidebarVariant.MINI })) } + function getTabs (widget?: Widget, state?: WidgetState): WidgetTab[] { + if (widget === undefined || !state?.tabs) return [] + const loc = getCurrentLocation() + + const result: WidgetTab[] = [] + for (const tab of state.tabs) { + if (tab.allowedPath !== undefined && !tab.isPinned) { + const path = loc.path.join('/') + if (!path.startsWith(tab.allowedPath)) { + void handleTabClose(tab.id, widget) + continue + } + } + + result.push(tab) + } + + return result + } + const unsubscribe = locationStore.subscribe((loc: Location) => { if (widget === undefined) return diff --git a/server-plugins/activity-resources/src/references.ts b/server-plugins/activity-resources/src/references.ts index d2e66a7531..f260299f70 100644 --- a/server-plugins/activity-resources/src/references.ts +++ b/server-plugins/activity-resources/src/references.ts @@ -248,7 +248,7 @@ export async function getPersonNotificationTxes ( ...content, docNotifyContext: context._id, _id: generateId(), - _class: notification.class.CommonInboxNotification, + _class: notification.class.MentionInboxNotification, space: receiverSpace._id, modifiedOn: originTx.modifiedOn, modifiedBy: sender._id diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index 9390692e34..a09e410c19 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -78,7 +78,7 @@ import serverNotification, { SenderInfo } from '@hcengineering/server-notification' import serverView from '@hcengineering/server-view' -import { markupToHTML, markupToText, stripTags } from '@hcengineering/text' +import { markupToText, stripTags } from '@hcengineering/text' import { encodeObjectURI } from '@hcengineering/view' import { workbenchId } from '@hcengineering/workbench' import webpush, { WebPushError } from 'web-push' @@ -240,8 +240,10 @@ export async function getContentByTemplate ( notificationData !== undefined && control.hierarchy.isDerived(notificationData._class, notification.class.MentionInboxNotification) ) { - const text = (notificationData as MentionInboxNotification).messageHtml - params.body = text !== undefined ? markupToHTML(text) : params.body + const messageContent = (notificationData as MentionInboxNotification).messageHtml + const text = messageContent !== undefined ? markupToText(messageContent) : undefined + params.body = text ?? params.body + params.message = text ?? params.message } if (message !== undefined) {