import Payload from './Payload' ; import { Thrift , TCompactProtocol , Int64 } from 'thrift' ; import FacebookCapFlags from '../../types/FacebookCapFlags' ; import Long from 'long' ; import AuthTokens from '../../types/AuthTokens' ; import DeviceId from '../../types/DeviceId' ; export default class ConnectRequest extends Payload { deviceId : DeviceId ; tokens : AuthTokens ; userAgent : string ; constructor ( deviceId , tokens , userAgent ) { super ( ) ; this . deviceId = deviceId ; this . tokens = tokens ; this . userAgent = userAgent ; } encode ( proto ) { proto . writeFieldBegin ( 'clientIdentifier' , Thrift . Type . STRING , 1 ) ; proto . writeString ( this . deviceId . clientId ) ; proto . writeFieldBegin ( 'clientInfo' , Thrift . Type . STRUCT , 4 ) ; proto . writeStructBegin ( 'clientInfo' ) ; proto . writeFieldBegin ( 'userId' , Thrift . Type . I64 , 1 ) ; proto . writeI64 ( new Int64 ( Buffer . from ( Long . fromString ( this . tokens . uid . toString ( ) ) . toBytes ( ) ) ) ) ; proto . writeFieldBegin ( 'userAgent' , Thrift . Type . STRING , 2 ) ; proto . writeString ( this . userAgent ) ; proto . writeFieldBegin ( 'clientCapabilities' , Thrift . Type . I64 , 3 ) ; proto . writeI64 ( FacebookCapFlags . FB_CP_ACKNOWLEDGED_DELIVERY | FacebookCapFlags . FB_CP_PROCESSING_LASTACTIVE_PRESENCEINFO | FacebookCapFlags . FB_CP_EXACT_KEEPALIVE | FacebookCapFlags . FB_CP_LARGE_PAYLOAD_SUPPORTED | FacebookCapFlags . FB_CP_DELTA_SENT_MESSAGE_ENABLED ) ; proto . writeFieldBegin ( 'endpointCapabilities' , Thrift . Type . I64 , 4 ) ; proto . writeI64 ( 26 ) ; proto . writeFieldBegin ( 'publishFormat' , Thrift . Type . I32 , 5 ) ; proto . writeI32 ( 1 ) ; proto . writeFieldBegin ( 'noAutomaticForeground' , Thrift . Type . BOOL , 6 ) ; proto . writeBool ( false ) ; proto . writeFieldBegin ( 'makeUserAvailableInForeground' , Thrift . Type . BOOL , 7 ) ; proto . writeBool ( true ) ; proto . writeFieldBegin ( 'deviceId' , Thrift . Type . STRING , 8 ) ; proto . writeString ( this . deviceId . deviceId ) ; proto . writeFieldBegin ( 'isInitiallyForeground' , Thrift . Type . BOOL , 9 ) ; proto . writeBool ( true ) ; proto . writeFieldBegin ( 'networkType' , Thrift . Type . I32 , 10 ) ; proto . writeI32 ( 1 ) ; proto . writeFieldBegin ( 'networkSubtype' , Thrift . Type . I32 , 11 ) ; proto . writeI32 ( 0 ) ; proto . writeFieldBegin ( 'clientMqttSessionId' , Thrift . Type . I64 , 12 ) ; proto . writeI64 ( this . deviceId . mqttId ) ; const topics = [ ] ; proto . writeFieldBegin ( 'subscribeTopics' , Thrift . Type . LIST , 14 ) ; proto . writeListBegin ( Thrift . Type . I32 , topics . length ) ; { for ( const topic of topics ) { proto . writeI32 ( topic ) ; } } proto . writeFieldBegin ( 'clientType' , Thrift . Type . STRING , 15 ) ; proto . writeString ( '' ) ; proto . writeFieldBegin ( 'deviceSecret' , Thrift . Type . STRING , 20 ) ; proto . writeString ( '' ) ; proto . writeByte ( 0 ) ; proto . writeStructEnd ( ) ; proto . writeFieldBegin ( 'password' , Thrift . Type . STRING , 5 ) ; proto . writeString ( this . tokens . access_token ) ; proto . writeFieldBegin ( 'combinedPublishes' , Thrift . Type . LIST , 8 ) ; proto . writeListBegin ( Thrift . Type . STRUCT , 0 ) ; proto . writeFieldBegin ( 'phpOverride' , Thrift . Type . STRUCT , 11 ) ; proto . writeStructBegin ( 'phpOverride' ) ; proto . writeFieldBegin ( 'port' , Thrift . Type . I32 , 2 ) ; proto . writeI32 ( 0 ) ; proto . writeByte ( 0 ) ; proto . writeStructEnd ( ) ; proto . writeByte ( 0 ) ; return null ; } }