Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-5686: Fix copy link #5368

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 22 additions & 37 deletions models/chunter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,29 +403,28 @@ export function createModel (builder: Builder, options = { addApplication: true
encode: chunter.function.GetThreadLink
})

// Note: it is not working now, need to fix navigation by url UBERF-5686
// createAction(
// builder,
// {
// action: view.actionImpl.CopyTextToClipboard,
// actionProps: {
// textProvider: chunter.function.GetLink
// },
// label: chunter.string.CopyLink,
// icon: chunter.icon.Copy,
// keyBinding: [],
// input: 'none',
// category: chunter.category.Chunter,
// target: activity.class.ActivityMessage,
// visibilityTester: chunter.function.CanCopyMessageLink,
// context: {
// mode: ['context', 'browser'],
// application: chunter.app.Chunter,
// group: 'copy'
// }
// },
// chunter.action.CopyChatMessageLink
// )
createAction(
builder,
{
action: view.actionImpl.CopyTextToClipboard,
actionProps: {
textProvider: chunter.function.GetLink
},
label: chunter.string.CopyLink,
icon: chunter.icon.Copy,
keyBinding: [],
input: 'none',
category: chunter.category.Chunter,
target: activity.class.ActivityMessage,
visibilityTester: chunter.function.CanCopyMessageLink,
context: {
mode: ['context', 'browser'],
application: chunter.app.Chunter,
group: 'copy'
}
},
chunter.action.CopyChatMessageLink
)

builder.mixin(chunter.class.ChunterMessage, core.class.Class, view.mixin.ClassFilters, {
filters: ['space', '_class']
Expand Down Expand Up @@ -603,20 +602,6 @@ export function createModel (builder: Builder, options = { addApplication: true
chunter.action.LeaveChannel
)

createAction(
builder,
{
...viewTemplates.open,
target: notification.class.DocNotifyContext,
context: {
mode: ['browser', 'context'],
group: 'create'
},
action: chunter.actionImpl.OpenChannel
},
chunter.action.OpenChannel
)

createAction(builder, {
...notificationActionTemplates.pinContext,
label: chunter.string.StarChannel,
Expand Down
12 changes: 6 additions & 6 deletions plugins/chunter-resources/src/components/Channel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import ChannelScrollView from './ChannelScrollView.svelte'
import { ChannelDataProvider } from '../channelDataProvider'

export let context: DocNotifyContext
export let object: Doc | undefined
export let object: Doc
export let context: DocNotifyContext | undefined
export let filters: Ref<ActivityMessagesFilter>[] = []
export let isAsideOpened = false

Expand All @@ -39,11 +39,11 @@
selectedMessageId = getMessageFromLoc(newLocation)
})

$: isDocChannel = !hierarchy.isDerived(context.attachedToClass, chunter.class.ChunterSpace)
$: isDocChannel = !hierarchy.isDerived(object._class, chunter.class.ChunterSpace)
$: _class = isDocChannel ? activity.class.ActivityMessage : chunter.class.ChatMessage
$: collection = isDocChannel ? 'comments' : 'messages'

$: updateDataProvider(context.attachedTo, _class, context.lastViewedTimestamp, selectedMessageId)
$: updateDataProvider(object._id, _class, context?.lastViewedTimestamp, selectedMessageId)

function updateDataProvider (
attachedTo: Ref<Doc>,
Expand All @@ -62,8 +62,8 @@

{#if dataProvider}
<ChannelScrollView
objectId={context.attachedTo}
objectClass={context.attachedToClass}
objectId={object._id}
objectClass={object._class}
{object}
skipLabels={!isDocChannel}
selectedFilters={filters}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
})
</script>

{#if context}
{#if object}
<div class="antiComponent">
<ChannelView {object} {context} embedded allowClose on:close />
</div>
Expand Down
21 changes: 10 additions & 11 deletions plugins/chunter-resources/src/components/ChannelView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import chunter from '../plugin'
import ChannelAside from './chat/ChannelAside.svelte'

export let context: DocNotifyContext
export let object: Doc | undefined = undefined
export let object: Doc
export let context: DocNotifyContext | undefined
export let allowClose = false
export let embedded = false

Expand All @@ -43,9 +43,8 @@
isThreadOpened = newLocation.path[4] != null
})

$: isDocChat = !hierarchy.isDerived(context.attachedToClass, chunter.class.ChunterSpace)
$: withAside =
!embedded && !isThreadOpened && !hierarchy.isDerived(context.attachedToClass, chunter.class.DirectMessage)
$: isDocChat = !hierarchy.isDerived(object._class, chunter.class.ChunterSpace)
$: withAside = !embedded && !isThreadOpened && !hierarchy.isDerived(object._class, chunter.class.DirectMessage)

function toChannel (object?: Doc): Channel | undefined {
return object as Channel | undefined
Expand All @@ -56,8 +55,8 @@

<div class="popupPanel panel" class:embedded>
<ChannelHeader
_id={context.attachedTo}
_class={context.attachedToClass}
_id={object._id}
_class={object._class}
{object}
{allowClose}
{withAside}
Expand All @@ -72,7 +71,7 @@

<div class="popupPanel-body" class:asideShown={withAside && isAsideShown}>
<div class="popupPanel-body__main">
{#key context._id}
{#key object._id}
<ChannelComponent {context} {object} {filters} isAsideOpened={(withAside && isAsideShown) || isThreadOpened} />
{/key}
</div>
Expand All @@ -82,10 +81,10 @@
<div class="popupPanel-body__aside" class:float={false} class:shown={withAside && isAsideShown}>
<Separator name="aside" float index={0} />
<div class="antiPanel-wrap__content">
{#if hierarchy.isDerived(context.attachedToClass, chunter.class.Channel)}
<ChannelAside _class={context.attachedToClass} object={toChannel(object)} />
{#if hierarchy.isDerived(object._class, chunter.class.Channel)}
<ChannelAside _class={object._class} object={toChannel(object)} />
{:else}
<DocAside _class={context.attachedToClass} {object} />
<DocAside _class={object._class} {object} />
{/if}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion plugins/chunter-resources/src/components/DmHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import { createQuery, getClient } from '@hcengineering/presentation'
import { SearchEdit } from '@hcengineering/ui'
import { openDoc } from '@hcengineering/view-resources'

import { userSearch } from '../index'
import chunter from '../plugin'
import { getDmName, navigateToSpecial } from '../utils'
import { getDmName } from '../utils'
import { navigateToSpecial } from '../navigation'

export let spaceId: Ref<DirectMessage> | undefined
export let withSearch: boolean = true
Expand Down
2 changes: 1 addition & 1 deletion plugins/chunter-resources/src/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { ActivityMessagesFilter } from '@hcengineering/activity'

import { userSearch } from '../index'
import { navigateToSpecial } from '../utils'
import { navigateToSpecial } from '../navigation'
import ChannelMessagesFilter from './ChannelMessagesFilter.svelte'

export let object: Doc | undefined = undefined
Expand Down
19 changes: 4 additions & 15 deletions plugins/chunter-resources/src/components/Replies.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
InboxNotificationsClient
} from '@hcengineering/notification'
import { getResource } from '@hcengineering/platform'
import { get } from 'svelte/store'

import { buildThreadLink } from '../utils'
import { buildThreadLink } from '../navigation'

export let object: ActivityMessage
export let embedded = false
Expand All @@ -40,7 +39,7 @@

let inboxClient: InboxNotificationsClient | undefined = undefined

getResource(notification.function.GetInboxNotificationsClient).then((getClientFn) => {
void getResource(notification.function.GetInboxNotificationsClient).then((getClientFn) => {
inboxClient = getClientFn()
})

Expand Down Expand Up @@ -78,7 +77,7 @@
.slice(0, maxDisplayPersons - 1)
}

function handleReply (e: any) {
function handleReply (e: MouseEvent) {
e.stopPropagation()
e.preventDefault()

Expand All @@ -87,17 +86,7 @@
return
}

if (inboxClient === undefined) {
return
}

const context = get(inboxClient.contextByDoc).get(object.attachedTo)

if (context === undefined) {
return
}

navigate(buildThreadLink(getLocation(), context._id, object._id))
navigate(buildThreadLink(getLocation(), object.attachedTo, object.attachedToClass, object._id))
}
</script>

Expand Down
65 changes: 29 additions & 36 deletions plugins/chunter-resources/src/components/chat/Chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Doc, IdMap, Ref } from '@hcengineering/core'
import { Doc, Ref, Class } from '@hcengineering/core'
import { createQuery } from '@hcengineering/presentation'
import {
Component,
Expand All @@ -24,7 +24,6 @@
Separator,
Location
} from '@hcengineering/ui'
import { DocNotifyContext } from '@hcengineering/notification'

import { NavigatorModel, SpecialNavModel } from '@hcengineering/workbench'
import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
Expand All @@ -33,22 +32,23 @@
import ChatNavigator from './navigator/ChatNavigator.svelte'
import ChannelView from '../ChannelView.svelte'
import { chatSpecials, loadSavedAttachments } from './utils'
import { SelectChannelEvent } from './types'
import { decodeChannelURI, openChannel } from '../../navigation'

export let visibleNav: boolean = true
export let navFloat: boolean = false
export let appsDirection: 'vertical' | 'horizontal' = 'horizontal'

const notificationsClient = InboxNotificationsClientImpl.getClient()
const contextByIdStore = notificationsClient.contextById
const contextByDocStore = notificationsClient.contextByDoc
const objectQuery = createQuery()

const navigatorModel: NavigatorModel = {
spaces: [],
specials: chatSpecials
}

let selectedContextId: Ref<DocNotifyContext> | undefined = undefined
let selectedContext: DocNotifyContext | undefined = undefined
let selectedData: { _id: Ref<Doc>, _class: Ref<Class<Doc>> } | undefined = undefined

let currentSpecial: SpecialNavModel | undefined

Expand All @@ -58,57 +58,49 @@
syncLocation(loc)
})

$: updateSelectedContext($contextByIdStore, selectedContextId)
$: void loadObject(selectedData?._id, selectedData?._class)

async function loadObject (_id?: Ref<Doc>, _class?: Ref<Class<Doc>>): Promise<void> {
if (_id === undefined || _class === undefined) {
object = undefined
objectQuery.unsubscribe()
return
}

$: selectedContext &&
objectQuery.query(
selectedContext.attachedToClass,
{ _id: selectedContext.attachedTo },
_class,
{ _id },
(res) => {
object = res[0]
},
{ limit: 1 }
)
}

function syncLocation (loc: Location) {
const specialId = loc.path[3]

currentSpecial = navigatorModel?.specials?.find((special) => special.id === specialId)

if (currentSpecial !== undefined) {
selectedContext = undefined
selectedContextId = undefined
selectedData = undefined
} else {
selectedContextId = loc.path[3] as Ref<DocNotifyContext> | undefined
}
}
const [_id, _class] = decodeChannelURI(loc.path[3])

function updateSelectedContext (contexts: IdMap<DocNotifyContext>, _id?: Ref<DocNotifyContext>) {
if (selectedContextId === undefined) {
selectedContext = undefined
} else {
selectedContext = contexts.get(selectedContextId)
selectedData = { _id, _class }
}
}

function handleChannelSelected (event: CustomEvent) {
const { context } = event.detail ?? {}
function handleChannelSelected (event: CustomEvent): void {
const detail = (event.detail ?? {}) as SelectChannelEvent

selectedContext = context
selectedContextId = selectedContext?._id
selectedData = { _id: detail.object._id, _class: detail.object._class }

if (selectedContext?.attachedTo !== object?._id) {
object = undefined
if (selectedData._id !== object?._id) {
object = detail.object
}

const loc = getCurrentLocation()

loc.path[3] = selectedContextId as string
loc.path[4] = ''
loc.query = { ...loc.query, message: null }
loc.path.length = 4

navigate(loc)
openChannel(selectedData._id, selectedData._class)
}

defineSeparators('chat', [
Expand All @@ -127,7 +119,7 @@
class="antiPanel-navigator {appsDirection === 'horizontal' ? 'portrait' : 'landscape'} background-surface-color"
>
<div class="antiPanel-wrap__content">
<ChatNavigator {selectedContextId} {currentSpecial} on:select={handleChannelSelected} />
<ChatNavigator objectId={selectedData?._id} {object} {currentSpecial} on:select={handleChannelSelected} />
</div>
<Separator name="chat" float={navFloat ? 'navigator' : true} index={0} />
</div>
Expand All @@ -153,8 +145,9 @@
}
}}
/>
{:else if selectedContext}
<ChannelView context={selectedContext} {object} />
{:else if object}
{@const context = $contextByDocStore.get(object._id)}
<ChannelView {object} {context} />
{/if}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@

{#if threadId}
<ThreadView _id={threadId} on:close />
{:else if context}
{:else if object}
<ChannelView {object} {context} allowClose embedded on:close />
{/if}
Loading