@@ -44,7 +44,7 @@ import { generateMessageId } from '@hcengineering/communication-shared'
44
44
45
45
import { BaseConfig , type Attachment } from './types'
46
46
import { EmailMessage , MailRecipient , MessageData } from './types'
47
- import { getMdContent } from './utils'
47
+ import { getBlobMetadata , getMdContent } from './utils'
48
48
import { PersonCacheFactory } from './person'
49
49
import { PersonSpacesCacheFactory } from './personSpaces'
50
50
import { ChannelCache , ChannelCacheFactory } from './channel'
@@ -252,11 +252,11 @@ async function saveMessageToSpaces (
252
252
}
253
253
254
254
const messageId = await createMailMessage ( producer , config , messageData , threadId )
255
+ await createFiles ( ctx , producer , config , attachments , messageData , threadId , messageId )
255
256
if ( ! isReply ) {
256
257
await addCollaborators ( producer , config , messageData , threadId )
257
258
await createMailThread ( producer , config , messageData , messageId )
258
259
}
259
- await createFiles ( producer , config , attachments , messageData , threadId , messageId )
260
260
261
261
await threadLookup . setThreadId ( mailId , space . _id , threadId )
262
262
} )
@@ -305,6 +305,7 @@ async function createMailMessage (
305
305
}
306
306
307
307
async function createFiles (
308
+ ctx : MeasureContext ,
308
309
producer : Producer ,
309
310
config : BaseConfig ,
310
311
attachments : Attachment [ ] ,
@@ -313,20 +314,21 @@ async function createFiles (
313
314
messageId : MessageID
314
315
) : Promise < void > {
315
316
const fileData : Buffer [ ] = attachments . map ( ( a ) => {
316
- const creeateFileEvent : CreateFileEvent = {
317
+ const createFileEvent : CreateFileEvent = {
317
318
type : MessageRequestEventType . CreateFile ,
318
- card : threadId ,
319
+ card : messageData . isReply ? threadId : messageData . channel ,
319
320
message : messageId ,
320
321
messageCreated : messageData . created ,
321
322
creator : messageData . modifiedBy ,
322
323
data : {
323
324
blobId : a . id as Ref < Blob > ,
324
325
type : a . contentType ,
325
326
filename : a . name ,
326
- size : a . data . length
327
+ size : a . data . length ,
328
+ meta : getBlobMetadata ( ctx , a )
327
329
}
328
330
}
329
- return Buffer . from ( JSON . stringify ( creeateFileEvent ) )
331
+ return Buffer . from ( JSON . stringify ( createFileEvent ) )
330
332
} )
331
333
const fileEvents = fileData . map ( ( data ) => ( {
332
334
key : Buffer . from ( messageData . channel ?? messageData . spaceId ) ,
0 commit comments