Skip to content

Commit bb34728

Browse files
author
Bjornskjald
committed
Split attachments into file and media attachments
1 parent d62e253 commit bb34728

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

src/types/Attachment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export default interface Attachment {
33
}
44
export * from './attachments/XMAAttachment'
55
export * from './attachments/FileAttachment'
6-
export { default as parseAttachment } from './attachments/parseAttachment'
6+
export { default as parseAttachments } from './attachments/parseAttachments'

src/types/attachments/parseAttachment.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import parseFileAttachment from './parseFileAttachment'
2+
import parseBlobAttachment from './parseBlobAttachment'
3+
import parseXMAAttachment from './parseXMAAttachment'
4+
import { FileAttachment, XMAAttachment } from '../Attachment'
5+
6+
interface Attachments {
7+
fileAttachments: FileAttachment[],
8+
mediaAttachments: XMAAttachment[]
9+
}
10+
11+
export default function parseAttachments (attachments: any[]): Attachments {
12+
const result: Attachments = {
13+
fileAttachments: [],
14+
mediaAttachments: []
15+
}
16+
for (let attachment of attachments) {
17+
if (attachment.mimeType) result.fileAttachments.push(parseFileAttachment(attachment))
18+
if (attachment.mimetype) result.fileAttachments.push(parseBlobAttachment(attachment))
19+
if (attachment.xmaGraphQL) result.mediaAttachments.push(parseXMAAttachment(JSON.parse(attachment.xmaGraphQL)))
20+
result.mediaAttachments.push({
21+
type: 'Unknown',
22+
...attachment
23+
})
24+
}
25+
return result
26+
}

src/types/message/parseDeltaMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { parseAttachment } from '../Attachment'
1+
import { parseAttachments } from '../Attachment'
22
import Message, { Mention } from '../Message'
33

44
export default function parseDeltaMessage (delta: any) {
55
return {
66
threadId: getThreadId(delta),
7-
attachments: delta.attachments ? delta.attachments.map(parseAttachment) : [],
7+
attachments: delta.attachments ? parseAttachments(delta.attachments) : [],
88
authorId: delta.messageMetadata.actorFbId,
99
id: delta.messageMetadata.messageId,
1010
timestamp: delta.messageMetadata.timestamp,

0 commit comments

Comments
 (0)