Remove groups table, conversation is single source of truth
This commit is contained in:
parent
b69eea543c
commit
5b54c9554e
16 changed files with 214 additions and 912 deletions
|
@ -560,7 +560,7 @@ MessageSender.prototype = {
|
|||
|
||||
async sendTypingMessage(options = {}, sendOptions = {}) {
|
||||
const ACTION_ENUM = textsecure.protobuf.TypingMessage.Action;
|
||||
const { recipientId, groupId, isTyping, timestamp } = options;
|
||||
const { recipientId, groupId, groupNumbers, isTyping, timestamp } = options;
|
||||
|
||||
// We don't want to send typing messages to our other devices, but we will
|
||||
// in the group case.
|
||||
|
@ -574,7 +574,7 @@ MessageSender.prototype = {
|
|||
}
|
||||
|
||||
const recipients = groupId
|
||||
? _.without(await textsecure.storage.groups.getNumbers(groupId), myNumber)
|
||||
? _.without(groupNumbers, myNumber)
|
||||
: [recipientId];
|
||||
const groupIdBuffer = groupId
|
||||
? window.Signal.Crypto.fromEncodedBinaryToArrayBuffer(groupId)
|
||||
|
@ -882,6 +882,7 @@ MessageSender.prototype = {
|
|||
|
||||
sendMessageToGroup(
|
||||
groupId,
|
||||
groupNumbers,
|
||||
messageText,
|
||||
attachments,
|
||||
quote,
|
||||
|
@ -891,59 +892,50 @@ MessageSender.prototype = {
|
|||
profileKey,
|
||||
options
|
||||
) {
|
||||
return textsecure.storage.groups.getNumbers(groupId).then(targetNumbers => {
|
||||
if (targetNumbers === undefined) {
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
}
|
||||
const me = textsecure.storage.user.getNumber();
|
||||
const numbers = groupNumbers.filter(number => number !== me);
|
||||
if (numbers.length === 0) {
|
||||
return Promise.reject(new Error('No other members in the group'));
|
||||
}
|
||||
|
||||
const me = textsecure.storage.user.getNumber();
|
||||
const numbers = targetNumbers.filter(number => number !== me);
|
||||
if (numbers.length === 0) {
|
||||
return Promise.reject(new Error('No other members in the group'));
|
||||
}
|
||||
|
||||
return this.sendMessage(
|
||||
{
|
||||
recipients: numbers,
|
||||
body: messageText,
|
||||
timestamp,
|
||||
attachments,
|
||||
quote,
|
||||
preview,
|
||||
needsSync: true,
|
||||
expireTimer,
|
||||
profileKey,
|
||||
group: {
|
||||
id: groupId,
|
||||
type: textsecure.protobuf.GroupContext.Type.DELIVER,
|
||||
},
|
||||
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
|
||||
);
|
||||
});
|
||||
},
|
||||
options
|
||||
);
|
||||
},
|
||||
|
||||
createGroup(targetNumbers, name, avatar, options) {
|
||||
createGroup(targetNumbers, id, name, avatar, options) {
|
||||
const proto = new textsecure.protobuf.DataMessage();
|
||||
proto.group = new textsecure.protobuf.GroupContext();
|
||||
proto.group.id = stringToArrayBuffer(id);
|
||||
|
||||
return textsecure.storage.groups
|
||||
.createNewGroup(targetNumbers)
|
||||
.then(group => {
|
||||
proto.group.id = stringToArrayBuffer(group.id);
|
||||
const { numbers } = group;
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
||||
proto.group.members = targetNumbers;
|
||||
proto.group.name = name;
|
||||
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
||||
proto.group.members = numbers;
|
||||
proto.group.name = name;
|
||||
|
||||
return this.makeAttachmentPointer(avatar).then(attachment => {
|
||||
proto.group.avatar = attachment;
|
||||
return this.sendGroupProto(numbers, proto, Date.now(), options).then(
|
||||
() => proto.group.id
|
||||
);
|
||||
});
|
||||
});
|
||||
return this.makeAttachmentPointer(avatar).then(attachment => {
|
||||
proto.group.avatar = attachment;
|
||||
return this.sendGroupProto(
|
||||
targetNumbers,
|
||||
proto,
|
||||
Date.now(),
|
||||
options
|
||||
).then(() => proto.group.id);
|
||||
});
|
||||
},
|
||||
|
||||
updateGroup(groupId, name, avatar, targetNumbers, options) {
|
||||
|
@ -953,121 +945,87 @@ MessageSender.prototype = {
|
|||
proto.group.id = stringToArrayBuffer(groupId);
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
||||
proto.group.name = name;
|
||||
proto.group.members = targetNumbers;
|
||||
|
||||
return textsecure.storage.groups
|
||||
.addNumbers(groupId, targetNumbers)
|
||||
.then(numbers => {
|
||||
if (numbers === undefined) {
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
}
|
||||
proto.group.members = numbers;
|
||||
|
||||
return this.makeAttachmentPointer(avatar).then(attachment => {
|
||||
proto.group.avatar = attachment;
|
||||
return this.sendGroupProto(numbers, proto, Date.now(), options).then(
|
||||
() => proto.group.id
|
||||
);
|
||||
});
|
||||
});
|
||||
return this.makeAttachmentPointer(avatar).then(attachment => {
|
||||
proto.group.avatar = attachment;
|
||||
return this.sendGroupProto(
|
||||
targetNumbers,
|
||||
proto,
|
||||
Date.now(),
|
||||
options
|
||||
).then(() => proto.group.id);
|
||||
});
|
||||
},
|
||||
|
||||
addNumberToGroup(groupId, number, options) {
|
||||
addNumberToGroup(groupId, newNumbers, options) {
|
||||
const proto = new textsecure.protobuf.DataMessage();
|
||||
proto.group = new textsecure.protobuf.GroupContext();
|
||||
proto.group.id = stringToArrayBuffer(groupId);
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
||||
|
||||
return textsecure.storage.groups
|
||||
.addNumbers(groupId, [number])
|
||||
.then(numbers => {
|
||||
if (numbers === undefined)
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
proto.group.members = numbers;
|
||||
|
||||
return this.sendGroupProto(numbers, proto, Date.now(), options);
|
||||
});
|
||||
proto.group.members = newNumbers;
|
||||
return this.sendGroupProto(newNumbers, proto, Date.now(), options);
|
||||
},
|
||||
|
||||
setGroupName(groupId, name, options) {
|
||||
setGroupName(groupId, name, groupNumbers, options) {
|
||||
const proto = new textsecure.protobuf.DataMessage();
|
||||
proto.group = new textsecure.protobuf.GroupContext();
|
||||
proto.group.id = stringToArrayBuffer(groupId);
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
||||
proto.group.name = name;
|
||||
proto.group.members = groupNumbers;
|
||||
|
||||
return textsecure.storage.groups.getNumbers(groupId).then(numbers => {
|
||||
if (numbers === undefined)
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
proto.group.members = numbers;
|
||||
|
||||
return this.sendGroupProto(numbers, proto, Date.now(), options);
|
||||
});
|
||||
return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
|
||||
},
|
||||
|
||||
setGroupAvatar(groupId, avatar, options) {
|
||||
setGroupAvatar(groupId, avatar, groupNumbers, options) {
|
||||
const proto = new textsecure.protobuf.DataMessage();
|
||||
proto.group = new textsecure.protobuf.GroupContext();
|
||||
proto.group.id = stringToArrayBuffer(groupId);
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.UPDATE;
|
||||
proto.group.members = groupNumbers;
|
||||
|
||||
return textsecure.storage.groups.getNumbers(groupId).then(numbers => {
|
||||
if (numbers === undefined)
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
proto.group.members = numbers;
|
||||
|
||||
return this.makeAttachmentPointer(avatar).then(attachment => {
|
||||
proto.group.avatar = attachment;
|
||||
return this.sendGroupProto(numbers, proto, Date.now(), options);
|
||||
});
|
||||
return this.makeAttachmentPointer(avatar).then(attachment => {
|
||||
proto.group.avatar = attachment;
|
||||
return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
|
||||
});
|
||||
},
|
||||
|
||||
leaveGroup(groupId, options) {
|
||||
leaveGroup(groupId, groupNumbers, options) {
|
||||
const proto = new textsecure.protobuf.DataMessage();
|
||||
proto.group = new textsecure.protobuf.GroupContext();
|
||||
proto.group.id = stringToArrayBuffer(groupId);
|
||||
proto.group.type = textsecure.protobuf.GroupContext.Type.QUIT;
|
||||
|
||||
return textsecure.storage.groups.getNumbers(groupId).then(numbers => {
|
||||
if (numbers === undefined)
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
return textsecure.storage.groups
|
||||
.deleteGroup(groupId)
|
||||
.then(() => this.sendGroupProto(numbers, proto, Date.now(), options));
|
||||
});
|
||||
return this.sendGroupProto(groupNumbers, proto, Date.now(), options);
|
||||
},
|
||||
sendExpirationTimerUpdateToGroup(
|
||||
groupId,
|
||||
groupNumbers,
|
||||
expireTimer,
|
||||
timestamp,
|
||||
profileKey,
|
||||
options
|
||||
) {
|
||||
return textsecure.storage.groups.getNumbers(groupId).then(targetNumbers => {
|
||||
if (targetNumbers === undefined)
|
||||
return Promise.reject(new Error('Unknown Group'));
|
||||
|
||||
const me = textsecure.storage.user.getNumber();
|
||||
const numbers = targetNumbers.filter(number => number !== me);
|
||||
if (numbers.length === 0) {
|
||||
return Promise.reject(new Error('No other members in the group'));
|
||||
}
|
||||
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,
|
||||
},
|
||||
const me = textsecure.storage.user.getNumber();
|
||||
const numbers = groupNumbers.filter(number => number !== me);
|
||||
if (numbers.length === 0) {
|
||||
return Promise.reject(new Error('No other members in the group'));
|
||||
}
|
||||
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
|
||||
);
|
||||
});
|
||||
},
|
||||
options
|
||||
);
|
||||
},
|
||||
sendExpirationTimerUpdateToNumber(
|
||||
number,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue