mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-10 11:47:42 +02:00
Adjust tg bot (#8412)
* Remove notification provider func Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * Adjust tg-bot Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * Use global integration Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * Use workspace integration Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * getSocialIdBySocialKey -> findFullSocialIdBySocialKey Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * move findFullSocialIdBySocialKey to service operations Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * use listIntegrations with account token Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * Adjust api Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> * Fxi tests Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com> --------- Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -60,11 +60,7 @@ import notification, {
|
||||
} from '@hcengineering/notification'
|
||||
import { getResource, translate } from '@hcengineering/platform'
|
||||
import { type TriggerControl } from '@hcengineering/server-core'
|
||||
import serverNotification, {
|
||||
NOTIFICATION_BODY_SIZE,
|
||||
ReceiverInfo,
|
||||
SenderInfo
|
||||
} from '@hcengineering/server-notification'
|
||||
import { NOTIFICATION_BODY_SIZE, ReceiverInfo, SenderInfo } from '@hcengineering/server-notification'
|
||||
import { markupToText, stripTags } from '@hcengineering/text-core'
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import { getAccountBySocialId, getEmployeesBySocialIds } from '@hcengineering/server-contact'
|
||||
@@ -140,7 +136,7 @@ export async function getCommonNotificationTxes (
|
||||
const res: Tx[] = []
|
||||
const notifyContexts = await control.findAll(ctx, notification.class.DocNotifyContext, { objectId: attachedTo })
|
||||
|
||||
const notificationTx = await pushInboxNotifications(
|
||||
await pushInboxNotifications(
|
||||
ctx,
|
||||
control,
|
||||
res,
|
||||
@@ -157,12 +153,6 @@ export async function getCommonNotificationTxes (
|
||||
tx
|
||||
)
|
||||
|
||||
if (notificationTx !== undefined) {
|
||||
const notificationData = TxProcessor.createDoc2Doc(notificationTx)
|
||||
|
||||
await applyNotificationProviders(notificationData, notifyResult, control, res, doc, receiver, sender, _class)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -534,32 +524,6 @@ export async function pushActivityInboxNotifications (
|
||||
)
|
||||
}
|
||||
|
||||
export async function applyNotificationProviders (
|
||||
data: InboxNotification,
|
||||
notifyResult: NotifyResult,
|
||||
control: TriggerControl,
|
||||
res: Tx[],
|
||||
object: Doc,
|
||||
receiver: ReceiverInfo,
|
||||
sender: SenderInfo,
|
||||
_class = notification.class.ActivityInboxNotification,
|
||||
message?: ActivityMessage
|
||||
): Promise<void> {
|
||||
const resources = control.modelDb.findAllSync(serverNotification.class.NotificationProviderResources, {})
|
||||
for (const [provider, types] of notifyResult.entries()) {
|
||||
const resource = resources.find((it) => it.provider === provider)
|
||||
|
||||
if (resource === undefined) continue
|
||||
|
||||
const fn = await getResource(resource.fn)
|
||||
|
||||
const txes = await fn(control, types, object, data, receiver, sender, message)
|
||||
if (txes.length > 0) {
|
||||
res.push(...txes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function createNotifyContext (
|
||||
ctx: MeasureContext,
|
||||
control: TriggerControl,
|
||||
@@ -651,28 +615,12 @@ export async function getNotificationTxes (
|
||||
)
|
||||
|
||||
if (notificationTx !== undefined) {
|
||||
const notificationData = TxProcessor.createDoc2Doc(notificationTx)
|
||||
|
||||
const current: AvailableProvidersCache = control.contextCache.get(AvailableProvidersCacheKey) ?? new Map()
|
||||
const providers = Array.from(notifyResult.keys()).filter(
|
||||
(p) => p !== notification.providers.InboxNotificationProvider
|
||||
)
|
||||
const providers = Array.from(notifyResult.keys())
|
||||
if (providers.length > 0) {
|
||||
current.set(notificationData._id, providers)
|
||||
current.set(notificationTx.objectId, providers)
|
||||
control.contextCache.set('AvailableNotificationProviders', current)
|
||||
}
|
||||
|
||||
await applyNotificationProviders(
|
||||
notificationData,
|
||||
notifyResult,
|
||||
control,
|
||||
res,
|
||||
object,
|
||||
receiver,
|
||||
sender,
|
||||
notificationData._class,
|
||||
message
|
||||
)
|
||||
}
|
||||
} else {
|
||||
const context = getDocNotifyContext(control, docNotifyContexts, message.attachedTo, receiver.account)
|
||||
|
||||
@@ -82,10 +82,10 @@ export function isUserEmployeeInFieldValueTypeMatch (
|
||||
type: NotificationType,
|
||||
control: TriggerControl
|
||||
): boolean {
|
||||
// TODO: check field type and compare with Ref<Person> or PersonId based on that
|
||||
if (type.field === undefined) return false
|
||||
const value = (doc as any)[type.field]
|
||||
if (value == null) return false
|
||||
if (value === person) return true
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return includesAny(value, socialIds)
|
||||
@@ -121,7 +121,7 @@ function escapeRegExp (str: string): string {
|
||||
|
||||
export async function shouldNotifyCommon (
|
||||
control: TriggerControl,
|
||||
user: PersonId[],
|
||||
socialIds: PersonId[],
|
||||
typeId: Ref<CommonNotificationType>,
|
||||
notificationControl: NotificationProviderControl
|
||||
): Promise<NotifyResult> {
|
||||
@@ -135,7 +135,7 @@ export async function shouldNotifyCommon (
|
||||
const providers = await control.modelDb.findAll(notification.class.NotificationProvider, {})
|
||||
|
||||
for (const provider of providers) {
|
||||
const allowed = isAllowed(control, user, type, provider, notificationControl)
|
||||
const allowed = isAllowed(control, socialIds, type, provider, notificationControl)
|
||||
|
||||
if (allowed) {
|
||||
const cur = result.get(provider._id) ?? []
|
||||
|
||||
Reference in New Issue
Block a user