Fix telegram notifications (#3257)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-05-25 18:10:08 +06:00 committed by GitHub
parent 7233d15ba0
commit 0298ff1c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 8 deletions

View File

@ -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, {

View File

@ -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
}

View File

@ -126,8 +126,8 @@ export async function IsIncomingMessage (
type: NotificationType,
control: TriggerControl
): Promise<boolean> {
const message = doc as Message
return message.incoming
const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc<Message>)
return message.incoming && message.sendOn > (doc.createOn ?? doc.modifiedOn)
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type

View File

@ -495,6 +495,7 @@ async function createCollabDocInfo (
isSpace: boolean = false
): Promise<Tx[]> {
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<Tx[]> {
switch (tx._class) {
case core.class.TxCreateDoc:
if (tx.space === core.space.DerivedTx) return []
return await createCollaboratorDoc(tx as TxCreateDoc<Doc>, 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<Doc>, control, originTx ?? tx)
res = res.concat(await updateCollaboratorsMixin(tx as TxMixin<Doc, Collaborators>, control, originTx ?? tx))
return res

View File

@ -124,8 +124,8 @@ export async function IsIncomingMessage (
type: NotificationType,
control: TriggerControl
): Promise<boolean> {
const message = doc as TelegramMessage
return message.incoming
const message = TxProcessor.createDoc2Doc(TxProcessor.extractTx(tx) as TxCreateDoc<TelegramMessage>)
return message.incoming && message.sendOn > (doc.createOn ?? doc.modifiedOn)
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type