Skip to content

Commit

Permalink
Send sync sent messages properly in 1-member group
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Mar 13, 2019
1 parent a7d0e6b commit 32fa5cc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
9 changes: 6 additions & 3 deletions js/models/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,12 @@
this.hasExpired = true;
},
getPropsForTimerNotification() {
const { expireTimer, fromSync, source } = this.get(
'expirationTimerUpdate'
);
const timerUpdate = this.get('expirationTimerUpdate');
if (!timerUpdate) {
return null;
}

const { expireTimer, fromSync, source } = timerUpdate;
const timespan = Whisper.ExpirationTimerOptions.getName(expireTimer || 0);
const disabled = !expireTimer;

Expand Down
79 changes: 42 additions & 37 deletions libtextsecure/sendmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function Message(options) {
this.expireTimer = options.expireTimer;
this.profileKey = options.profileKey;

if (!(this.recipients instanceof Array) || this.recipients.length < 1) {
if (!(this.recipients instanceof Array)) {
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');
}

Expand Down Expand Up @@ -739,6 +739,7 @@ MessageSender.prototype = {
failoverNumbers: [],
errors: [],
unidentifiedDeliveries: [],
dataMessage: proto.toArrayBuffer(),
});
}

Expand Down Expand Up @@ -787,6 +788,10 @@ MessageSender.prototype = {
flags,
};

return this.getMessageProtoObj(attributes);
},

async getMessageProtoObj(attributes) {
const message = new Message(attributes);
await Promise.all([
this.uploadAttachments(message),
Expand Down Expand Up @@ -893,7 +898,7 @@ MessageSender.prototype = {
return Promise.all([sendToContactPromise, sendSyncPromise]);
},

sendMessageToGroup(
async sendMessageToGroup(
groupId,
groupNumbers,
messageText,
Expand All @@ -907,33 +912,33 @@ MessageSender.prototype = {
) {
const me = textsecure.storage.user.getNumber();
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) {
return Promise.resolve({
successfulNumbers: [],
failoverNumbers: [],
errors: [],
unidentifiedDeliveries: [],
dataMessage: await this.getMessageProtoObj(attrs),
});
}

return this.sendMessage(
{
recipients: numbers,
body: messageText,
timestamp,
attachments,
quote,
preview,
needsSync: true,
expireTimer,
profileKey,
group: {
id: groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
},
options
);
return this.sendMessage(attrs, options);
},

createGroup(targetNumbers, id, name, avatar, options) {
Expand Down Expand Up @@ -1016,7 +1021,7 @@ MessageSender.prototype = {
proto.group.type = textsecure.protobuf.GroupContext.Type.QUIT;
return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
},
sendExpirationTimerUpdateToGroup(
async sendExpirationTimerUpdateToGroup(
groupId,
groupNumbers,
expireTimer,
Expand All @@ -1026,30 +1031,30 @@ MessageSender.prototype = {
) {
const me = textsecure.storage.user.getNumber();
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) {
return Promise.resolve({
successfulNumbers: [],
failoverNumbers: [],
errors: [],
unidentifiedDeliveries: [],
dataMessage: await this.getMessageProtoObj(attrs),
});
}

return this.sendMessage(
{
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
);
return this.sendMessage(attrs, options);
},
sendExpirationTimerUpdateToNumber(
number,
Expand Down

0 comments on commit 32fa5cc

Please sign in to comment.