From 822731c23ce54dbf7999a11e940fb65f70a4b375 Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 24 Sep 2024 16:31:34 +0400 Subject: [PATCH] Qfix sidebar (#6708) --- models/notification/src/index.ts | 4 + models/time/src/plugin.ts | 1 - .../src/components/Channel.svelte | 7 +- .../src/components/ChannelScrollView.svelte | 6 +- .../src/components/ChannelSidebarView.svelte | 18 ++- .../components/threads/ThreadContent.svelte | 79 +++++++++++++ .../src/components/threads/ThreadView.svelte | 108 +++++------------- plugins/chunter-resources/src/navigation.ts | 7 +- plugins/chunter-resources/src/stores.ts | 3 + plugins/chunter/src/index.ts | 17 ++- .../components/DocNotifyContextCard.svelte | 1 + .../src/components/Notification.svelte | 39 +++++-- plugins/notification/src/index.ts | 4 + plugins/time/src/index.ts | 3 +- plugins/workbench-resources/src/sidebar.ts | 17 +++ .../notification-resources/src/index.ts | 30 +++-- server/server-pipeline/package.json | 4 +- .../src/internationalization.ts | 3 + 18 files changed, 238 insertions(+), 113 deletions(-) create mode 100644 plugins/chunter-resources/src/components/threads/ThreadContent.svelte diff --git a/models/notification/src/index.ts b/models/notification/src/index.ts index cc076d5782..07a35e3fde 100644 --- a/models/notification/src/index.ts +++ b/models/notification/src/index.ts @@ -105,6 +105,10 @@ export class TBrowserNotification extends TDoc implements BrowserNotification { onClickLocation?: Location | undefined user!: Ref status!: NotificationStatus + messageId?: Ref + messageClass?: Ref> + objectId!: Ref + objectClass!: Ref> } @Model(notification.class.PushSubscription, core.class.Doc, DOMAIN_USER_NOTIFY) diff --git a/models/time/src/plugin.ts b/models/time/src/plugin.ts index 28c07b59e2..19b134da99 100644 --- a/models/time/src/plugin.ts +++ b/models/time/src/plugin.ts @@ -34,7 +34,6 @@ export default mergeIds(timeId, time, { EditToDo: '' as IntlString, GotoTimePlaning: '' as IntlString, GotoTimeTeamPlaning: '' as IntlString, - NewToDo: '' as IntlString, Priority: '' as IntlString, MarkedAsDone: '' as IntlString }, diff --git a/plugins/chunter-resources/src/components/Channel.svelte b/plugins/chunter-resources/src/components/Channel.svelte index eb43c295af..b07c21d2df 100644 --- a/plugins/chunter-resources/src/components/Channel.svelte +++ b/plugins/chunter-resources/src/components/Channel.svelte @@ -31,14 +31,15 @@ export let isAsideOpened = false export let syncLocation = true export let freeze = false + export let selectedMessageId: Ref | undefined = undefined const client = getClient() const hierarchy = client.getHierarchy() let dataProvider: ChannelDataProvider | undefined - let selectedMessageId: Ref | undefined = undefined const unsubscribe = messageInFocus.subscribe((id) => { + if (!syncLocation) return if (id !== undefined && id !== selectedMessageId) { selectedMessageId = id } @@ -47,9 +48,7 @@ }) const unsubscribeLocation = locationStore.subscribe((newLocation) => { - if (!syncLocation) { - return - } + if (!syncLocation) return const id = getMessageFromLoc(newLocation) selectedMessageId = id messageInFocus.set(id) diff --git a/plugins/chunter-resources/src/components/ChannelScrollView.svelte b/plugins/chunter-resources/src/components/ChannelScrollView.svelte index 1863acb886..7b154a99b0 100644 --- a/plugins/chunter-resources/src/components/ChannelScrollView.svelte +++ b/plugins/chunter-resources/src/components/ChannelScrollView.svelte @@ -582,13 +582,13 @@ } async function restoreScroll () { - if (!scrollElement || !scroller) { + await wait() + + if (!scrollElement || !scroller || scrollToRestore === 0) { scrollToRestore = 0 return } - await wait() - const delta = scrollElement.scrollHeight - scrollToRestore scroller.scrollBy(delta) diff --git a/plugins/chunter-resources/src/components/ChannelSidebarView.svelte b/plugins/chunter-resources/src/components/ChannelSidebarView.svelte index 440f363341..920eb30fe9 100644 --- a/plugins/chunter-resources/src/components/ChannelSidebarView.svelte +++ b/plugins/chunter-resources/src/components/ChannelSidebarView.svelte @@ -18,7 +18,9 @@ import { DocNotifyContext } from '@hcengineering/notification' import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources' import { Widget } from '@hcengineering/workbench' + import { ActivityMessage } from '@hcengineering/activity' import { ChatWidgetTab } from '@hcengineering/chunter' + import { updateTabData } from '@hcengineering/workbench-resources' import Channel from './Channel.svelte' import { closeThreadInSidebarChannel } from '../navigation' @@ -36,12 +38,18 @@ let object: Doc | undefined = undefined let context: DocNotifyContext | undefined = undefined + let selectedMessageId: Ref | undefined = tab.data.selectedMessageId $: context = object ? $contextByDocStore.get(object._id) : undefined $: void loadObject(tab.data._id, tab.data._class) $: threadId = tab.data.thread + $: if (tab.data.selectedMessageId !== undefined && tab.data.selectedMessageId !== '') { + selectedMessageId = tab.data.selectedMessageId + updateTabData(widget._id, tab.id, { selectedMessageId: '' }) + } + async function loadObject (_id?: Ref, _class?: Ref>): Promise { if (_id === undefined || _class === undefined) { object = undefined @@ -80,13 +88,19 @@ on:close /> {#key object._id} - + {/key} {/if} {#if threadId}
- closeThreadInSidebarChannel(widget, tab)} on:close /> + closeThreadInSidebarChannel(widget, tab)} + on:close + />
{/if} diff --git a/plugins/chunter-resources/src/components/threads/ThreadContent.svelte b/plugins/chunter-resources/src/components/threads/ThreadContent.svelte new file mode 100644 index 0000000000..cb11b0bab6 --- /dev/null +++ b/plugins/chunter-resources/src/components/threads/ThreadContent.svelte @@ -0,0 +1,79 @@ + + +
+ {#if dataProvider !== undefined} + + +
+ +
+ + {#if (message.replies ?? $messagesStore?.length ?? 0) > 0} +
+
+
+
+
+ {/if} + + + {/if} +
+ + diff --git a/plugins/chunter-resources/src/components/threads/ThreadView.svelte b/plugins/chunter-resources/src/components/threads/ThreadView.svelte index 9a249b28de..f6c386e228 100644 --- a/plugins/chunter-resources/src/components/threads/ThreadView.svelte +++ b/plugins/chunter-resources/src/components/threads/ThreadView.svelte @@ -15,7 +15,7 @@ {#if showHeader} @@ -153,54 +141,10 @@ {/if} -
- {#if message && dataProvider !== undefined} - - -
- -
- - {#if (message.replies ?? $messagesStore?.length ?? 0) > 0} -
-
-
-
-
- {/if} - - - {/if} -
- - +{#if message} + {#key _id} + + {/key} +{:else if isLoading} + +{/if} diff --git a/plugins/chunter-resources/src/navigation.ts b/plugins/chunter-resources/src/navigation.ts index 6e9cf29e75..9281c98fa2 100644 --- a/plugins/chunter-resources/src/navigation.ts +++ b/plugins/chunter-resources/src/navigation.ts @@ -28,6 +28,7 @@ import { get } from 'svelte/store' import { chatSpecials } from './components/chat/utils' import { getChannelName, isThreadMessage } from './utils' import chunter from './plugin' +import { threadMessagesStore } from './stores' export function openChannel (_id: string, _class: Ref>, thread?: Ref): void { const loc = getCurrentLocation() @@ -168,6 +169,8 @@ export async function replyToThread (message: ActivityMessage, e: Event): Promis const fromSidebar = isElementFromSidebar(e.target as HTMLElement) const loc = getCurrentLocation() + threadMessagesStore.set(message) + if (fromSidebar) { const widget = getClient().getModel().findAllSync(workbench.class.Widget, { _id: chunter.ids.ChatWidget })[0] const widgetState = get(sidebarStore).widgetsState.get(widget._id) @@ -235,7 +238,8 @@ export async function openChannelInSidebar ( _class: Ref>, doc?: Doc, thread?: Ref, - newTab = true + newTab = true, + selectedMessageId?: Ref ): Promise { const client = getClient() @@ -267,6 +271,7 @@ export async function openChannelInSidebar ( _id, _class, thread, + selectedMessageId, channelName: name } } diff --git a/plugins/chunter-resources/src/stores.ts b/plugins/chunter-resources/src/stores.ts index 789c8a702d..03b1b787ad 100644 --- a/plugins/chunter-resources/src/stores.ts +++ b/plugins/chunter-resources/src/stores.ts @@ -17,11 +17,14 @@ import { writable } from 'svelte/store' import { type ChatMessage } from '@hcengineering/chunter' import { type Markup, type Ref } from '@hcengineering/core' import { languageStore } from '@hcengineering/ui' +import { type ActivityMessage } from '@hcengineering/activity' export const translatingMessagesStore = writable>>(new Set()) export const translatedMessagesStore = writable, Markup>>(new Map()) export const shownTranslatedMessagesStore = writable>>(new Set()) +export const threadMessagesStore = writable(undefined) + languageStore.subscribe(() => { translatedMessagesStore.set(new Map()) shownTranslatedMessagesStore.set(new Set()) diff --git a/plugins/chunter/src/index.ts b/plugins/chunter/src/index.ts index 3c814160b9..662ea1e23d 100644 --- a/plugins/chunter/src/index.ts +++ b/plugins/chunter/src/index.ts @@ -100,7 +100,13 @@ export interface InlineButton extends AttachedDoc { } export interface ChatWidgetTab extends WidgetTab { - data: { _id?: Ref, _class?: Ref>, thread?: Ref, channelName: string } + data: { + _id?: Ref + _class?: Ref> + thread?: Ref + channelName: string + selectedMessageId?: Ref + } } /** @@ -234,7 +240,14 @@ export default plugin(chunterId, { CanTranslateMessage: '' as Resource<(doc?: Doc | Doc[]) => Promise>, OpenThreadInSidebar: '' as Resource<(_id: Ref, msg?: ActivityMessage, doc?: Doc) => Promise>, OpenChannelInSidebar: '' as Resource< - (_id: Ref, _class: Ref, doc?: Doc, thread?: Ref) => Promise + ( + _id: Ref, + _class: Ref>, + doc?: Doc, + thread?: Ref, + newTab?: boolean, + selectedMessageId?: Ref + ) => Promise > } }) diff --git a/plugins/notification-resources/src/components/DocNotifyContextCard.svelte b/plugins/notification-resources/src/components/DocNotifyContextCard.svelte index d9c8b7ef75..206e845674 100644 --- a/plugins/notification-resources/src/components/DocNotifyContextCard.svelte +++ b/plugins/notification-resources/src/components/DocNotifyContextCard.svelte @@ -64,6 +64,7 @@ $: if (object !== undefined && object?._id !== value.objectId) { object = undefined + isLoading = true } let isActionMenuOpened = false diff --git a/plugins/notification-resources/src/components/Notification.svelte b/plugins/notification-resources/src/components/Notification.svelte index e76f6c5ae8..0fd5045cee 100644 --- a/plugins/notification-resources/src/components/Notification.svelte +++ b/plugins/notification-resources/src/components/Notification.svelte @@ -1,13 +1,14 @@ @@ -56,7 +77,7 @@