Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/api-client/src/APIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class APIClient extends EventEmitter {
}

private configureApis(backendFeatures: BackendFeatures): Apis {
this.logger.info('configuring APIs with config', backendFeatures);
return {
account: new AccountAPI(this.transport.http),
asset: new AssetAPI(this.transport.http),
Expand Down Expand Up @@ -242,9 +243,7 @@ export class APIClient extends EventEmitter {
}
let backendVersions: BackendVersionResponse = {supported: [0]};
try {
backendVersions = await (
await this.transport.http.sendRequest<BackendVersionResponse>({url: '/api-version'})
).data;
backendVersions = (await this.transport.http.sendRequest<BackendVersionResponse>({url: '/api-version'})).data;
} catch (error) {}
const highestCommonVersion = backendVersions.supported
.sort()
Expand Down
27 changes: 26 additions & 1 deletion packages/api-client/src/broadcast/BroadcastAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ 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 {ClientMismatch, MessageSendingStatus, NewOTRMessage} from '../conversation/';
import type {HttpClient} from '../http/';

export class BroadcastAPI {
constructor(private readonly client: HttpClient) {}

public static readonly URL = {
BROADCAST: '/broadcast/otr/messages',
BROADCAST_FEDERATED: '/broadcast/proteus/messages',
};

/**
Expand Down Expand Up @@ -114,4 +115,28 @@ export class BroadcastAPI {
const response = await this.client.sendProtocolBuffer<ClientMismatch>(config);
return response.data;
}

/**
* Broadcast an encrypted message to all team members and all contacts in federated environments
* @param sendingClientId The sender's client ID
* @param messageData The message content
* @see https://staging-nginz-https.zinfra.io/swagger-ui/tab.html#!/postOtrBroadcast
*/
public async postBroadcastFederatedMessage(
sendingClientId: string,
messageData: ProtobufOTR.QualifiedNewOtrMessage,
): Promise<MessageSendingStatus> {
if (!sendingClientId) {
throw new ValidationError('Unable to send OTR message without client ID.');
}

const config: AxiosRequestConfig = {
data: ProtobufOTR.QualifiedNewOtrMessage.encode(messageData).finish().slice(),
method: 'post',
url: BroadcastAPI.URL.BROADCAST_FEDERATED,
};

const response = await this.client.sendProtocolBuffer<MessageSendingStatus>(config);
return response.data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ export class MessageService {
}

if (!options.conversationId) {
//TODO implement federated broadcast sending
throw new Error('Unimplemented federated broadcast');
return this.apiClient.api.broadcast.postBroadcastFederatedMessage(sendingClientId, protoMessage);
}

const {id, domain} = options.conversationId;
Expand Down