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)
)
);
}
},