Support for group sync
Protocol and handling is all analogous to contact sync: Multiple GroupDetails structs are packed into a single attachment blob and parsed on our end. We don't display the synced groups in the conversation list until a new message is sent to one of them. // FREEBIEpull/749/head
parent
3dd8056487
commit
5925c2fe84
@ -1,32 +1,52 @@
|
|||||||
/*
|
/*
|
||||||
* vim: ts=4:sw=4:expandtab
|
* vim: ts=4:sw=4:expandtab
|
||||||
*/
|
*/
|
||||||
function ContactBuffer(arrayBuffer) {
|
|
||||||
|
function ProtoParser(arrayBuffer, protobuf) {
|
||||||
|
this.protobuf = protobuf;
|
||||||
this.buffer = new dcodeIO.ByteBuffer();
|
this.buffer = new dcodeIO.ByteBuffer();
|
||||||
this.buffer.append(arrayBuffer);
|
this.buffer.append(arrayBuffer);
|
||||||
this.buffer.offset = 0;
|
this.buffer.offset = 0;
|
||||||
this.buffer.limit = arrayBuffer.byteLength;
|
this.buffer.limit = arrayBuffer.byteLength;
|
||||||
}
|
}
|
||||||
ContactBuffer.prototype = {
|
ProtoParser.prototype = {
|
||||||
constructor: ContactBuffer,
|
constructor: ProtoParser,
|
||||||
readContact: function() {
|
next: function() {
|
||||||
try {
|
try {
|
||||||
if (this.buffer.limit === this.buffer.offset) {
|
if (this.buffer.limit === this.buffer.offset) {
|
||||||
return undefined; // eof
|
return undefined; // eof
|
||||||
}
|
}
|
||||||
var len = this.buffer.readVarint64().toNumber();
|
var len = this.buffer.readVarint32();
|
||||||
var contactInfoBuffer = this.buffer.slice(this.buffer.offset, this.buffer.offset+len);
|
var nextBuffer = this.buffer.slice(
|
||||||
var contactInfo = textsecure.protobuf.ContactDetails.decode(contactInfoBuffer);
|
this.buffer.offset, this.buffer.offset+len
|
||||||
|
).toArrayBuffer();
|
||||||
|
// TODO: de-dupe ByteBuffer.js includes in libaxo/libts
|
||||||
|
// then remove this toArrayBuffer call.
|
||||||
|
|
||||||
|
var proto = this.protobuf.decode(nextBuffer);
|
||||||
this.buffer.skip(len);
|
this.buffer.skip(len);
|
||||||
if (contactInfo.avatar) {
|
|
||||||
var attachmentLen = contactInfo.avatar.length.toNumber();
|
if (proto.avatar) {
|
||||||
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
var attachmentLen = proto.avatar.length;
|
||||||
|
proto.avatar.data = this.buffer.slice(
|
||||||
|
this.buffer.offset, this.buffer.offset + attachmentLen
|
||||||
|
).toArrayBuffer();
|
||||||
this.buffer.skip(attachmentLen);
|
this.buffer.skip(attachmentLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return contactInfo;
|
return proto;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var GroupBuffer = function(arrayBuffer) {
|
||||||
|
ProtoParser.call(this, arrayBuffer, textsecure.protobuf.GroupDetails);
|
||||||
|
};
|
||||||
|
GroupBuffer.prototype = Object.create(ProtoParser.prototype);
|
||||||
|
GroupBuffer.prototype.constructor = GroupBuffer;
|
||||||
|
var ContactBuffer = function(arrayBuffer) {
|
||||||
|
ProtoParser.call(this, arrayBuffer, textsecure.protobuf.ContactDetails);
|
||||||
|
};
|
||||||
|
ContactBuffer.prototype = Object.create(ProtoParser.prototype);
|
||||||
|
ContactBuffer.prototype.constructor = ContactBuffer;
|
||||||
|
Loading…
Reference in New Issue