Skip to content

Commit dff81c2

Browse files
author
Bjornskjald
committed
2.3.1: Fixed format of attachments
2 parents 0f6a848 + 7c1e9f2 commit dff81c2

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libfb",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "Facebook MQTT library for Node.js",
55
"repository": "https://github.com/ChatPlug/libfb-js",
66
"main": "dist/index.js",

src/types/Message.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import Attachment from './Attachment'
1+
import { FileAttachment, XMAAttachment } from './Attachment'
22

33
export default interface Message {
44
id: string
55
timestamp: number
66
authorId: string
77
threadId: string
88
message: string
9-
attachments: Attachment[]
9+
fileAttachments: FileAttachment[],
10+
mediaAttachments: XMAAttachment[]
1011
stickerId?: number,
1112
mentions?: Mention[]
1213
}

src/types/attachments/parseAttachments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import parseBlobAttachment from './parseBlobAttachment'
33
import parseXMAAttachment from './parseXMAAttachment'
44
import { FileAttachment, XMAAttachment } from '../Attachment'
55

6-
interface Attachments {
6+
export interface Attachments {
77
fileAttachments: FileAttachment[],
88
mediaAttachments: XMAAttachment[]
99
}

src/types/message/parseDeltaMessage.ts

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

44
export default function parseDeltaMessage (delta: any) {
5+
const { fileAttachments, mediaAttachments } = parseAttachments(delta.attachments || [])
56
return {
67
threadId: getThreadId(delta),
7-
attachments: delta.attachments ? parseAttachments(delta.attachments) : [],
8+
fileAttachments,
9+
mediaAttachments,
810
authorId: delta.messageMetadata.actorFbId,
911
id: delta.messageMetadata.messageId,
1012
timestamp: delta.messageMetadata.timestamp,
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import Message from '../Message'
2-
import Attachment from '../Attachment'
32
import parseXMAAttachment from '../attachments/parseXMAAttachment'
43
import parseBlobAttachment from '../attachments/parseBlobAttachment'
4+
import { Attachments } from '../attachments/parseAttachments'
55

66
export default function parseThreadMessage (threadId: string, message: any) {
7+
const { fileAttachments, mediaAttachments } = parseAttachments(message)
78
return {
89
id: message.message_id,
910
timestamp: Number(message.timestamp_precise),
1011
authorId: message.message_sender ? message.message_sender.messaging_actor.id : '',
1112
threadId,
1213
message: message.message ? message.message.text : '',
13-
attachments: parseAttachments(message),
14+
fileAttachments,
15+
mediaAttachments,
1416
stickerId: message.sticker
1517
} as Message
1618
}
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) : []
1922
// const attachments = message.blob_attachments ? message.blob_attachments : []
2023
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 }
2327
}

0 commit comments

Comments
 (0)