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