Send sync sent messages properly in 1-member group

pull/272/head
Scott Nonnenberg 6 years ago
parent a7d0e6bf88
commit 32fa5cccde

@ -272,9 +272,12 @@
this.hasExpired = true; this.hasExpired = true;
}, },
getPropsForTimerNotification() { getPropsForTimerNotification() {
const { expireTimer, fromSync, source } = this.get( const timerUpdate = this.get('expirationTimerUpdate');
'expirationTimerUpdate' if (!timerUpdate) {
); return null;
}
const { expireTimer, fromSync, source } = timerUpdate;
const timespan = Whisper.ExpirationTimerOptions.getName(expireTimer || 0); const timespan = Whisper.ExpirationTimerOptions.getName(expireTimer || 0);
const disabled = !expireTimer; const disabled = !expireTimer;

@ -27,11 +27,11 @@ function Message(options) {
this.expireTimer = options.expireTimer; this.expireTimer = options.expireTimer;
this.profileKey = options.profileKey; this.profileKey = options.profileKey;
if (!(this.recipients instanceof Array) || this.recipients.length < 1) { if (!(this.recipients instanceof Array)) {
throw new Error('Invalid recipient list'); throw new Error('Invalid recipient list');
} }
if (!this.group && this.recipients.length > 1) { if (!this.group && this.recipients.length !== 1) {
throw new Error('Invalid recipient list for non-group'); throw new Error('Invalid recipient list for non-group');
} }
@ -739,6 +739,7 @@ MessageSender.prototype = {
failoverNumbers: [], failoverNumbers: [],
errors: [], errors: [],
unidentifiedDeliveries: [], unidentifiedDeliveries: [],
dataMessage: proto.toArrayBuffer(),
}); });
} }
@ -787,6 +788,10 @@ MessageSender.prototype = {
flags, flags,
}; };
return this.getMessageProtoObj(attributes);
},
async getMessageProtoObj(attributes) {
const message = new Message(attributes); const message = new Message(attributes);
await Promise.all([ await Promise.all([
this.uploadAttachments(message), this.uploadAttachments(message),
@ -893,7 +898,7 @@ MessageSender.prototype = {
return Promise.all([sendToContactPromise, sendSyncPromise]); return Promise.all([sendToContactPromise, sendSyncPromise]);
}, },
sendMessageToGroup( async sendMessageToGroup(
groupId, groupId,
groupNumbers, groupNumbers,
messageText, messageText,
@ -907,33 +912,33 @@ MessageSender.prototype = {
) { ) {
const me = textsecure.storage.user.getNumber(); const me = textsecure.storage.user.getNumber();
const numbers = groupNumbers.filter(number => number !== me); const numbers = groupNumbers.filter(number => number !== me);
const attrs = {
recipients: numbers,
body: messageText,
timestamp,
attachments,
quote,
preview,
needsSync: true,
expireTimer,
profileKey,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
};
if (numbers.length === 0) { if (numbers.length === 0) {
return Promise.resolve({ return Promise.resolve({
successfulNumbers: [], successfulNumbers: [],
failoverNumbers: [], failoverNumbers: [],
errors: [], errors: [],
unidentifiedDeliveries: [], unidentifiedDeliveries: [],
dataMessage: await this.getMessageProtoObj(attrs),
}); });
} }
return this.sendMessage( return this.sendMessage(attrs, options);
{
recipients: numbers,
body: messageText,
timestamp,
attachments,
quote,
preview,
needsSync: true,
expireTimer,
profileKey,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
},
options
);
}, },
createGroup(targetNumbers, id, name, avatar, options) { createGroup(targetNumbers, id, name, avatar, options) {
@ -1016,7 +1021,7 @@ MessageSender.prototype = {
proto.group.type = textsecure.protobuf.GroupContext.Type.QUIT; proto.group.type = textsecure.protobuf.GroupContext.Type.QUIT;
return this.sendGroupProto(groupNumbers, proto, Date.now(), options); return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
}, },
sendExpirationTimerUpdateToGroup( async sendExpirationTimerUpdateToGroup(
groupId, groupId,
groupNumbers, groupNumbers,
expireTimer, expireTimer,
@ -1026,30 +1031,30 @@ MessageSender.prototype = {
) { ) {
const me = textsecure.storage.user.getNumber(); const me = textsecure.storage.user.getNumber();
const numbers = groupNumbers.filter(number => number !== me); const numbers = groupNumbers.filter(number => number !== me);
const attrs = {
recipients: numbers,
timestamp,
needsSync: true,
expireTimer,
profileKey,
flags: textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
};
if (numbers.length === 0) { if (numbers.length === 0) {
return Promise.resolve({ return Promise.resolve({
successfulNumbers: [], successfulNumbers: [],
failoverNumbers: [], failoverNumbers: [],
errors: [], errors: [],
unidentifiedDeliveries: [], unidentifiedDeliveries: [],
dataMessage: await this.getMessageProtoObj(attrs),
}); });
} }
return this.sendMessage( return this.sendMessage(attrs, options);
{
recipients: numbers,
timestamp,
needsSync: true,
expireTimer,
profileKey,
flags: textsecure.protobuf.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
},
options
);
}, },
sendExpirationTimerUpdateToNumber( sendExpirationTimerUpdateToNumber(
number, number,

Loading…
Cancel
Save