QFix: Fix mail messages order (#9419)

Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
Artyom Savchenko
2025-07-01 14:30:37 +07:00
committed by GitHub
parent e9a264be22
commit 10292174eb
3 changed files with 19 additions and 9 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ import chat from '@hcengineering/chat'
import mail from '@hcengineering/mail'
import { PersonSpace } from '@hcengineering/contact'
import { SyncMutex } from './mutex'
import { normalizeEmail } from './utils'
import { MessageTimeShift, normalizeEmail } from './utils'
const createMutex = new SyncMutex()
@@ -144,7 +144,7 @@ export class ChannelCache {
modifiedBy: personId
},
generateId(),
Date.now(),
Date.now() + MessageTimeShift.Channel,
personId
)
@@ -155,7 +155,7 @@ export class ChannelCache {
space,
mail.tag.MailChannel,
{},
Date.now(),
Date.now() + MessageTimeShift.MailTag,
personId
)
+6 -6
View File
@@ -44,7 +44,7 @@ import { generateMessageId } from '@hcengineering/communication-shared'
import { BaseConfig, SyncOptions, type Attachment } from './types'
import { EmailMessage, MailRecipient, MessageData } from './types'
import { getBlobMetadata, getMdContent } from './utils'
import { getBlobMetadata, getMdContent, MessageTimeShift } from './utils'
import { PersonCacheFactory } from './person'
import { PersonSpacesCacheFactory } from './personSpaces'
import { ChannelCache, ChannelCacheFactory } from './channel'
@@ -229,10 +229,10 @@ async function saveMessageToSpaces (
createdBy: modifiedBy,
modifiedBy,
parent: channel,
createdOn: createdDate - 4 // Add a small shift to ensure correct ordering
createdOn: createdDate + MessageTimeShift.ThreadCard // Add a small shift to ensure correct ordering
},
generateId(),
createdDate - 4,
createdDate + MessageTimeShift.ThreadCard,
modifiedBy
)
threadId = newThreadId as Ref<Card>
@@ -281,7 +281,7 @@ async function createMailThread (
cardType: chat.masterTag.Thread,
content: data.subject,
socialId: data.modifiedBy,
date: new Date(data.created.getTime() - 1),
date: new Date(data.created.getTime() + MessageTimeShift.Subject),
messageId: subjectId,
options: {
noNotify: options?.noNotify
@@ -300,7 +300,7 @@ async function createMailThread (
threadType: chat.masterTag.Thread
},
socialId: data.modifiedBy,
date: new Date(data.created.getTime() - 3)
date: new Date(data.created.getTime() + MessageTimeShift.Thread)
}
const thread = Buffer.from(JSON.stringify(threadEvent))
await sendToCommunicationTopic(producer, config, data, thread)
@@ -392,7 +392,7 @@ async function addCollaborators (
cardType: chat.masterTag.Thread,
collaborators: [data.recipient.uuid as AccountUuid],
socialId: data.modifiedBy,
date: new Date(data.created.getTime() - 2)
date: new Date(data.created.getTime() + MessageTimeShift.Collaborator)
}
const createMessageData = Buffer.from(JSON.stringify(addCollaboratorsEvent))
await sendToCommunicationTopic(producer, config, data, createMessageData)
+10
View File
@@ -150,3 +150,13 @@ export function getBlobMetadata (ctx: MeasureContext, attachment: Attachment): B
return undefined
}
}
// Define different time shifts for objects to ensure correct ordering
export enum MessageTimeShift {
Channel = -6,
MailTag = -5,
ThreadCard = -4,
Thread = -3,
Collaborator = -2,
Subject = -1
}