Fix closed group issues

pull/1211/head
Mikunj 5 years ago
parent f5bc1efc3a
commit 269c87a42e

@ -639,13 +639,15 @@
confirm: () => {},
};
await window.NewReceiver.onGroupReceived(ev);
const convo = await ConversationController.getOrCreateAndWait(
groupId,
'group'
);
const recipients = _.union(convo.get('members'), members);
await window.NewReceiver.onGroupReceived(ev);
if (convo.isPublic()) {
const API = await convo.getPublicSendData();
@ -703,8 +705,6 @@
}
const options = {};
const recipients = _.union(convo.get('members'), members);
const isMediumGroup = convo.isMediumGroup();
const updateObj = {

@ -1239,12 +1239,12 @@
recipients,
});
if (this.isPrivate()) {
messageWithSchema.destination = destination;
} else if (this.isPublic()) {
if (this.isPublic()) {
// Public chats require this data to detect duplicates
messageWithSchema.source = textsecure.storage.user.getNumber();
messageWithSchema.sourceDevice = 1;
} else {
messageWithSchema.destination = destination;
}
const { sessionRestoration = false } = otherOptions;
@ -1368,6 +1368,7 @@
}
if (conversationType === Message.GROUP) {
const members = this.get('members');
if (this.isMediumGroup()) {
const mediumGroupChatMessage = new libsession.Messages.Outgoing.MediumGroupChatMessage(
{
@ -1375,7 +1376,6 @@
groupId: destination,
}
);
const members = this.get('members');
await Promise.all(
members.map(async m => {
const memberPubKey = new libsession.Types.PubKey(m);
@ -1391,6 +1391,16 @@
groupId: destination,
}
);
// Special-case the self-send case - we send only a sync message
if (members.length === 1) {
const isOurDevice = await libsession.Protocols.MultiDeviceProtocol.isOurDevice(members[0]);
if (isOurDevice) {
await message.sendSyncMessageOnly(closedGroupChatMessage);
return true;
}
}
await libsession
.getMessageQueue()
.sendToGroup(closedGroupChatMessage);
@ -1815,13 +1825,16 @@
);
message.set({ id: messageId });
// Difference between `recipients` and `members` is that `recipients` includes the members which were removed in this update
const { id, name, members, avatar, recipients } = groupUpdate;
if (groupUpdate.is_medium_group) {
const { secretKey, senderKey } = groupUpdate;
// Constructing a "create group" message
const { id, name, secretKey, senderKey, members } = groupUpdate;
const { chainKey, keyIdx } = senderKey;
const createParams = {
timestamp: Date.now(),
timestamp: now,
groupId: id,
identifier: messageId,
groupSecretKey: secretKey,
@ -1849,17 +1862,18 @@
const updateParams = {
// if we do set an identifier here, be sure to not sync the message two times in msg.handleMessageSentSuccess()
timestamp: Date.now(),
groupId: this.id,
name: this.get('name'),
avatar: this.get('avatar'),
members: this.get('members'),
timestamp: now,
groupId: id,
name,
avatar,
members,
admins: this.get('groupAdmins'),
};
const groupUpdateMessage = new libsession.Messages.Outgoing.ClosedGroupUpdateMessage(
updateParams
);
await this.sendClosedGroupMessageWithSync(groupUpdateMessage);
await this.sendClosedGroupMessageWithSync(groupUpdateMessage, recipients);
},
sendGroupInfo(recipient) {
@ -1935,7 +1949,7 @@
}
},
async sendClosedGroupMessageWithSync(message) {
async sendClosedGroupMessageWithSync(message, recipients) {
const {
ClosedGroupMessage,
ClosedGroupChatMessage,
@ -1951,19 +1965,28 @@
);
}
const members = recipients || this.get('members');
try {
await libsession.getMessageQueue().sendToGroup(message);
// Exclude our device from members and send them the message
const ourNumber = textsecure.storage.user.getNumber();
const primary = await libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice(ourNumber);
const otherMembers = (members || []).filter(member => !primary.isEqual(member));
const sendPromises = otherMembers.map(member => {
const memberPubKey = libsession.Types.PubKey.cast(member);
return libsession.getMessageQueue().sendUsingMultiDevice(memberPubKey, message);
});
await Promise.all(sendPromises);
const syncMessage = libsession.Utils.SyncMessageUtils.getSentSyncMessage(
{
destination: message.groupId,
message,
}
);
// Send the sync message to our devices
const syncMessage = new libsession.Messages.Outgoing.SentSyncMessage({
timestamp: Date.now(),
identifier: message.identifier,
destination: message.groupId,
dataMessage: message.dataProto(),
});
if (syncMessage) {
await libsession.getMessageQueue().sendSyncMessage(syncMessage);
}
await libsession.getMessageQueue().sendSyncMessage(syncMessage);
} catch (e) {
window.log.error(e);
}

@ -1100,8 +1100,11 @@
});
// Special-case the self-send case - we send only a sync message
if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) {
return this.sendSyncMessageOnly(chatMessage);
if (recipients.length === 1) {
const isOurDevice = await libsession.Protocols.MultiDeviceProtocol.isOurDevice(recipients[0]);
if (isOurDevice) {
return this.sendSyncMessageOnly(chatMessage);
}
}
if (conversation.isPrivate()) {
@ -1433,10 +1436,15 @@
return;
}
const data =
dataMessage instanceof libsession.Messages.Outgoing.DataMessage
? dataMessage.dataProto()
: dataMessage;
const syncMessage = new libsession.Messages.Outgoing.SentSyncMessage({
timestamp: this.get('sent_at'),
identifier: this.id,
dataMessage,
dataMessage: data,
destination: this.get('destination'),
expirationStartTimestamp: this.get('expirationStartTimestamp'),
sent_to: this.get('sent_to'),

@ -222,7 +222,7 @@ export class SessionGroupSettings extends React.Component<Props, any> {
const leaveGroupString = isPublic
? window.i18n('leaveOpenGroup')
: isKickedFromGroup
? window.i18n('youAreKickedFromThisGroup')
? window.i18n('youGotKickedFromThisGroup')
: window.i18n('leaveClosedGroup');
const disappearingMessagesOptions = timerOptions.map(option => {

@ -533,7 +533,7 @@ export async function handleMessageEvent(event: any): Promise<void> {
let { source } = data;
const isGroupMessage = message.group;
const isGroupMessage = Boolean(message.group);
const type = isGroupMessage
? ConversationType.GROUP

Loading…
Cancel
Save