parent
6a5f923cac
commit
8dc4e34aaf
4 changed files with 29 additions and 13 deletions
|
@ -53,7 +53,8 @@
|
|||
messageReceiver = new textsecure.MessageReceiver(window);
|
||||
}
|
||||
|
||||
function onContactReceived(contactInfo) {
|
||||
function onContactReceived(ev) {
|
||||
var contactInfo = ev.contactInfo;
|
||||
new Whisper.Conversation({
|
||||
name: contactInfo.name,
|
||||
id: contactInfo.number,
|
||||
|
@ -63,7 +64,8 @@
|
|||
}).save();
|
||||
}
|
||||
|
||||
function onGroupReceived(group) {
|
||||
function onGroupReceived(ev) {
|
||||
var group = ev.group;
|
||||
new Whisper.Conversation({
|
||||
members: group.members,
|
||||
name: group.name,
|
||||
|
|
|
@ -40134,13 +40134,18 @@ ContactBuffer.prototype = {
|
|||
constructor: ContactBuffer,
|
||||
readContact: function() {
|
||||
try {
|
||||
var len = this.buffer.readVarint32();
|
||||
if (this.buffer.limit === this.buffer.offset) {
|
||||
return undefined; // eof
|
||||
}
|
||||
var len = this.buffer.readVarint64().toNumber();
|
||||
var contactInfoBuffer = this.buffer.slice(this.buffer.offset, this.buffer.offset+len);
|
||||
var contactInfo = textsecure.protobuf.ContactDetails.decode(contactInfoBuffer);
|
||||
this.buffer.skip(len);
|
||||
var attachmentLen = contactInfo.avatar.length.toNumber();
|
||||
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
||||
this.buffer.skip(attachmentLen);
|
||||
if (contactInfo.avatar) {
|
||||
var attachmentLen = contactInfo.avatar.length.toNumber();
|
||||
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
||||
this.buffer.skip(attachmentLen);
|
||||
}
|
||||
|
||||
return contactInfo;
|
||||
} catch(e) {
|
||||
|
|
|
@ -11,13 +11,18 @@ ContactBuffer.prototype = {
|
|||
constructor: ContactBuffer,
|
||||
readContact: function() {
|
||||
try {
|
||||
var len = this.buffer.readVarint32();
|
||||
if (this.buffer.limit === this.buffer.offset) {
|
||||
return undefined; // eof
|
||||
}
|
||||
var len = this.buffer.readVarint64().toNumber();
|
||||
var contactInfoBuffer = this.buffer.slice(this.buffer.offset, this.buffer.offset+len);
|
||||
var contactInfo = textsecure.protobuf.ContactDetails.decode(contactInfoBuffer);
|
||||
this.buffer.skip(len);
|
||||
var attachmentLen = contactInfo.avatar.length.toNumber();
|
||||
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
||||
this.buffer.skip(attachmentLen);
|
||||
if (contactInfo.avatar) {
|
||||
var attachmentLen = contactInfo.avatar.length.toNumber();
|
||||
contactInfo.avatar.data = this.buffer.slice(this.buffer.offset, this.buffer.offset + attachmentLen).toArrayBuffer(true);
|
||||
this.buffer.skip(attachmentLen);
|
||||
}
|
||||
|
||||
return contactInfo;
|
||||
} catch(e) {
|
||||
|
|
|
@ -39,16 +39,18 @@ describe("ContactsBuffer", function() {
|
|||
buffer.append(avatarBuffer.clone());
|
||||
}
|
||||
|
||||
buffer.limit = buffer.offset;
|
||||
buffer.offset = 0;
|
||||
buffer.limit = buffer.buffer.byteLength;
|
||||
return buffer.toArrayBuffer();
|
||||
}
|
||||
|
||||
it("parses an array buffer of contacts", function() {
|
||||
var arrayBuffer = getTestBuffer();
|
||||
var contactBuffer = new ContactBuffer(arrayBuffer);
|
||||
for (var i=0; i < 3; ++i) {
|
||||
var contact = contactBuffer.readContact();
|
||||
var contact = contactBuffer.readContact();
|
||||
var count = 0;
|
||||
while (contact !== undefined) {
|
||||
count++;
|
||||
assert.strictEqual(contact.name, "Zero Cool");
|
||||
assert.strictEqual(contact.number, "+10000000000");
|
||||
assert.strictEqual(contact.avatar.contentType, "image/jpg");
|
||||
|
@ -56,6 +58,8 @@ describe("ContactsBuffer", function() {
|
|||
for (var j=0; j < 255; ++j) {
|
||||
assert.strictEqual(avatarBytes[j],j);
|
||||
}
|
||||
contact = contactBuffer.readContact();
|
||||
}
|
||||
assert.strictEqual(count, 3);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue