From b14cc900390fa4744874217c1fdf50df64ab1ae2 Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 10 Jul 2024 19:27:44 +0400 Subject: [PATCH] Chat UI fixes (#6046) Signed-off-by: Kristina Fefelova --- models/notification/src/index.ts | 13 ++++- .../src/components/ReferenceInput.svelte | 2 + .../src/channelDataProvider.ts | 48 +++++++++++++++---- .../src/components/Channel.svelte | 22 ++++----- .../notification-resources/src/index.ts | 9 +--- .../notification-resources/src/utils.ts | 2 +- 6 files changed, 63 insertions(+), 33 deletions(-) diff --git a/models/notification/src/index.ts b/models/notification/src/index.ts index 721d0ce1e9..5fd732b970 100644 --- a/models/notification/src/index.ts +++ b/models/notification/src/index.ts @@ -645,8 +645,17 @@ export function createModel (builder: Builder): void { indexes: [] } ) - builder.mixin, IndexingConfiguration>( - notification.class.ActivityInboxNotification, + builder.mixin, IndexingConfiguration>( + notification.class.InboxNotification, + core.class.Class, + core.mixin.IndexConfiguration, + { + searchDisabled: true, + indexes: [] + } + ) + builder.mixin, IndexingConfiguration>( + notification.class.BrowserNotification, core.class.Class, core.mixin.IndexConfiguration, { diff --git a/packages/text-editor/src/components/ReferenceInput.svelte b/packages/text-editor/src/components/ReferenceInput.svelte index 8f8bee4711..442bb0f3ff 100644 --- a/packages/text-editor/src/components/ReferenceInput.svelte +++ b/packages/text-editor/src/components/ReferenceInput.svelte @@ -254,6 +254,8 @@ } .text-input { + max-height: 18.75rem; + overflow: auto; min-height: 2.75rem; padding: 0.125rem 0.75rem; } diff --git a/plugins/chunter-resources/src/channelDataProvider.ts b/plugins/chunter-resources/src/channelDataProvider.ts index 8eb7f71baf..11235b8057 100644 --- a/plugins/chunter-resources/src/channelDataProvider.ts +++ b/plugins/chunter-resources/src/channelDataProvider.ts @@ -32,6 +32,7 @@ import { combineActivityMessages } from '@hcengineering/activity-resources' import chunter from './plugin' import { type ChatMessage } from '@hcengineering/chunter' +import notification, { type DocNotifyContext, type InboxNotification } from '@hcengineering/notification' export type LoadMode = 'forward' | 'backward' @@ -71,7 +72,7 @@ export class ChannelDataProvider implements IChannelDataProvider { private readonly tailQuery = createQuery(true) private chatId: Ref | undefined = undefined - private readonly lastViewedTimestamp: Timestamp | undefined = undefined + private readonly context: DocNotifyContext | undefined = undefined private readonly msgClass: Ref> private selectedMsgId: Ref | undefined = undefined private tailStart: Timestamp | undefined = undefined @@ -101,15 +102,15 @@ export class ChannelDataProvider implements IChannelDataProvider { constructor ( chatId: Ref, _class: Ref>, - lastViewedTimestamp?: Timestamp, + context: DocNotifyContext | undefined, selectedMsgId?: Ref, loadAll = false ) { this.chatId = chatId - this.lastViewedTimestamp = lastViewedTimestamp + this.context = context this.msgClass = _class this.selectedMsgId = selectedMsgId - this.loadData(loadAll) + void this.loadData(loadAll) } public destroy (): void { @@ -154,7 +155,7 @@ export class ChannelDataProvider implements IChannelDataProvider { this.selectedMsgId = undefined } - private loadData (loadAll = false): void { + private async loadData (loadAll = false): Promise { if (this.chatId === undefined) { return } @@ -182,10 +183,25 @@ export class ChannelDataProvider implements IChannelDataProvider { return } + const client = getClient() this.isInitialLoadingStore.set(true) + const firstNotification = + this.context !== undefined + ? await client.findOne( + notification.class.InboxNotification, + { + _class: { + $in: [notification.class.MentionInboxNotification, notification.class.ActivityInboxNotification] + }, + docNotifyContext: this.context._id, + isViewed: false + }, + { sort: { createdOn: SortingOrder.Ascending } } + ) + : undefined const metadata = get(this.metadataStore) - const firstNewMsgIndex = this.getFirstNewMsgIndex(this.lastViewedTimestamp) + const firstNewMsgIndex = this.getFirstNewMsgIndex(firstNotification) if (get(this.newTimestampStore) === undefined) { this.newTimestampStore.set(firstNewMsgIndex !== undefined ? metadata[firstNewMsgIndex]?.createdOn : undefined) @@ -335,19 +351,33 @@ export class ChannelDataProvider implements IChannelDataProvider { return firsNewMsgIndex } - private getFirstNewMsgIndex (lastViewedTimestamp?: Timestamp): number | undefined { + private getFirstNewMsgIndex (firstNotification: InboxNotification | undefined): number | undefined { const metadata = get(this.metadataStore) if (metadata.length === 0) { return undefined } - if (lastViewedTimestamp === undefined) { + if (this.context === undefined) { + return -1 + } + + const lastViewedTimestamp = this.context.lastViewedTimestamp + + if (lastViewedTimestamp === undefined && firstNotification === undefined) { return -1 } const me = getCurrentAccount()._id + let newTimestamp = 0 + + if (lastViewedTimestamp !== undefined && firstNotification !== undefined) { + newTimestamp = Math.min(lastViewedTimestamp ?? 0, firstNotification?.createdOn ?? 0) + } else { + newTimestamp = lastViewedTimestamp ?? firstNotification?.createdOn ?? 0 + } + return metadata.findIndex((message) => { if (message.createdBy === me) { return false @@ -355,7 +385,7 @@ export class ChannelDataProvider implements IChannelDataProvider { const createdOn = message.createdOn ?? 0 - return lastViewedTimestamp < createdOn + return newTimestamp < createdOn }) } diff --git a/plugins/chunter-resources/src/components/Channel.svelte b/plugins/chunter-resources/src/components/Channel.svelte index 813e2444f7..5b8cbfe43b 100644 --- a/plugins/chunter-resources/src/components/Channel.svelte +++ b/plugins/chunter-resources/src/components/Channel.svelte @@ -13,7 +13,7 @@ // limitations under the License. --> diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index 34d6b38702..126b5b6e7a 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -15,7 +15,6 @@ // import activity, { ActivityMessage, DocUpdateMessage } from '@hcengineering/activity' -import { Analytics } from '@hcengineering/analytics' import chunter, { ChatMessage } from '@hcengineering/chunter' import contact, { type AvatarInfo, @@ -467,12 +466,6 @@ async function activityInboxNotificationToText (doc: Data { if (m1.has(it._id)) { return [account.email] diff --git a/server-plugins/notification-resources/src/utils.ts b/server-plugins/notification-resources/src/utils.ts index f7cb2e3239..a0df71f569 100644 --- a/server-plugins/notification-resources/src/utils.ts +++ b/server-plugins/notification-resources/src/utils.ts @@ -414,7 +414,7 @@ export async function getNotificationContent ( export async function getUsersInfo (ids: Ref[], control: TriggerControl): Promise { const accounts = await control.modelDb.findAll(contact.class.PersonAccount, { _id: { $in: ids } }) - const persons = await control.findAll(contact.class.Person, { _id: { $in: accounts.map(({ person }) => person) } }) + const persons = await control.queryFind(contact.class.Person, {}) return accounts.map((account) => ({ _id: account._id,