import { proteus as ProtobufOTR } from '@wireapp/protocol-messaging/web/otr' ; import type { AxiosRequestConfig } from 'axios' ; import { ValidationError } from '../validation/' ; import type { ClientMismatch , NewOTRMessage } from '../conversation/' ; import type { HttpClient } from '../http/' ; export class BroadcastAPI { constructor ( private readonly client ) { } public static readonly URL = { BROADCAST : '/broadcast/otr/messages' , } ; param sendingClientId param messageData param ignoreMissing see https public async postBroadcastMessage ( sendingClientId , messageData , ignoreMissing ? ) { if ( ! sendingClientId ) { throw new ValidationError ( 'Unable to send OTR message without client ID.' ) ; } const config = { data : messageData , method : 'post' , url : BroadcastAPI . URL . BROADCAST , } ; if ( typeof ignoreMissing !== 'undefined' ) { const ignore_missing = Array . isArray ( ignoreMissing ) ? ignoreMissing . join ( ',' ) : ignoreMissing ; config . params = { ignore_missing } ; delete messageData . report_missing ; } else if ( typeof messageData . report_missing === 'undefined' ) { config . params = { ignore_missing : ! ! messageData . data } ; } const response = await this . client . sendJSON < ClientMismatch > ( config ) ; return response . data ; } param sendingClientId param messageData param ignoreMissing see https public async postBroadcastProtobufMessage ( sendingClientId , messageData , ignoreMissing ? ) { if ( ! sendingClientId ) { throw new ValidationError ( 'Unable to send OTR message without client ID.' ) ; } const config = { data : ProtobufOTR . NewOtrMessage . encode ( messageData ) . finish ( ) , method : 'post' , url : BroadcastAPI . URL . BROADCAST , } ; if ( typeof ignoreMissing !== 'undefined' ) { const ignore_missing = Array . isArray ( ignoreMissing ) ? ignoreMissing . join ( ',' ) : ignoreMissing ; config . params = { ignore_missing } ; messageData . reportMissing = [ ] ; } else if ( typeof messageData . reportMissing === 'undefined' || ! messageData . reportMissing . length ) { config . params = { ignore_missing : ! ! messageData . blob } ; } const response = await this . client . sendProtocolBuffer < ClientMismatch > ( config ) ; return response . data ; } }