From 57ee6f5f498be6da08388a58e016291b8b3ddbe0 Mon Sep 17 00:00:00 2001 From: Kristina Date: Thu, 8 Feb 2024 16:26:00 +0400 Subject: [PATCH] UBERF-5393: fix backlink for thread (#4578) Signed-off-by: Kristina Fefelova --- models/chunter/src/index.ts | 2 +- models/chunter/src/plugin.ts | 3 +- .../src/components/Replies.svelte | 6 +- .../threads/ThreadMessagePresenter.svelte | 60 +++++++++++++------ plugins/chunter-resources/src/index.ts | 8 ++- plugins/chunter-resources/src/utils.ts | 34 +++++++++-- 6 files changed, 81 insertions(+), 32 deletions(-) diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index 7636528b71..9dd2d56239 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -414,7 +414,7 @@ export function createModel (builder: Builder, options = { addApplication: true } builder.mixin(chunter.class.ThreadMessage, core.class.Class, view.mixin.LinkProvider, { - encode: chunter.function.GetFragment + encode: chunter.function.GetThreadLink }) createAction( diff --git a/models/chunter/src/plugin.ts b/models/chunter/src/plugin.ts index 438567ea07..b8e1cd2c33 100644 --- a/models/chunter/src/plugin.ts +++ b/models/chunter/src/plugin.ts @@ -108,7 +108,8 @@ export default mergeIds(chunterId, chunter, { CanDeleteMessage: '' as Resource<(doc?: Doc | Doc[]) => Promise>, CanReplyToThread: '' as Resource<(doc?: Doc | Doc[]) => Promise>, CanCopyMessageLink: '' as Resource<(doc?: Doc | Doc[]) => Promise>, - GetChunterSpaceLinkFragment: '' as Resource<(doc: Doc, props: Record) => Promise> + GetChunterSpaceLinkFragment: '' as Resource<(doc: Doc, props: Record) => Promise>, + GetThreadLink: '' as Resource<(doc: Doc, props: Record) => Promise> }, filter: { BacklinksFilter: '' as Resource<(message: ActivityMessage, _class?: Ref) => boolean>, diff --git a/plugins/chunter-resources/src/components/Replies.svelte b/plugins/chunter-resources/src/components/Replies.svelte index 0cd9089d9a..754fd6f871 100644 --- a/plugins/chunter-resources/src/components/Replies.svelte +++ b/plugins/chunter-resources/src/components/Replies.svelte @@ -16,7 +16,7 @@ import { Person } from '@hcengineering/contact' import { personByIdStore, Avatar } from '@hcengineering/contact-resources' import { Doc, IdMap, Ref, WithLookup } from '@hcengineering/core' - import { getLocation, Label, TimeSince } from '@hcengineering/ui' + import { getLocation, Label, navigate, TimeSince } from '@hcengineering/ui' import activity, { ActivityMessage } from '@hcengineering/activity' import notification, { ActivityInboxNotification, @@ -27,7 +27,7 @@ import { getResource } from '@hcengineering/platform' import { get } from 'svelte/store' - import { navigateToThread } from '../utils' + import { buildThreadLink } from '../utils' export let object: ActivityMessage export let embedded = false @@ -97,7 +97,7 @@ return } - navigateToThread(getLocation(), context._id, object._id) + navigate(buildThreadLink(getLocation(), context._id, object._id)) } diff --git a/plugins/chunter-resources/src/components/threads/ThreadMessagePresenter.svelte b/plugins/chunter-resources/src/components/threads/ThreadMessagePresenter.svelte index ae33098169..7fffaeb475 100644 --- a/plugins/chunter-resources/src/components/threads/ThreadMessagePresenter.svelte +++ b/plugins/chunter-resources/src/components/threads/ThreadMessagePresenter.svelte @@ -14,8 +14,13 @@ --> - +{#if inline && value} + {#await getDocLinkTitle(client, value.objectId, value.objectClass) then title} + + + + + + {title} + + {/await} +{:else} + +{/if} diff --git a/plugins/chunter-resources/src/index.ts b/plugins/chunter-resources/src/index.ts index 763bc436de..214106cb5f 100644 --- a/plugins/chunter-resources/src/index.ts +++ b/plugins/chunter-resources/src/index.ts @@ -82,7 +82,8 @@ import { getTitle, getUnreadThreadsCount, canCopyMessageLink, - navigateToThread + buildThreadLink, + getThreadLink } from './utils' import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources' import { type Mode } from './components/chat/types' @@ -244,7 +245,7 @@ export async function replyToThread (message: ActivityMessage): Promise { loc.path[2] = chunterId } - navigateToThread(loc, contextId, message._id) + navigate(buildThreadLink(loc, contextId, message._id)) } export default async (): Promise => ({ @@ -297,7 +298,8 @@ export default async (): Promise => ({ CanReplyToThread: canReplyToThread, CanCopyMessageLink: canCopyMessageLink, GetChunterSpaceLinkFragment: chunterSpaceLinkFragmentProvider, - GetUnreadThreadsCount: getUnreadThreadsCount + GetUnreadThreadsCount: getUnreadThreadsCount, + GetThreadLink: getThreadLink }, activity: { BacklinkCreatedLabel diff --git a/plugins/chunter-resources/src/utils.ts b/plugins/chunter-resources/src/utils.ts index 817f0db467..65f63f9ceb 100644 --- a/plugins/chunter-resources/src/utils.ts +++ b/plugins/chunter-resources/src/utils.ts @@ -51,7 +51,7 @@ import activity, { type DocUpdateMessage } from '@hcengineering/activity' import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources' -import { type DocNotifyContext, inboxId } from '@hcengineering/notification' +import notification, { type DocNotifyContext, inboxId } from '@hcengineering/notification' import { get, type Unsubscriber } from 'svelte/store' import chunter from './plugin' @@ -380,14 +380,13 @@ export async function filterChatMessages ( return messages.filter((message) => filtersFns.some((filterFn) => filterFn(message, objectClass))) } -export function navigateToThread (loc: Location, contextId: Ref, _id: Ref): void { +export function buildThreadLink (loc: Location, contextId: Ref, _id: Ref): Location { const specials = chatSpecials.map(({ id }) => id) if (loc.path[2] === chunterId && specials.includes(loc.path[3])) { loc.path[4] = _id loc.query = { message: _id } - navigate(loc) - return + return loc } if (loc.path[2] !== inboxId) { @@ -398,7 +397,32 @@ export function navigateToThread (loc: Location, contextId: Ref { + const loc = getCurrentResolvedLocation() + const client = getClient() + const inboxClient = InboxNotificationsClientImpl.getClient() + + let contextId: Ref | undefined = get(inboxClient.docNotifyContextByDoc).get(doc.objectId)?._id + + if (contextId === undefined) { + contextId = await client.createDoc(notification.class.DocNotifyContext, doc.space, { + attachedTo: doc.attachedTo, + attachedToClass: doc.attachedToClass, + user: getCurrentAccount()._id, + hidden: false, + lastViewedTimestamp: Date.now() + }) + } + + if (contextId === undefined) { + return loc + } + + return buildThreadLink(loc, contextId, doc.attachedTo) } export async function joinChannel (channel: Channel, value: Ref | Array>): Promise {