ChatPlug / libfb-js

Messenger's MQTT implementation
GNU General Public License v2.0
60 stars 12 forks source link

Modified queue creation to receive more delta messages #65

Closed Nordskog closed 5 years ago

Nordskog commented 5 years ago

Mqtt messages send to /messenger_sync_create_queue and /messenger_sync_get_diffs modified so we receive /t_ms delta messages we did not receive before, such as messages removals, replies, and reactions.

The addition of client_delta_sync_bitmask: 'Amvr2dBlf7PNgA' to the message sent in createQueue() is the most important bit, but the rest was copied mostly verbatim as well.

This bitmask comes from an array of numbers ranging from 0 to 67, when is then encoded into a byte bitmask, and finally byte64 encoded. We have no way of knowing what the individual flags means, so it is copied as-is.

Both messages include a sync_api_version value. The queue must be created with a value of 3 to receive json payloads rather than thrift, and must be connected to with 10 to receive all messages ( reactions and message removals, for instance, as otherwise omitted ).

Below are a few examples of the messages received

Message removal:

{
    "deltas": [{
            "deltaReplaceMessage": {
                "newMessage": {
                    "messageMetadata": {
                        "threadKey": {
                            "otherUserFbId": 100035639611682
                        },
                        "messageId": "mid.$cAAAAAAwhQ9ZxTE2UzVrGwhH0wqwr",
                        "actorFbId": 100035639611682,
                        "timestamp": 1559526657229,
                        "shouldBuzzDevice": 1,
                        "unsendType": "deny_for_non_sender",
                        "snippet": "John removed a message"
                    },
                    "attachments": [{
                            "id": "ee.mid.$cAAAAAAwhQ9ZxTE2UzVrGwhH0wqwr",
                            "xmaGraphQL": "{\"ZXh0ZW5zaWJsZV9tZXNzYWdlX2F0dGFjaG1lbnQ6ZWUubWlkLiRjQUFBQUFBd2hROVp4VEUyVXpWckd3aEgwd3F3cg\":{\"__typename\":\"ExtensibleMessageAttachment\",\"id\":\"ZXh0ZW5zaWJsZV9tZXNzYWdlX2F0dGFjaG1lbnQ6ZWUubWlkLiRjQUFBQUFBd2hROVp4VEUyVXpWckd3aEgwd3F3cg\",\"story_attachment\":{\"title_with_entities\":{\"text\":\"\"},\"style_list\":[\"globally_deleted_message_placeholder\",\"fallback\"],\"title\":\"\",\"description\":{\"text\":\"John Alcefcifaafhb Putnamberg removed a message\"},\"deduplication_key\":\"06381818e872aab70d7ab1a5eb31629f\"},\"genie_attachment\":{}}}"
                        }
                    ]
                },
                "replacedMessageId": "mid.$cAAAAAAwhQ9ZxTE2UzVrGwhH0wqwr"
            }
        }
    ],
    "firstDeltaSeqId": 1731,
    "lastIssuedSeqId": 1731
}

Message reply:

Nothing immediately identifying it as a reply. Libfb parses it as a normal message at the moment.

{
    "deltas": [{
            "deltaNewMessage": {
                "messageMetadata": {
                    "threadKey": {
                        "otherUserFbId": 100035639611682
                    },
                    "messageId": "mid.$cAAAAAAwhQ9ZxTCpotlrGuUb5ZeMs",
                    "offlineThreadingId": 6541119223285277484,
                    "actorFbId": 100035639611682,
                    "timestamp": 1559524352182,
                    "shouldBuzzDevice": 1,
                    "tags": ["source:messenger:web"],
                    "threadReadStateEffect": 2,
                    "skipSnippetUpdate": 0,
                    "unsendType": "deny_for_non_sender"
                },
                "body": "I am a reply!",
                "attachments": []
            }
        }
    ],
    "firstDeltaSeqId": 1703,
    "lastIssuedSeqId": 1703
}

Reactions:

Reactions are a bit strange, in that they contain a delta with a thrift-encoded payload written to a string. This will require special handling.

{
    "deltas": [{
            "deltaClientPayload": {
                "payload": "\u0019\u001c�\u001c\u0016�Ĝ��-\u0000\u0018\"mid.$cAAAAAAwhQ9ZxTDqZPQAAAAAI6QBn\u0015\u0000\u0016�Ĝ��-\u0018\u0004�😍\u0016�˖��-\u0018\t
                9487719\u0000\u0000\u0000"
            }
        }
    ],
    "firstDeltaSeqId": 1725,
    "lastIssuedSeqId": 1725
}

The decoded payload. Note that some of the property names are incorrect, as they are automated best-guesses made by comparing the structure to other thrift payloads.

Object
    {
        #1 additional_contacts ( List of struct ): 
            [Object
            {
                #10 ( struct ): Object
                {
                    #1 threadKey ( struct ): Object
                    {
                        #1 userId ( i64 ): 100035639611682

                    }
                    #2 messageId ( string ): "mid.$cAAAAAAwhQ9ZxPEQ7ZgAAAAB98MxR"( 6D69642E2463414141414141776851395A78504551375A67414141414239384D7852 )
                    #3 action ( i32 ): 0
                    #4 userId ( i64 ): 100035639611682
                    #5 reaction ( string ): "😠"( F09F98A0 )
                    #6 senderId ( i64 ): 100035440333556
                    #7 offlineThreadingId ( string ): "2112932945"( 32313132393332393435 )
                }
            }
            ]
    }