diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 8ef9f4fc00..42b1e4728c 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -960,6 +960,10 @@ export class LiveQuery implements WithTx, Client { result: LookupData ): Promise { for (const key in lookup._id) { + if ((doc as any)[key] === undefined || (doc as any)[key] === 0) { + continue + } + const value = lookup._id[key] let _class: Ref> diff --git a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte index 817ec9ed83..6612fbd8a6 100644 --- a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte +++ b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte @@ -50,6 +50,7 @@ export let placeholder: IntlString | undefined = undefined export let extraActions: RefAction[] = [] export let boundary: HTMLElement | undefined = undefined + export let skipAttachmentsPreload = false let refInput: ReferenceInput @@ -72,9 +73,30 @@ let refContainer: HTMLElement + const existingAttachmentsQuery = createQuery() + let existingAttachments: Ref[] = [] + + $: if (Array.from(attachments.keys()).length > 0) { + existingAttachmentsQuery.query( + attachment.class.Attachment, + { + space, + attachedTo: objectId, + attachedToClass: _class, + _id: { $in: Array.from(attachments.keys()) } + }, + (res) => { + existingAttachments = res.map((p) => p._id) + } + ) + } else { + existingAttachments = [] + existingAttachmentsQuery.unsubscribe() + } + $: objectId && updateAttachments(objectId) - async function updateAttachments (objectId: Ref) { + async function updateAttachments (objectId: Ref): Promise { draftAttachments = $draftsStore[draftKey] if (draftAttachments && shouldSaveDraft) { attachments.clear() @@ -87,7 +109,8 @@ }) originalAttachments.clear() removedAttachments.clear() - } else { + query.unsubscribe() + } else if (!skipAttachmentsPreload) { query.query( attachment.class.Attachment, { @@ -103,17 +126,23 @@ } } ) + } else { + attachments.clear() + newAttachments.clear() + originalAttachments.clear() + removedAttachments.clear() + query.unsubscribe() } } - async function saveDraft () { + function saveDraft (): void { if (shouldSaveDraft) { draftAttachments = Object.fromEntries(attachments) draftController.save(draftAttachments) } } - async function createAttachment (file: File) { + async function createAttachment (file: File): Promise { try { const uuid = await uploadFile(file) const metadata = await getFileMetadata(file, uuid) @@ -137,27 +166,13 @@ }) newAttachments.add(_id) attachments = attachments + dispatch('update', { message: content, attachments: attachments.size }) saveDraft() } catch (err: any) { - setPlatformStatus(unknownError(err)) + void setPlatformStatus(unknownError(err)) } } - const existingAttachmentsQuery = createQuery() - let existingAttachments: Ref[] = [] - $: existingAttachmentsQuery.query( - attachment.class.Attachment, - { - space, - attachedTo: objectId, - attachedToClass: _class, - _id: { $in: Array.from(attachments.keys()) } - }, - (res) => { - existingAttachments = res.map((p) => p._id) - } - ) - async function saveAttachment (doc: Attachment): Promise { if (!existingAttachments.includes(doc._id)) { await client.addCollection(attachment.class.Attachment, space, objectId, _class, 'attachments', doc, doc._id) @@ -199,6 +214,7 @@ await createAttachments() } attachments = attachments + dispatch('update', { message: content, attachments: attachments.size }) saveDraft() } @@ -231,7 +247,7 @@ } }) - export function removeDraft (removeFiles: boolean) { + export function removeDraft (removeFiles: boolean): void { draftController.remove() if (removeFiles) { newAttachments.forEach((p) => { @@ -258,14 +274,14 @@ return Promise.all(promises).then() } - async function onMessage (event: CustomEvent) { + async function onMessage (event: CustomEvent): Promise { loading = true await createAttachments() loading = false dispatch('message', { message: event.detail, attachments: attachments.size }) } - async function onUpdate (event: CustomEvent) { + function onUpdate (event: CustomEvent): void { dispatch('update', { message: event.detail, attachments: attachments.size }) } @@ -326,7 +342,7 @@
- {#if attachments.size || progress} + {#if attachments.size > 0 || progress}
{#if progress}
@@ -371,7 +387,7 @@ value={attachment} removable on:remove={(result) => { - if (result !== undefined) removeAttachment(attachment) + if (result !== undefined) void removeAttachment(attachment) }} />
diff --git a/plugins/chunter-resources/src/channelDataProvider.ts b/plugins/chunter-resources/src/channelDataProvider.ts index b86b228112..f7ebbb60c1 100644 --- a/plugins/chunter-resources/src/channelDataProvider.ts +++ b/plugins/chunter-resources/src/channelDataProvider.ts @@ -131,8 +131,10 @@ export class ChannelDataProvider implements IChannelDataProvider { const metadata = get(this.metadataStore) if (mode === 'forward') { + const isTailLoading = get(this.isTailLoading) + const tail = get(this.tailStore) const last = metadata[metadata.length - 1]?.createdOn ?? 0 - return last > timestamp + return last > timestamp && !isTailLoading && tail.length === 0 } else { const first = metadata[0]?.createdOn ?? 0 return first < timestamp diff --git a/plugins/chunter-resources/src/components/ChannelScrollView.svelte b/plugins/chunter-resources/src/components/ChannelScrollView.svelte index 5eafc2925b..30ca4136e3 100644 --- a/plugins/chunter-resources/src/components/ChannelScrollView.svelte +++ b/plugins/chunter-resources/src/components/ChannelScrollView.svelte @@ -29,11 +29,17 @@ } from '@hcengineering/activity-resources' import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources' import { get } from 'svelte/store' - import { tick, beforeUpdate, afterUpdate } from 'svelte' + import { tick, beforeUpdate, afterUpdate, onMount, onDestroy } from 'svelte' import { getResource } from '@hcengineering/platform' import ActivityMessagesSeparator from './ChannelMessagesSeparator.svelte' - import { filterChatMessages, getClosestDate, readChannelMessages } from '../utils' + import { + filterChatMessages, + getClosestDate, + readChannelMessages, + chatReadMessagesStore, + recheckNotifications + } from '../utils' import HistoryLoading from './LoadingHistory.svelte' import { ChannelDataProvider, MessageMetadata } from '../channelDataProvider' import JumpToDateSelector from './JumpToDateSelector.svelte' @@ -113,8 +119,11 @@ $: displayMessages = filterChatMessages(messages, filters, filterResources, objectClass, selectedFilters) - inboxClient.inboxNotificationsByContext.subscribe(() => { - readViewportMessages() + const unsubscribe = inboxClient.inboxNotificationsByContext.subscribe(() => { + if (notifyContext !== undefined) { + recheckNotifications(notifyContext) + readViewportMessages() + } }) function scrollToBottom (afterScrollFn?: () => void): void { @@ -589,6 +598,14 @@ return canGroupMessages(message, prevMessage ?? prevMetadata) } + + onMount(() => { + chatReadMessagesStore.update(() => new Set()) + }) + + onDestroy(() => { + unsubscribe() + }) {#if isLoading} @@ -635,22 +652,20 @@ {/if} -
- -
+ {/each} {#if loadMoreAllowed && provider.canLoadMore('forward', messages[messages.length - 1]?.createdOn)} @@ -670,14 +685,6 @@ {/if}