Merge pull request #1235 from Bilb/closed-group-update-sync

handle sync for closed groups update as we do for regular messages
pull/1243/head
Audric Ackermann 5 years ago committed by GitHub
commit 49164f069e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1704,7 +1704,17 @@
const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage( const expirationTimerMessage = new libsession.Messages.Outgoing.ExpirationTimerUpdateMessage(
expireUpdate expireUpdate
); );
// special case when we are the only member of a closed group
const ourNumber = textsecure.storage.user.getNumber();
const primary = await libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice(
ourNumber
);
if (
this.get('members').length === 1 &&
this.get('members')[0] === primary.key
) {
return message.sendSyncMessageOnly(expirationTimerMessage);
}
await libsession.getMessageQueue().sendToGroup(expirationTimerMessage); await libsession.getMessageQueue().sendToGroup(expirationTimerMessage);
} }
return message; return message;
@ -1890,6 +1900,7 @@
const updateParams = { const updateParams = {
// if we do set an identifier here, be sure to not sync the message two times in msg.handleMessageSentSuccess() // if we do set an identifier here, be sure to not sync the message two times in msg.handleMessageSentSuccess()
identifier: messageId,
timestamp: now, timestamp: now,
groupId: id, groupId: id,
name: name || this.getName(), name: name || this.getName(),
@ -1901,7 +1912,11 @@
updateParams updateParams
); );
await this.sendClosedGroupMessageWithSync(groupUpdateMessage, recipients); await this.sendClosedGroupMessage(
groupUpdateMessage,
recipients,
message
);
if (groupUpdate.joined && groupUpdate.joined.length) { if (groupUpdate.joined && groupUpdate.joined.length) {
const expireUpdate = { const expireUpdate = {
@ -2002,6 +2017,7 @@
// FIXME what about public groups? // FIXME what about public groups?
const quitGroup = { const quitGroup = {
identifier: id,
timestamp: now, timestamp: now,
groupId: this.id, groupId: this.id,
// if we do set an identifier here, be sure to not sync it a second time in handleMessageSentSuccess() // if we do set an identifier here, be sure to not sync it a second time in handleMessageSentSuccess()
@ -2010,13 +2026,13 @@
quitGroup quitGroup
); );
await this.sendClosedGroupMessageWithSync(quitGroupMessage); await this.sendClosedGroupMessage(quitGroupMessage, undefined, message);
this.updateTextInputState(); this.updateTextInputState();
} }
}, },
async sendClosedGroupMessageWithSync(message, recipients) { async sendClosedGroupMessage(message, recipients, dbMessage) {
const { const {
ClosedGroupMessage, ClosedGroupMessage,
ClosedGroupChatMessage, ClosedGroupChatMessage,
@ -2043,6 +2059,11 @@
const otherMembers = (members || []).filter( const otherMembers = (members || []).filter(
member => !primary.isEqual(member) member => !primary.isEqual(member)
); );
// we are the only member in here
if (members.length === 1 && members[0] === primary.key) {
dbMessage.sendSyncMessageOnly(message);
return;
}
const sendPromises = otherMembers.map(member => { const sendPromises = otherMembers.map(member => {
const memberPubKey = libsession.Types.PubKey.cast(member); const memberPubKey = libsession.Types.PubKey.cast(member);
return libsession return libsession
@ -2050,16 +2071,6 @@
.sendUsingMultiDevice(memberPubKey, message); .sendUsingMultiDevice(memberPubKey, message);
}); });
await Promise.all(sendPromises); await Promise.all(sendPromises);
// 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(),
});
await libsession.getMessageQueue().sendSyncMessage(syncMessage);
} catch (e) { } catch (e) {
window.log.error(e); window.log.error(e);
} }

@ -1245,7 +1245,7 @@
); );
const { dataMessage } = contentDecoded; const { dataMessage } = contentDecoded;
if (dataMessage) { if (dataMessage) {
this.sendSyncMessage(dataMessage); await this.sendSyncMessage(dataMessage);
} }
} else if (shouldMarkMessageAsSynced) { } else if (shouldMarkMessageAsSynced) {
this.set({ synced: true }); this.set({ synced: true });

Loading…
Cancel
Save