From 19573c2a3fde5792ec0b9d4cb7b86ef8037e5037 Mon Sep 17 00:00:00 2001 From: Kristina Fefelova Date: Thu, 6 Mar 2025 17:23:07 +0400 Subject: [PATCH] Fix threads Signed-off-by: Kristina Fefelova --- .../src/components/AttachmentDocList.svelte | 9 ++- plugins/attachment-resources/src/index.ts | 1 + plugins/attachment-resources/src/stores.ts | 42 ++++++++++++ plugins/chunter-assets/lang/cs.json | 3 +- plugins/chunter-assets/lang/de.json | 3 +- plugins/chunter-assets/lang/en.json | 3 +- plugins/chunter-assets/lang/es.json | 3 +- plugins/chunter-assets/lang/fr.json | 3 +- plugins/chunter-assets/lang/it.json | 3 +- plugins/chunter-assets/lang/pt.json | 3 +- plugins/chunter-assets/lang/ru.json | 3 +- plugins/chunter-assets/lang/zh.json | 3 +- .../src/components/chat/Chat.svelte | 3 +- .../chat/navigator/ChatSpecialElement.svelte | 2 +- .../chat/specials/SavedMessages.svelte | 61 ++++++++++------- .../src/components/chat/utils.ts | 25 ++----- .../src/components/threads/Threads.svelte | 65 ++++++++++++++++--- plugins/chunter-resources/src/plugin.ts | 3 +- 18 files changed, 170 insertions(+), 68 deletions(-) create mode 100644 plugins/attachment-resources/src/stores.ts diff --git a/plugins/attachment-resources/src/components/AttachmentDocList.svelte b/plugins/attachment-resources/src/components/AttachmentDocList.svelte index df9f02a267c..0c96686dc83 100644 --- a/plugins/attachment-resources/src/components/AttachmentDocList.svelte +++ b/plugins/attachment-resources/src/components/AttachmentDocList.svelte @@ -16,10 +16,12 @@ import { Attachment } from '@hcengineering/attachment' import { type Doc, type Ref, type WithLookup } from '@hcengineering/core' import { createQuery } from '@hcengineering/presentation' + import { onMount } from 'svelte' import attachment from '../plugin' import { AttachmentImageSize } from '../types' import AttachmentGroup from './AttachmentGroup.svelte' + import { loadSavedAttachments, savedAttachmentsStore } from '../stores' export let value: Doc & { attachments?: number } export let attachments: Attachment[] | undefined = undefined @@ -27,11 +29,12 @@ export let videoPreload = true const query = createQuery() - const savedAttachmentsQuery = createQuery() let savedAttachmentsIds: Ref[] = [] let resAttachments: WithLookup[] = [] + $: savedAttachmentsIds = $savedAttachmentsStore.map((it) => it.attachedTo) + $: updateQuery(value, attachments) function updateQuery (value: Doc & { attachments?: number }, attachments?: Attachment[]): void { @@ -57,8 +60,8 @@ } } - savedAttachmentsQuery.query(attachment.class.SavedAttachments, {}, (res) => { - savedAttachmentsIds = res.map(({ attachedTo }) => attachedTo) + onMount(() => { + loadSavedAttachments() }) diff --git a/plugins/attachment-resources/src/index.ts b/plugins/attachment-resources/src/index.ts index eecca099903..3d39bdac1f9 100644 --- a/plugins/attachment-resources/src/index.ts +++ b/plugins/attachment-resources/src/index.ts @@ -46,6 +46,7 @@ import PreviewPopupActions from './components/PreviewPopupActions.svelte' import DrawingPresenter from './components/DrawingPresenter.svelte' export * from './types' +export * from './stores' export { AccordionEditor, diff --git a/plugins/attachment-resources/src/stores.ts b/plugins/attachment-resources/src/stores.ts new file mode 100644 index 00000000000..71e923e387f --- /dev/null +++ b/plugins/attachment-resources/src/stores.ts @@ -0,0 +1,42 @@ +// +// Copyright © 2025 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import { get, writable } from 'svelte/store' +import core, { SortingOrder, type WithLookup } from '@hcengineering/core' +import attachment, { type SavedAttachments } from '@hcengineering/attachment' +import { createQuery, onClient } from '@hcengineering/presentation' + +export const savedAttachmentsStore = writable>>([]) +export const isSavedAttachmentsLoaded = writable(false) + +const savedAttachmentsQuery = createQuery(true) + +export function loadSavedAttachments (): void { + if (get(isSavedAttachmentsLoaded)) { + return + } + + onClient(() => { + savedAttachmentsQuery.query( + attachment.class.SavedAttachments, + { space: core.space.Workspace }, + (res) => { + isSavedAttachmentsLoaded.set(true) + savedAttachmentsStore.set(res.filter(({ $lookup }) => $lookup?.attachedTo !== undefined)) + }, + { lookup: { attachedTo: attachment.class.Attachment }, sort: { modifiedOn: SortingOrder.Descending } } + ) + }) +} diff --git a/plugins/chunter-assets/lang/cs.json b/plugins/chunter-assets/lang/cs.json index 5750b42a255..990b31668fc 100644 --- a/plugins/chunter-assets/lang/cs.json +++ b/plugins/chunter-assets/lang/cs.json @@ -130,6 +130,7 @@ "StartConversation": "Začít konverzaci", "ViewingThreadFromArchivedChannel": "Prohlížíte vlákno z archivovaného kanálu", "ViewingArchivedChannel": "Prohlížíte archivovaný kanál", - "OpenChatInSidebar": "Otevřít chat v postranním panelu" + "OpenChatInSidebar": "Otevřít chat v postranním panelu", + "NoThreadsYet": "Zatím nejsou žádné vlákna." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/de.json b/plugins/chunter-assets/lang/de.json index eb06efed05b..d05bf5fb573 100644 --- a/plugins/chunter-assets/lang/de.json +++ b/plugins/chunter-assets/lang/de.json @@ -131,6 +131,7 @@ "ViewingThreadFromArchivedChannel": "Sie sehen einen Thread aus einem archivierten Kanal", "ViewingArchivedChannel": "Sie sehen einen archivierten Kanal", "OpenChatInSidebar": "Chat in Seitenleiste öffnen", - "ResolveThread": "Thread abschließen" + "ResolveThread": "Thread abschließen", + "NoThreadsYet": "Es gibt noch keine Threads." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/en.json b/plugins/chunter-assets/lang/en.json index 0db3ce58bc4..e0e8c4161e5 100644 --- a/plugins/chunter-assets/lang/en.json +++ b/plugins/chunter-assets/lang/en.json @@ -131,6 +131,7 @@ "ViewingThreadFromArchivedChannel": "You are viewing a thread from an archived channel", "ViewingArchivedChannel": "You are viewing an archived channel", "OpenChatInSidebar": "Open chat in sidebar", - "ResolveThread": "Resolve" + "ResolveThread": "Resolve", + "NoThreadsYet": "There are no threads yet." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/es.json b/plugins/chunter-assets/lang/es.json index fd888637ab2..35a29796f12 100644 --- a/plugins/chunter-assets/lang/es.json +++ b/plugins/chunter-assets/lang/es.json @@ -130,6 +130,7 @@ "StartConversation": "Iniciar conversación", "ViewingThreadFromArchivedChannel": "Estás viendo un hilo de un canal archivado", "ViewingArchivedChannel": "Estás viendo un canal archivado", - "OpenChatInSidebar": "Abrir chat en la barra lateral" + "OpenChatInSidebar": "Abrir chat en la barra lateral", + "NoThreadsYet": "No hay hilos todavía." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/fr.json b/plugins/chunter-assets/lang/fr.json index 4222e03c886..415d5552479 100644 --- a/plugins/chunter-assets/lang/fr.json +++ b/plugins/chunter-assets/lang/fr.json @@ -130,6 +130,7 @@ "StartConversation": "Démarrer la conversation", "ViewingThreadFromArchivedChannel": "Vous consultez un fil de discussion d'un canal archivé", "ViewingArchivedChannel": "Vous consultez un canal archivé", - "OpenChatInSidebar": "Ouvrir le chat dans la barre latérale" + "OpenChatInSidebar": "Ouvrir le chat dans la barre latérale", + "NoThreadsYet": "Il n'y a pas encore de fils de discussion." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/it.json b/plugins/chunter-assets/lang/it.json index 6305fa0835d..633a2fac1f5 100644 --- a/plugins/chunter-assets/lang/it.json +++ b/plugins/chunter-assets/lang/it.json @@ -130,6 +130,7 @@ "StartConversation": "Inizia conversazione", "ViewingThreadFromArchivedChannel": "Stai visualizzando una discussione da un canale archiviato", "ViewingArchivedChannel": "Stai visualizzando un canale archiviato", - "OpenChatInSidebar": "Apri chat nella barra laterale" + "OpenChatInSidebar": "Apri chat nella barra laterale", + "NoThreadsYet": "Non ci sono ancora discussioni." } } diff --git a/plugins/chunter-assets/lang/pt.json b/plugins/chunter-assets/lang/pt.json index b4855bb67de..0abbb3c33c1 100644 --- a/plugins/chunter-assets/lang/pt.json +++ b/plugins/chunter-assets/lang/pt.json @@ -130,6 +130,7 @@ "StartConversation": "Iniciar conversa", "ViewingThreadFromArchivedChannel": "Está a visualizar uma conversa em cadeia de um canal arquivado", "ViewingArchivedChannel": "Está a visualizar um canal arquivado", - "OpenChatInSidebar": "Abrir chat na barra lateral" + "OpenChatInSidebar": "Abrir chat na barra lateral", + "NoThreadsYet": "Não há conversas ainda." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/ru.json b/plugins/chunter-assets/lang/ru.json index 2194eda855b..c7849904d63 100644 --- a/plugins/chunter-assets/lang/ru.json +++ b/plugins/chunter-assets/lang/ru.json @@ -131,6 +131,7 @@ "ViewingThreadFromArchivedChannel": "Вы просматриваете обсуждение из архивированного канала", "ViewingArchivedChannel": "Вы просматриваете архивированный канал", "OpenChatInSidebar": "Открыть чат в боковой панели", - "ResolveThread": "Пометить завершенным" + "ResolveThread": "Пометить завершенным", + "NoThreadsYet": "Пока нет обсуждений." } } \ No newline at end of file diff --git a/plugins/chunter-assets/lang/zh.json b/plugins/chunter-assets/lang/zh.json index 9a1d7fa3116..596ee9773da 100644 --- a/plugins/chunter-assets/lang/zh.json +++ b/plugins/chunter-assets/lang/zh.json @@ -130,6 +130,7 @@ "StartConversation": "开始对话", "ViewingThreadFromArchivedChannel": "你正在查看已归档频道的线程", "ViewingArchivedChannel": "你正在查看已归档频道", - "OpenChatInSidebar": "在侧边栏中打开聊天" + "OpenChatInSidebar": "在侧边栏中打开聊天", + "NoThreadsYet": "还没有线程。" } } diff --git a/plugins/chunter-resources/src/components/chat/Chat.svelte b/plugins/chunter-resources/src/components/chat/Chat.svelte index 428702d2ff3..b0e16f10c64 100644 --- a/plugins/chunter-resources/src/components/chat/Chat.svelte +++ b/plugins/chunter-resources/src/components/chat/Chat.svelte @@ -33,10 +33,11 @@ import view, { decodeObjectURI } from '@hcengineering/view' import { parseLinkId, getObjectLinkId } from '@hcengineering/view-resources' import { ActivityMessage } from '@hcengineering/activity' + import { loadSavedAttachments } from '@hcengineering/attachment-resources' import ChatNavigator from './navigator/ChatNavigator.svelte' import ChannelView from '../ChannelView.svelte' - import { chatSpecials, loadSavedAttachments } from './utils' + import { chatSpecials } from './utils' import { SelectChannelEvent } from './types' import { openChannel, openThreadInSidebar } from '../../navigation' diff --git a/plugins/chunter-resources/src/components/chat/navigator/ChatSpecialElement.svelte b/plugins/chunter-resources/src/components/chat/navigator/ChatSpecialElement.svelte index 1deea5c9852..b7b12bc5b2a 100644 --- a/plugins/chunter-resources/src/components/chat/navigator/ChatSpecialElement.svelte +++ b/plugins/chunter-resources/src/components/chat/navigator/ChatSpecialElement.svelte @@ -22,9 +22,9 @@ import { SavedAttachments } from '@hcengineering/attachment' import { SavedMessage } from '@hcengineering/activity' import { savedMessagesStore } from '@hcengineering/activity-resources' + import { savedAttachmentsStore } from '@hcengineering/attachment-resources' import NavItem from './NavItem.svelte' - import { savedAttachmentsStore } from '../utils' export let special: SpecialNavModel export let currentSpecial: SpecialNavModel | undefined = undefined diff --git a/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte b/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte index d1855f0b593..c16b16bed37 100644 --- a/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte +++ b/plugins/chunter-resources/src/components/chat/specials/SavedMessages.svelte @@ -14,17 +14,16 @@ -->
- - {#if savedMessages.length > 0 || savedAttachments.length > 0} + + {#if !isEmpty} {#each savedMessages as message} {#if message.$lookup?.attachedTo} - - - - { - handleMessageClicked(message.$lookup?.attachedTo) - }} - /> +
+ + + + { + handleMessageClicked(message.$lookup?.attachedTo) + }} + /> + +
{/if} {/each} {#each savedAttachments as attach} @@ -92,16 +96,18 @@ class="attachmentContainer flex-no-shrink clear-mins" on:click={() => openAttachment(attach.$lookup?.attachedTo)} > - -
-
+ + +
+
+
{/if} {/each} @@ -119,6 +125,7 @@ cursor: pointer; padding: 2rem; border-radius: 0.25rem; + min-height: 3.75rem; &:hover { background-color: var(--global-ui-BackgroundColor); @@ -128,4 +135,10 @@ padding-top: 1rem; } } + + .message-container { + display: flex; + flex-direction: column; + min-height: 3.75rem; + } diff --git a/plugins/chunter-resources/src/components/chat/utils.ts b/plugins/chunter-resources/src/components/chat/utils.ts index f843631f72f..119a69c5a26 100644 --- a/plugins/chunter-resources/src/components/chat/utils.ts +++ b/plugins/chunter-resources/src/components/chat/utils.ts @@ -12,23 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. // -import attachment, { type SavedAttachments } from '@hcengineering/attachment' + import { type DirectMessage } from '@hcengineering/chunter' import contact, { type PersonAccount } from '@hcengineering/contact' -import core, { +import { type Account, AccountRole, getCurrentAccount, hasAccountRole, type IdMap, type Ref, - SortingOrder, - type UserStatus, - type WithLookup + type UserStatus } from '@hcengineering/core' import notification, { type DocNotifyContext } from '@hcengineering/notification' import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources' -import { createQuery, getClient, MessageBox, onClient } from '@hcengineering/presentation' +import { getClient, MessageBox } from '@hcengineering/presentation' import { type Action, showPopup } from '@hcengineering/ui' import view from '@hcengineering/view' import workbench, { type SpecialNavModel } from '@hcengineering/workbench' @@ -43,7 +41,6 @@ interface NavigatorState { collapsedSections: string[] } -export const savedAttachmentsStore = writable>>([]) export const navigatorStateStore = writable(restoreNavigatorState()) function restoreNavigatorState (): NavigatorState { @@ -364,20 +361,6 @@ function archiveActivityChannels (contexts: DocNotifyContext[]): void { ) } -const savedAttachmentsQuery = createQuery(true) -export function loadSavedAttachments (): void { - onClient(() => { - savedAttachmentsQuery.query( - attachment.class.SavedAttachments, - { space: core.space.Workspace }, - (res) => { - savedAttachmentsStore.set(res.filter(({ $lookup }) => $lookup?.attachedTo !== undefined)) - }, - { lookup: { attachedTo: attachment.class.Attachment }, sort: { modifiedOn: SortingOrder.Descending } } - ) - }) -} - export async function hideActivityChannels (contexts: DocNotifyContext[]): Promise { const ops = getClient().apply(undefined, 'hideActivityChannels') diff --git a/plugins/chunter-resources/src/components/threads/Threads.svelte b/plugins/chunter-resources/src/components/threads/Threads.svelte index 3e3a0cc68c9..cfc7ed374c7 100644 --- a/plugins/chunter-resources/src/components/threads/Threads.svelte +++ b/plugins/chunter-resources/src/components/threads/Threads.svelte @@ -15,7 +15,7 @@
- - {#each threads as thread} - openMessageFromSpecial(thread)} withShowMore={false} /> - {/each} + 0} onScroll={handleScroll}> + {#if isLoading} + + {:else if threads.length === 0} + + {:else} + {#each threads as thread} +
+ + openMessageFromSpecial(thread)} + withShowMore={false} + /> + +
+ {/each} + {#if hasNextPage} + + {/if} + {/if}
+ + diff --git a/plugins/chunter-resources/src/plugin.ts b/plugins/chunter-resources/src/plugin.ts index d2f93c3bdd2..d8c184ca873 100644 --- a/plugins/chunter-resources/src/plugin.ts +++ b/plugins/chunter-resources/src/plugin.ts @@ -109,6 +109,7 @@ export default mergeIds(chunterId, chunter, { JoinChannelHeader: '' as IntlString, JoinChannelText: '' as IntlString, LatestMessages: '' as IntlString, - ResolveThread: '' as IntlString + ResolveThread: '' as IntlString, + NoThreadsYet: '' as IntlString } })