Added sending of group sync message

pull/877/head
Mikunj 5 years ago
parent b61dd6a839
commit abf298ba25

@ -152,6 +152,34 @@
});
return syncMessage;
}
async function createGroupSyncProtoMessage(conversations) {
// We only want to sync across closed groups that we haven't left
const sessionGroups = conversations.filter(c => c.isClosedGroup() && !c.get('left') && c.isFriend());
const rawGroups = await Promise.all(
sessionGroups.map(async conversation => ({
id: conversation.id,
name: conversation.get('name'),
members: conversation.get('members') || [],
blocked: conversation.isBlocked(),
expireTimer: conversation.get('expireTimer'),
admins: conversation.get('groupAdmins') || [],
}))
);
// Convert raw groups to an array of buffers
const groupDetails = rawGroups
.map(x => new textsecure.protobuf.GroupDetails(x))
.map(x => x.encode());
// Serialise array of byteBuffers into 1 byteBuffer
const byteBuffer = serialiseByteBuffers(groupDetails);
const data = new Uint8Array(byteBuffer.toArrayBuffer());
const groups = new textsecure.protobuf.SyncMessage.Groups({
data,
});
const syncMessage = new textsecure.protobuf.SyncMessage({
groups,
});
return syncMessage;
}
async function sendPairingAuthorisation(authorisation, recipientPubKey) {
const pairingAuthorisation = createPairingAuthorisationProtoMessage(
authorisation
@ -222,5 +250,6 @@
createPairingAuthorisationProtoMessage,
sendUnpairingMessageToSecondary,
createContactSyncProtoMessage,
createGroupSyncProtoMessage,
};
})();

@ -634,6 +634,8 @@
blockSync: true,
}
);
// Send group sync message
await textsecure.messaging.sendGroupSyncMessage(window.getConversations())
},
validatePubKeyHex(pubKey) {
const c = new Whisper.Conversation({

@ -1574,11 +1574,10 @@ MessageReceiver.prototype.extend({
},
handleGroups(envelope, groups) {
window.log.info('group sync');
const { blob } = groups;
// Note: we do not return here because we don't want to block the next message on
// this attachment download and a lot of processing of that attachment.
this.handleAttachment(blob).then(attachmentPointer => {
this.handleAttachment(groups).then(attachmentPointer => {
const groupBuffer = new GroupBuffer(attachmentPointer.data);
let groupDetails = groupBuffer.next();
const promises = [];

@ -700,6 +700,22 @@ MessageSender.prototype = {
);
},
async sendGroupSyncMessage(conversations) {
const ourNumber = textsecure.storage.user.getNumber();
const syncMessage = await libloki.api.createGroupSyncProtoMessage(conversations);
const contentMessage = new textsecure.protobuf.Content();
contentMessage.syncMessage = syncMessage;
const silent = true;
return this.sendIndividualProto(
ourNumber,
contentMessage,
Date.now(),
silent,
{} // options
);
},
sendRequestContactSyncMessage(options) {
const myNumber = textsecure.storage.user.getNumber();
const myDevice = textsecure.storage.user.getDeviceId();

@ -282,6 +282,7 @@ message SyncMessage {
message Groups {
optional AttachmentPointer blob = 1;
optional bytes data = 101;
}
message Blocked {
@ -390,4 +391,5 @@ message GroupDetails {
optional uint32 expireTimer = 6;
optional string color = 7;
optional bool blocked = 8;
repeated string admins = 9;
}

Loading…
Cancel
Save