From e202027d2bb0ea58f93fc29104644449b1ae9f2c Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 23 Apr 2024 19:44:49 +0400 Subject: [PATCH] Add chat fixes (#5437) Signed-off-by: Kristina Fefelova --- .../src/components/ReferenceInput.svelte | 3 +- .../src/components/ChannelScrollView.svelte | 65 +++++++++---------- server-plugins/chunter-resources/src/index.ts | 14 ++-- .../notification-resources/src/index.ts | 34 ++++++---- 4 files changed, 60 insertions(+), 56 deletions(-) diff --git a/packages/text-editor/src/components/ReferenceInput.svelte b/packages/text-editor/src/components/ReferenceInput.svelte index 41cd8969ab..5904b418ad 100644 --- a/packages/text-editor/src/components/ReferenceInput.svelte +++ b/packages/text-editor/src/components/ReferenceInput.svelte @@ -64,7 +64,8 @@ $: devSize = $deviceInfo.size $: shrinkButtons = checkAdaptiveMatching(devSize, 'sm') - $: canSubmit = (!isEmpty || haveAttachment) && !isEmptyMarkup(content) && !loading + $: isEmptyContent = isEmpty || isEmptyMarkup(content) + $: canSubmit = (haveAttachment || !isEmptyContent) && !loading function setContent (content: Markup): void { textEditor?.setContent(content) diff --git a/plugins/chunter-resources/src/components/ChannelScrollView.svelte b/plugins/chunter-resources/src/components/ChannelScrollView.svelte index ef7fa0d181..02a5927cf6 100644 --- a/plugins/chunter-resources/src/components/ChannelScrollView.svelte +++ b/plugins/chunter-resources/src/components/ChannelScrollView.svelte @@ -164,13 +164,13 @@ readViewportMessages() } - function isDateRendered (date: Timestamp) { + function isDateRendered (date: Timestamp): boolean { const day = getDay(date) return document.getElementById(day.toString()) != null } - async function jumpToDate (e: CustomEvent) { + function jumpToDate (e: CustomEvent): void { const date = e.detail.date if (!date || !scrollElement) { @@ -191,7 +191,7 @@ } } - function scrollToDate (date: Timestamp) { + function scrollToDate (date: Timestamp): void { autoscroll = false dateToJump = undefined shouldWaitAndRead = false @@ -210,7 +210,7 @@ scroller?.scroll(offset) } - function updateShouldScrollToNew () { + function updateShouldScrollToNew (): void { if (scrollElement) { const { offsetHeight, scrollHeight, scrollTop } = scrollElement const offset = 100 @@ -219,7 +219,7 @@ } } - function shouldLoadMoreUp () { + function shouldLoadMoreUp (): boolean { if (!scrollElement) { return false } @@ -227,7 +227,7 @@ return scrollElement.scrollTop === 0 } - function shouldLoadMoreDown () { + function shouldLoadMoreDown (): boolean { if (!scrollElement) { return false } @@ -239,7 +239,7 @@ let scrollToRestore = 0 - function loadMore () { + function loadMore (): void { if (!loadMoreAllowed || $isLoadingMoreStore || !scrollElement || isInitialScrolling) { return } @@ -259,7 +259,7 @@ } } - function handleScroll ({ autoScrolling }: ScrollParams) { + function handleScroll ({ autoScrolling }: ScrollParams): void { saveScrollPosition() if (autoScrolling) { return @@ -302,7 +302,7 @@ return messageRect.top >= containerRect.top && messageRect.bottom - messageRect.height / 2 <= containerRect.bottom } - function readViewportMessages () { + function readViewportMessages (): void { if (!scrollElement || !scrollContentBox) { return } @@ -327,7 +327,7 @@ void readChannelMessages(messagesToRead, notifyContext) } - function updateSelectedDate () { + function updateSelectedDate (): void { if (!withDates) { return } @@ -446,33 +446,16 @@ } } - let scrollToLastMessage = false - - function scrollUntilSeeLastMessage () { - if (isLastMessageViewed()) { - readViewportMessages() - shouldScrollToNew = true - scrollToLastMessage = false - } else if (scrollToLastMessage && shouldScrollToNew) { - setTimeout(() => { - scrollToBottom(scrollUntilSeeLastMessage) - }, 50) - } else { - scrollToLastMessage = false - } - } - - function scrollToNewMessages () { + function scrollToNewMessages (): void { if (!scrollElement || !shouldScrollToNew) { return } - scrollToLastMessage = true scrollToBottom() - scrollUntilSeeLastMessage() + readViewportMessages() } - async function wait () { + async function wait (): Promise { // One tick is not enough for messages to be rendered, // I think this is due to the fact that we are using a Component, which takes some time to load, // because after one tick I see spinners from Component @@ -498,7 +481,7 @@ shouldWaitAndRead = false } - async function handleMessagesUpdated (newCount: number) { + async function handleMessagesUpdated (newCount: number): Promise { if (newCount === messagesCount) { return } @@ -516,11 +499,17 @@ messagesCount = newCount } - $: handleMessagesUpdated(displayMessages.length) - function handleResize () { - if (!isInitialScrolling && isScrollInitialized) { - loadMore() + $: void handleMessagesUpdated(displayMessages.length) + function handleResize (): void { + if (isInitialScrolling || !isScrollInitialized) { + return } + + if (shouldScrollToNew) { + scrollToBottom() + } + + loadMore() } let prevScrollHeight = 0 @@ -632,7 +621,11 @@ {#if object}
- +
{/if} {/if} diff --git a/server-plugins/chunter-resources/src/index.ts b/server-plugins/chunter-resources/src/index.ts index 5704fdde88..1a28744f15 100644 --- a/server-plugins/chunter-resources/src/index.ts +++ b/server-plugins/chunter-resources/src/index.ts @@ -145,18 +145,16 @@ async function OnThreadMessageCreated (tx: Tx, control: TriggerControl): Promise async function OnChatMessageCreated (tx: TxCUD, control: TriggerControl): Promise { const hierarchy = control.hierarchy - const actualTx = TxProcessor.extractTx(tx) + const actualTx = TxProcessor.extractTx(tx) as TxCreateDoc - if (actualTx._class !== core.class.TxCreateDoc) { - return [] - } - - const chatMessage = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc) - - if (!hierarchy.isDerived(chatMessage._class, chunter.class.ChatMessage)) { + if ( + actualTx._class !== core.class.TxCreateDoc || + !hierarchy.isDerived(actualTx.objectClass, chunter.class.ChatMessage) + ) { return [] } + const chatMessage = TxProcessor.createDoc2Doc(actualTx) const mixin = hierarchy.classHierarchyMixin(chatMessage.attachedToClass, notification.mixin.ClassCollaborators) if (mixin === undefined) { diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index bbe3b21fbe..b51a587989 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -1235,9 +1235,13 @@ async function OnActivityNotificationViewed ( } const inboxNotification = ( - await control.findAll(notification.class.ActivityInboxNotification, { - _id: tx.objectId as Ref - }) + await control.findAll( + notification.class.ActivityInboxNotification, + { + _id: tx.objectId as Ref + }, + { projection: { _id: 1, attachedTo: 1, user: 1 } } + ) )[0] if (inboxNotification === undefined) { @@ -1247,19 +1251,27 @@ async function OnActivityNotificationViewed ( // Read reactions notifications when message is read const { attachedTo, user } = inboxNotification - const reactionMessages = await control.findAll(activity.class.DocUpdateMessage, { - attachedTo, - objectClass: activity.class.Reaction - }) + const reactionMessages = await control.findAll( + activity.class.DocUpdateMessage, + { + attachedTo, + objectClass: activity.class.Reaction + }, + { projection: { _id: 1 } } + ) if (reactionMessages.length === 0) { return [] } - const reactionNotifications = await control.findAll(notification.class.ActivityInboxNotification, { - attachedTo: { $in: reactionMessages.map(({ _id }) => _id) }, - user - }) + const reactionNotifications = await control.findAll( + notification.class.ActivityInboxNotification, + { + attachedTo: { $in: reactionMessages.map(({ _id }) => _id) }, + user + }, + { projection: { _id: 1, _class: 1, space: 1 } } + ) return reactionNotifications.map(({ _id, _class, space }) => control.txFactory.createTxUpdateDoc(_class, space, _id, { isViewed: true })