Properly prepare, await and hand response for sync message send

This commit is contained in:
Scott Nonnenberg 2020-10-24 08:11:18 -07:00
parent 89d29b49a3
commit 5c0fcad6b1
3 changed files with 44 additions and 19 deletions

View file

@ -1381,17 +1381,40 @@ export class ConversationModel extends window.Backbone.Model<
} }
); );
await wrap( const groupId = this.get('groupId');
window.textsecure.messaging.syncMessageRequestResponse( let groupIdBuffer;
{ if (groupId && this.isGroupV1()) {
threadE164: this.get('e164'), groupIdBuffer = fromEncodedBinaryToArrayBuffer(groupId);
threadUuid: this.get('uuid'), } else if (groupId && this.isGroupV2()) {
groupId: this.get('groupId'), groupIdBuffer = base64ToArrayBuffer(groupId);
type: response, }
},
sendOptions try {
) await wrap(
); window.textsecure.messaging.syncMessageRequestResponse(
{
threadE164: this.get('e164'),
threadUuid: this.get('uuid'),
groupId: groupIdBuffer,
type: response,
},
sendOptions
)
);
} catch (result) {
if (result instanceof Error) {
throw result;
} else if (result && result.errors) {
// We filter out unregistered user errors, because we ignore those in groups
const wasThereARealError = window._.some(
result.errors,
error => error.name !== 'UnregisteredUserError'
);
if (wasThereARealError) {
throw result;
}
}
}
} }
onMessageError(): void { onMessageError(): void {

View file

@ -14,6 +14,7 @@ import {
CallbackResultType, CallbackResultType,
SendMetadataType, SendMetadataType,
SendOptionsType, SendOptionsType,
CustomError,
} from './SendMessage'; } from './SendMessage';
import { import {
OutgoingIdentityKeyError, OutgoingIdentityKeyError,
@ -44,7 +45,7 @@ export default class OutgoingMessage {
identifiersCompleted: number; identifiersCompleted: number;
errors: Array<unknown>; errors: Array<CustomError>;
successfulIdentifiers: Array<unknown>; successfulIdentifiers: Array<unknown>;

View file

@ -67,10 +67,15 @@ export type SendOptionsType = {
online?: boolean; online?: boolean;
}; };
export interface CustomError extends Error {
identifier?: string;
number?: string;
}
export type CallbackResultType = { export type CallbackResultType = {
successfulIdentifiers?: Array<any>; successfulIdentifiers?: Array<any>;
failoverIdentifiers?: Array<any>; failoverIdentifiers?: Array<any>;
errors?: Array<any>; errors?: Array<CustomError>;
unidentifiedDeliveries?: Array<any>; unidentifiedDeliveries?: Array<any>;
dataMessage?: ArrayBuffer; dataMessage?: ArrayBuffer;
discoveredIdentifierPairs: Array<{ discoveredIdentifierPairs: Array<{
@ -1216,7 +1221,7 @@ export default class MessageSender {
responseArgs: { responseArgs: {
threadE164?: string; threadE164?: string;
threadUuid?: string; threadUuid?: string;
groupId?: string; groupId?: ArrayBuffer;
type: number; type: number;
}, },
sendOptions?: SendOptionsType sendOptions?: SendOptionsType
@ -1233,11 +1238,7 @@ export default class MessageSender {
const response = new window.textsecure.protobuf.SyncMessage.MessageRequestResponse(); const response = new window.textsecure.protobuf.SyncMessage.MessageRequestResponse();
response.threadE164 = responseArgs.threadE164; response.threadE164 = responseArgs.threadE164;
response.threadUuid = responseArgs.threadUuid; response.threadUuid = responseArgs.threadUuid;
response.groupId = responseArgs.groupId response.groupId = responseArgs.groupId || null;
? window.Signal.Crypto.fromEncodedBinaryToArrayBuffer(
responseArgs.groupId
)
: null;
response.type = responseArgs.type; response.type = responseArgs.type;
syncMessage.messageRequestResponse = response; syncMessage.messageRequestResponse = response;