Properly prepare, await and hand response for sync message send
This commit is contained in:
parent
89d29b49a3
commit
5c0fcad6b1
3 changed files with 44 additions and 19 deletions
|
@ -1381,17 +1381,40 @@ export class ConversationModel extends window.Backbone.Model<
|
|||
}
|
||||
);
|
||||
|
||||
await wrap(
|
||||
window.textsecure.messaging.syncMessageRequestResponse(
|
||||
{
|
||||
threadE164: this.get('e164'),
|
||||
threadUuid: this.get('uuid'),
|
||||
groupId: this.get('groupId'),
|
||||
type: response,
|
||||
},
|
||||
sendOptions
|
||||
)
|
||||
);
|
||||
const groupId = this.get('groupId');
|
||||
let groupIdBuffer;
|
||||
if (groupId && this.isGroupV1()) {
|
||||
groupIdBuffer = fromEncodedBinaryToArrayBuffer(groupId);
|
||||
} else if (groupId && this.isGroupV2()) {
|
||||
groupIdBuffer = base64ToArrayBuffer(groupId);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
CallbackResultType,
|
||||
SendMetadataType,
|
||||
SendOptionsType,
|
||||
CustomError,
|
||||
} from './SendMessage';
|
||||
import {
|
||||
OutgoingIdentityKeyError,
|
||||
|
@ -44,7 +45,7 @@ export default class OutgoingMessage {
|
|||
|
||||
identifiersCompleted: number;
|
||||
|
||||
errors: Array<unknown>;
|
||||
errors: Array<CustomError>;
|
||||
|
||||
successfulIdentifiers: Array<unknown>;
|
||||
|
||||
|
|
|
@ -67,10 +67,15 @@ export type SendOptionsType = {
|
|||
online?: boolean;
|
||||
};
|
||||
|
||||
export interface CustomError extends Error {
|
||||
identifier?: string;
|
||||
number?: string;
|
||||
}
|
||||
|
||||
export type CallbackResultType = {
|
||||
successfulIdentifiers?: Array<any>;
|
||||
failoverIdentifiers?: Array<any>;
|
||||
errors?: Array<any>;
|
||||
errors?: Array<CustomError>;
|
||||
unidentifiedDeliveries?: Array<any>;
|
||||
dataMessage?: ArrayBuffer;
|
||||
discoveredIdentifierPairs: Array<{
|
||||
|
@ -1216,7 +1221,7 @@ export default class MessageSender {
|
|||
responseArgs: {
|
||||
threadE164?: string;
|
||||
threadUuid?: string;
|
||||
groupId?: string;
|
||||
groupId?: ArrayBuffer;
|
||||
type: number;
|
||||
},
|
||||
sendOptions?: SendOptionsType
|
||||
|
@ -1233,11 +1238,7 @@ export default class MessageSender {
|
|||
const response = new window.textsecure.protobuf.SyncMessage.MessageRequestResponse();
|
||||
response.threadE164 = responseArgs.threadE164;
|
||||
response.threadUuid = responseArgs.threadUuid;
|
||||
response.groupId = responseArgs.groupId
|
||||
? window.Signal.Crypto.fromEncodedBinaryToArrayBuffer(
|
||||
responseArgs.groupId
|
||||
)
|
||||
: null;
|
||||
response.groupId = responseArgs.groupId || null;
|
||||
response.type = responseArgs.type;
|
||||
syncMessage.messageRequestResponse = response;
|
||||
|
||||
|
|
Loading…
Reference in a new issue