Skip to content

Commit 0f6a848

Browse files
author
Bjornskjald
committed
2.3.0: Fixed errors with attachments
2 parents 24db6cf + 55d6a00 commit 0f6a848

File tree

8 files changed

+83
-67
lines changed

8 files changed

+83
-67
lines changed

package-lock.json

Lines changed: 42 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libfb",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Facebook MQTT library for Node.js",
55
"repository": "https://github.com/ChatPlug/libfb-js",
66
"main": "dist/index.js",
@@ -25,28 +25,28 @@
2525
"node-fetch": "^2.6.0",
2626
"strict-event-emitter-types": "^2.0.0",
2727
"thrift": "^0.12.0",
28-
"tslib": "^1.9.3"
28+
"tslib": "^1.10.0"
2929
},
3030
"devDependencies": {
3131
"@types/chai": "^4.1.7",
3232
"@types/debug": "^4.1.4",
3333
"@types/long": "^4.0.0",
3434
"@types/mocha": "^5.2.7",
35-
"@types/node": "^12.0.4",
36-
"@types/node-fetch": "^2.3.4",
35+
"@types/node": "^12.0.10",
36+
"@types/node-fetch": "^2.3.7",
3737
"@types/node-int64": "^0.4.29",
3838
"@types/thrift": "^0.10.8",
3939
"chai": "^4.2.0",
40-
"console-stamp": "^0.2.7",
40+
"console-stamp": "^0.2.9",
4141
"mocha": "^6.1.4",
4242
"shx": "^0.3.2",
43-
"ts-node": "^8.2.0",
44-
"tslint": "^5.17.0",
43+
"ts-node": "^8.3.0",
44+
"tslint": "^5.18.0",
4545
"tslint-config-standard": "^8.0.1",
4646
"typedoc": "^0.14.2",
4747
"typedoc-plugin-as-member-of": "^1.0.2",
4848
"typedoc-plugin-sourcefile-url": "^1.0.4",
49-
"typescript": "^3.5.1"
49+
"typescript": "^3.5.2"
5050
},
5151
"license": "MIT"
5252
}

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/XMAAttachment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface XMAAttachment extends Attachment {
2626
export interface UnavailableXMA extends XMAAttachment {
2727
type: 'UnavailableXMA'
2828
message: string
29+
attach: any
2930
}
3031
export interface StoryXMA extends XMAAttachment {
3132
type: 'StoryXMA'

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/attachments/parseXMAAttachment.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import vm from 'vm'
1111

1212
export default function parseXMAAttachment (attach: any) {
1313
attach = attach[Object.keys(attach)[0]].story_attachment
14-
if (!attach.target) {
14+
if (!attach.target || !attach.target.__type__) {
1515
return {
1616
type: 'UnavailableXMA',
17-
message: attach.description.text
17+
message: attach.description.text,
18+
attach
1819
} as UnavailableXMA
1920
}
2021
const type = attach.target.__type__.name

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)