From 0298ff1c8d8b50e2d3225c9e8ee1a0759cd6ac2a Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 25 May 2023 18:10:08 +0600 Subject: [PATCH] Fix telegram notifications (#3257) Signed-off-by: Denis Bykhov --- models/contact/src/index.ts | 2 +- packages/core/src/tx.ts | 2 +- server-plugins/gmail-resources/src/index.ts | 4 ++-- server-plugins/notification-resources/src/index.ts | 3 +-- server-plugins/telegram-resources/src/index.ts | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index 97de8345f0..aebb02eb8d 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -327,7 +327,7 @@ export function createModel (builder: Builder): void { }) builder.mixin(contact.class.Channel, core.class.Class, notification.mixin.ClassCollaborators, { - fields: [] + fields: ['modifiedBy'] }) builder.mixin(contact.class.Channel, core.class.Class, notification.mixin.NotificationObjectPresenter, { diff --git a/packages/core/src/tx.ts b/packages/core/src/tx.ts index 75fd03b9cd..18655c6902 100644 --- a/packages/core/src/tx.ts +++ b/packages/core/src/tx.ts @@ -354,7 +354,7 @@ export abstract class TxProcessor implements WithTx { modifiedBy: tx.modifiedBy, modifiedOn: tx.modifiedOn, createdBy: tx.createdBy ?? tx.modifiedBy, - createOn: tx.createOn ?? tx.modifiedBy + createOn: tx.createOn ?? tx.modifiedOn } as T } diff --git a/server-plugins/gmail-resources/src/index.ts b/server-plugins/gmail-resources/src/index.ts index 0a6c7f07d8..11d34ebb2b 100644 --- a/server-plugins/gmail-resources/src/index.ts +++ b/server-plugins/gmail-resources/src/index.ts @@ -126,8 +126,8 @@ export async function IsIncomingMessage ( type: NotificationType, control: TriggerControl ): Promise { - const message = doc as Message - return message.incoming + const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc) + return message.incoming && message.sendOn > (doc.createOn ?? doc.modifiedOn) } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index 365da85944..b547c885d3 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -495,6 +495,7 @@ async function createCollabDocInfo ( isSpace: boolean = false ): Promise { let res: Tx[] = [] + if (originTx.space === core.space.DerivedTx) return res const targets = new Set(collaborators) const docUpdates = await control.findAll(notification.class.DocUpdates, { attachedTo: object._id }) for (const target of targets) { @@ -578,11 +579,9 @@ export async function collaboratorDocHandler ( ): Promise { switch (tx._class) { case core.class.TxCreateDoc: - if (tx.space === core.space.DerivedTx) return [] return await createCollaboratorDoc(tx as TxCreateDoc, control, originTx ?? tx) case core.class.TxUpdateDoc: case core.class.TxMixin: { - if (tx.space === core.space.DerivedTx) return [] let res = await updateCollaboratorDoc(tx as TxUpdateDoc, control, originTx ?? tx) res = res.concat(await updateCollaboratorsMixin(tx as TxMixin, control, originTx ?? tx)) return res diff --git a/server-plugins/telegram-resources/src/index.ts b/server-plugins/telegram-resources/src/index.ts index c79bd852ff..45320dd99a 100644 --- a/server-plugins/telegram-resources/src/index.ts +++ b/server-plugins/telegram-resources/src/index.ts @@ -124,8 +124,8 @@ export async function IsIncomingMessage ( type: NotificationType, control: TriggerControl ): Promise { - const message = doc as TelegramMessage - return message.incoming + const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc) + return message.incoming && message.sendOn > (doc.createOn ?? doc.modifiedOn) } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type