Fix notification preview and creation from contact card

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina Fefelova 2024-07-04 17:36:18 +04:00
parent fed5814e68
commit 5eb6ad71e9
No known key found for this signature in database
GPG Key ID: 750D35EF042F0690
9 changed files with 161 additions and 27 deletions

View File

@ -271,8 +271,6 @@ export function createModel (builder: Builder): void {
]
})
builder.mixin(contact.class.Channel, core.class.Class, activity.mixin.ActivityDoc, {})
builder.mixin(contact.class.Person, core.class.Class, view.mixin.ObjectIcon, {
component: contact.component.PersonIcon
})

View File

@ -184,4 +184,8 @@ export function createModel (builder: Builder): void {
chunter.action.ReplyToThreadAction
]
})
builder.mixin(telegram.class.TelegramChatMessage, core.class.Class, activity.mixin.ActivityMessagePreview, {
presenter: telegram.component.TelegramMessagePreview
})
}

View File

@ -14,7 +14,6 @@
// limitations under the License.
//
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { AnyComponent } from '@hcengineering/ui'
import { type Ref } from '@hcengineering/core'
import { type IntlString, type Resource, mergeIds } from '@hcengineering/platform'
@ -40,6 +39,9 @@ export default mergeIds(telegramId, telegram, {
NewMessage: '' as IntlString,
NewIncomingMessage: '' as IntlString
},
component: {
TelegramMessagePreview: '' as AnyComponent
},
ids: {
NotificationGroup: '' as Ref<NotificationGroup>,
TelegramMessageSharedActivityViewlet: '' as Ref<DocUpdateMessageViewlet>

View File

@ -116,6 +116,8 @@
if (channel === undefined) return
loading = true
const { message, attachments } = event.detail
const receiver = Array.from($personAccountByIdStore.values()).find((it) => it.person === object._id)?._id
await client.addCollection(
telegram.class.TelegramChannelMessage,
core.space.Workspace,
@ -126,6 +128,7 @@
content: markupToHTML(message),
status: TelegramMessageStatus.New,
history: false,
receiver,
attachments
},
newId

View File

@ -14,15 +14,17 @@
-->
<script lang="ts">
import { TelegramChatMessage, TelegramChannelMessage, TelegramMessageStatus } from '@hcengineering/telegram'
import { Doc, getCurrentAccount, WithLookup } from '@hcengineering/core'
import { Doc, getCurrentAccount, Ref, WithLookup } from '@hcengineering/core'
import { Action, Icon, IconCheckmark, Label, Spinner } from '@hcengineering/ui'
import { AttachmentImageSize } from '@hcengineering/attachment-resources'
import { ActivityMessageViewType } from '@hcengineering/activity'
import { ChatMessageContent, ChatMessagePresenter } from '@hcengineering/chunter-resources'
import notification from '@hcengineering/notification'
import { Attachment } from '@hcengineering/attachment'
import { createQuery } from '@hcengineering/presentation'
import attachment, { Attachment } from '@hcengineering/attachment'
import TelegramIcon from './icons/Telegram.svelte'
import telegram from '../plugin'
export let value: WithLookup<TelegramChatMessage> | undefined
export let doc: Doc | undefined = undefined
@ -33,15 +35,27 @@
export let attachmentImageSize: AttachmentImageSize = 'x-large'
export let showLinksPreview = true
export let type: ActivityMessageViewType = 'default'
export let shortTime = false
export let embedded = false
export let onClick: (() => void) | undefined = undefined
const me = getCurrentAccount()
const channelMessageQuery = createQuery()
let channelMessage: WithLookup<TelegramChannelMessage> | undefined = undefined
$: channelMessage = value?.$lookup?.channelMessage as WithLookup<TelegramChannelMessage>
$: if (value && value?.$lookup?.channelMessage === undefined) {
channelMessageQuery.query(
telegram.class.TelegramChannelMessage,
{ _id: value.channelMessage as Ref<TelegramChannelMessage> },
(res) => {
channelMessage = res[0]
},
{ lookup: { _id: { attachments: attachment.class.Attachment } } }
)
} else {
channelMessage = value?.$lookup?.channelMessage as WithLookup<TelegramChannelMessage>
channelMessageQuery.unsubscribe()
}
let attachments: Attachment[] = []
$: attachments = (channelMessage?.$lookup?.attachments ?? []) as Attachment[]
@ -62,7 +76,6 @@
{embedded}
{type}
withShowMore={false}
{shortTime}
skipLabel={false}
typeIcon={TelegramIcon}
{onClick}

View File

@ -0,0 +1,104 @@
<!--
// Copyright © 2024 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
import { ActivityMessagePreviewType } from '@hcengineering/activity'
import { BaseMessagePreview } from '@hcengineering/activity-resources'
import attachment, { Attachment } from '@hcengineering/attachment'
import { AttachmentsTooltip } from '@hcengineering/attachment-resources'
import core, { Ref, WithLookup } from '@hcengineering/core'
import { createQuery } from '@hcengineering/presentation'
import { Action, Icon, Label, tooltip } from '@hcengineering/ui'
import { TelegramChannelMessage, TelegramChatMessage } from '@hcengineering/telegram'
import telegram from '../plugin'
import { isEmptyMarkup } from '@hcengineering/text'
export let value: WithLookup<TelegramChatMessage>
export let readonly = false
export let type: ActivityMessagePreviewType = 'full'
export let actions: Action[] = []
const attachmentsQuery = createQuery()
const channelMessageQuery = createQuery()
let channelMessage: TelegramChannelMessage | undefined = undefined
let attachments: Attachment[] = []
$: if ((channelMessage?.attachments ?? 0) > 0) {
attachmentsQuery.query(
attachment.class.Attachment,
{
attachedTo: value._id
},
(res) => {
attachments = res
},
{
lookup: {
file: core.class.Blob
}
}
)
} else {
attachments = []
attachmentsQuery.unsubscribe()
}
$: channelMessageQuery.query(
telegram.class.TelegramChannelMessage,
{
_id: value.channelMessage as Ref<TelegramChannelMessage>
},
(res) => {
channelMessage = res[0]
}
)
$: isEmpty = channelMessage ? isEmptyMarkup(channelMessage.content) : true
</script>
<BaseMessagePreview text={channelMessage?.content} message={value} {type} {readonly} {actions} on:click>
{#if value.attachments && type === 'full' && !isEmpty}
<div class="attachments" use:tooltip={{ component: AttachmentsTooltip, props: { attachments } }}>
{value.attachments}
<Icon icon={attachment.icon.Attachment} size="small" />
</div>
{:else if attachments.length > 0 && !isEmpty}
<span class="font-normal">
<Label label={attachment.string.Attachments} />:
<span class="ml-1">
{attachments.map(({ name }) => name).join(', ')}
</span>
</span>
{/if}
</BaseMessagePreview>
<style lang="scss">
.attachments {
margin-left: 0;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: var(--global-secondary-TextColor);
&:hover {
cursor: pointer;
color: var(--global-primary-TextColor);
}
}
</style>

View File

@ -23,6 +23,7 @@ import Connect from './components/Connect.svelte'
import Reconnect from './components/Reconnect.svelte'
import IconTelegram from './components/icons/TelegramColor.svelte'
import MessagePresenter from './components/MessagePresenter.svelte'
import TelegramMessagePreview from './components/TelegramMessagePreview.svelte'
import telegram from './plugin'
import { getCurrentEmployeeTG, getIntegrationOwnerTG, createMessage, editMessage, canGroupMessages } from './utils'
@ -35,7 +36,8 @@ export default async (): Promise<Resources> => ({
Reconnect,
IconTelegram,
SharedMessages,
MessagePresenter
MessagePresenter,
TelegramMessagePreview
},
function: {
GetCurrentEmployeeTG: getCurrentEmployeeTG,

View File

@ -49,9 +49,10 @@ export async function getIntegrationOwnerTG (provider: TemplateDataProvider): Pr
}
}
export const createMessage: CreateExternalMessageFn = async (client, object: Doc, channel, data) => {
export const createMessage: CreateExternalMessageFn = async (_, object: Doc, channel, data) => {
const { _id, message, attachments, collection } = data
const direct = object as DirectMessage
const client = getClient()
const channelMessageId = await client.addCollection<Doc, TelegramChannelMessage>(
telegram.class.TelegramChannelMessage,
@ -83,7 +84,7 @@ export const createMessage: CreateExternalMessageFn = async (client, object: Doc
channelClass: channel._class,
channelMessage: channelMessageId,
channelMessageClass: telegram.class.TelegramChannelMessage,
message: ''
message
}
)
}

View File

@ -30,7 +30,7 @@ import core, {
TxRemoveDoc
} from '@hcengineering/core'
import { TriggerControl } from '@hcengineering/server-core'
import telegram, { TelegramChannelMessage, TelegramChatMessage, TelegramMessageStatus } from '@hcengineering/telegram'
import telegram, { TelegramChannelMessage, TelegramChatMessage } from '@hcengineering/telegram'
import setting, { Integration } from '@hcengineering/setting'
import chunter, { DirectMessage } from '@hcengineering/chunter'
import { deepEqual } from 'fast-equals'
@ -59,13 +59,20 @@ export async function FindMessages (
* @public
*/
export async function IsNewMessage (
tx: Tx,
originTx: Tx,
doc: Doc,
user: Ref<Account>,
type: NotificationType,
control: TriggerControl
): Promise<boolean> {
const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc<TelegramChatMessage>)
const tx = TxProcessor.extractTx(originTx) as TxCreateDoc<TelegramChatMessage>
if (!control.hierarchy.isDerived(tx.objectClass, telegram.class.TelegramChatMessage)) {
return true
}
const message = TxProcessor.createDoc2Doc(tx)
const channelMessage = (await control.findAll(message.channelMessageClass, { _id: message.channelMessage }))[0] as
| TelegramChannelMessage
| undefined
@ -144,11 +151,6 @@ async function OnChannelMessageCreate (
}
const message = TxProcessor.createDoc2Doc(tx)
if (message.status === TelegramMessageStatus.New) {
return []
}
const res: Tx[] = []
const sender = tx.modifiedBy as Ref<PersonAccount>
const receiver = message.receiver as Ref<PersonAccount>
@ -198,15 +200,20 @@ async function OnChannelMessageCreate (
message.modifiedOn
)
res.push(
control.txFactory.createTxCollectionCUD<DirectMessage, TelegramChatMessage>(
chunter.class.DirectMessage,
direct,
core.space.Space,
'messages',
createTx
)
createTx.space = core.space.Tx
const collectionTx = control.txFactory.createTxCollectionCUD<DirectMessage, TelegramChatMessage>(
chunter.class.DirectMessage,
direct,
core.space.Space,
'messages',
createTx
)
collectionTx.space = core.space.Tx
res.push(collectionTx)
return res
}