|
1 | 1 | import Message from '../Message' |
2 | | -import Attachment from '../Attachment' |
3 | 2 | import parseXMAAttachment from '../attachments/parseXMAAttachment' |
4 | 3 | import parseBlobAttachment from '../attachments/parseBlobAttachment' |
| 4 | +import { Attachments } from '../attachments/parseAttachments' |
5 | 5 |
|
6 | 6 | export default function parseThreadMessage (threadId: string, message: any) { |
| 7 | + const { fileAttachments, mediaAttachments } = parseAttachments(message) |
7 | 8 | return { |
8 | 9 | id: message.message_id, |
9 | 10 | timestamp: Number(message.timestamp_precise), |
10 | 11 | authorId: message.message_sender ? message.message_sender.messaging_actor.id : '', |
11 | 12 | threadId, |
12 | 13 | message: message.message ? message.message.text : '', |
13 | | - attachments: parseAttachments(message), |
| 14 | + fileAttachments, |
| 15 | + mediaAttachments, |
14 | 16 | stickerId: message.sticker |
15 | 17 | } as Message |
16 | 18 | } |
17 | | -function parseAttachments (message: any): Attachment[] { |
18 | | - const attachments = message.blob_attachments ? message.blob_attachments.map(parseBlobAttachment) : [] |
| 19 | + |
| 20 | +function parseAttachments (message: any): Attachments { |
| 21 | + const fileAttachments = message.blob_attachments ? message.blob_attachments.map(parseBlobAttachment) : [] |
19 | 22 | // const attachments = message.blob_attachments ? message.blob_attachments : [] |
20 | 23 | const xma = message.extensible_attachment |
21 | | - if (xma) attachments.push(parseXMAAttachment({ [xma.id]: xma })) |
22 | | - return attachments |
| 24 | + const mediaAttachments = [] |
| 25 | + if (xma) mediaAttachments.push(parseXMAAttachment({ [xma.id]: xma })) |
| 26 | + return { fileAttachments, mediaAttachments } |
23 | 27 | } |
0 commit comments