Remove groups table, conversation is single source of truth

This commit is contained in:
Scott Nonnenberg 2019-02-11 15:59:21 -08:00
parent b69eea543c
commit 5b54c9554e
16 changed files with 214 additions and 912 deletions

View file

@ -210,14 +210,16 @@
sendTypingMessage(isTyping) {
const groupId = !this.isPrivate() ? this.id : null;
const recipientId = this.isPrivate() ? this.id : null;
const groupNumbers = this.getRecipients();
const sendOptions = this.getSendOptions();
this.wrapSend(
textsecure.messaging.sendTypingMessage(
{
groupId,
isTyping,
recipientId,
groupId,
groupNumbers,
},
sendOptions
)
@ -929,12 +931,36 @@
}
const conversationType = this.get('type');
const sendFunction = (() => {
const options = this.getSendOptions();
const groupNumbers = this.getRecipients();
const promise = (() => {
switch (conversationType) {
case Message.PRIVATE:
return textsecure.messaging.sendMessageToNumber;
return textsecure.messaging.sendMessageToNumber(
destination,
body,
attachmentsWithData,
quote,
preview,
now,
expireTimer,
profileKey,
options
);
case Message.GROUP:
return textsecure.messaging.sendMessageToGroup;
return textsecure.messaging.sendMessageToGroup(
destination,
groupNumbers,
body,
attachmentsWithData,
quote,
preview,
now,
expireTimer,
profileKey,
options
);
default:
throw new TypeError(
`Invalid conversation type: '${conversationType}'`
@ -942,22 +968,7 @@
}
})();
const options = this.getSendOptions();
return message.send(
this.wrapSend(
sendFunction(
destination,
body,
attachmentsWithData,
quote,
preview,
now,
expireTimer,
profileKey,
options
)
)
);
return message.send(this.wrapSend(promise));
});
},
@ -1239,25 +1250,31 @@
return message;
}
let sendFunc;
if (this.get('type') === 'private') {
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToNumber;
} else {
sendFunc = textsecure.messaging.sendExpirationTimerUpdateToGroup;
}
let profileKey;
if (this.get('profileSharing')) {
profileKey = storage.get('profileKey');
}
const sendOptions = this.getSendOptions();
const promise = sendFunc(
this.get('id'),
this.get('expireTimer'),
message.get('sent_at'),
profileKey,
sendOptions
);
let promise;
if (this.get('type') === 'private') {
promise = textsecure.messaging.sendExpirationTimerUpdateToNumber(
this.get('id'),
this.get('expireTimer'),
message.get('sent_at'),
profileKey,
sendOptions
);
} else {
promise = textsecure.messaging.sendExpirationTimerUpdateToGroup(
this.get('id'),
this.getRecipients(),
this.get('expireTimer'),
message.get('sent_at'),
profileKey,
sendOptions
);
}
await message.send(this.wrapSend(promise));
@ -1335,6 +1352,7 @@
async leaveGroup() {
const now = Date.now();
if (this.get('type') === 'group') {
const groupNumbers = this.getRecipients();
this.set({ left: true });
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
@ -1355,7 +1373,9 @@
const options = this.getSendOptions();
message.send(
this.wrapSend(textsecure.messaging.leaveGroup(this.id, options))
this.wrapSend(
textsecure.messaging.leaveGroup(this.id, groupNumbers, options)
)
);
}
},

View file

@ -706,21 +706,35 @@
this.isReplayableError.bind(this)
);
// Remove the errors that aren't replayable
// Put the errors back which aren't replayable
this.set({ errors });
const profileKey = null;
let numbers = retries
const conversation = this.getConversation();
const intendedRecipients = this.get('recipients') || [];
const currentRecipients = conversation.getRecipients();
const profileKey = conversation.get('profileSharing')
? storage.get('profileKey')
: null;
const errorNumbers = retries
.map(retry => retry.number)
.filter(item => Boolean(item));
let numbers = _.intersection(
errorNumbers,
intendedRecipients,
currentRecipients
);
if (!numbers.length) {
window.log.warn(
'retrySend: No numbers in error set, using all recipients'
);
const conversation = this.getConversation();
if (conversation) {
numbers = conversation.getRecipients();
numbers = _.intersection(currentRecipients, intendedRecipients);
// We clear all errors here to start with a fresh slate, since we are starting
// from scratch on this message with a fresh set of recipients
this.set({ errors: null });
} else {
throw new Error(
@ -752,7 +766,6 @@
}
let promise;
const conversation = this.getConversation();
const options = conversation.getSendOptions();
if (conversation.isPrivate()) {