Fix group update avatar handling

The avatar handler was being added to the list of promises too late,
so we were storing the raw avatar protobuf (Long id, bytes key) rather
than the downloaded/decrypted attachment data.

Fixes #280
This commit is contained in:
lilia 2015-06-26 12:23:57 -07:00
parent 5e6145aa46
commit 5242108e15
2 changed files with 14 additions and 12 deletions

View file

@ -38781,14 +38781,18 @@ function processDecrypted(decrypted, source) {
if (decrypted.group !== null) { if (decrypted.group !== null) {
decrypted.group.id = getString(decrypted.group.id); decrypted.group.id = getString(decrypted.group.id);
if (decrypted.group.type == textsecure.protobuf.GroupContext.Type.UPDATE) {
if (decrypted.group.avatar !== null) {
promises.push(handleAttachment(decrypted.group.avatar));
}
}
promises.push(textsecure.storage.groups.getNumbers(decrypted.group.id).then(function(existingGroup) { promises.push(textsecure.storage.groups.getNumbers(decrypted.group.id).then(function(existingGroup) {
if (existingGroup === undefined) { if (existingGroup === undefined) {
if (decrypted.group.type != textsecure.protobuf.GroupContext.Type.UPDATE) { if (decrypted.group.type != textsecure.protobuf.GroupContext.Type.UPDATE) {
throw new Error("Got message for unknown group"); throw new Error("Got message for unknown group");
} }
if (decrypted.group.avatar !== null) {
promises.push(handleAttachment(decrypted.group.avatar));
}
return textsecure.storage.groups.createNewGroup(decrypted.group.members, decrypted.group.id); return textsecure.storage.groups.createNewGroup(decrypted.group.members, decrypted.group.id);
} else { } else {
var fromIndex = existingGroup.indexOf(source); var fromIndex = existingGroup.indexOf(source);
@ -38800,9 +38804,6 @@ function processDecrypted(decrypted, source) {
switch(decrypted.group.type) { switch(decrypted.group.type) {
case textsecure.protobuf.GroupContext.Type.UPDATE: case textsecure.protobuf.GroupContext.Type.UPDATE:
if (decrypted.group.avatar !== null)
promises.push(handleAttachment(decrypted.group.avatar));
return textsecure.storage.groups.updateNumbers( return textsecure.storage.groups.updateNumbers(
decrypted.group.id, decrypted.group.members decrypted.group.id, decrypted.group.members
).then(function(added) { ).then(function(added) {

View file

@ -170,14 +170,18 @@ function processDecrypted(decrypted, source) {
if (decrypted.group !== null) { if (decrypted.group !== null) {
decrypted.group.id = getString(decrypted.group.id); decrypted.group.id = getString(decrypted.group.id);
if (decrypted.group.type == textsecure.protobuf.GroupContext.Type.UPDATE) {
if (decrypted.group.avatar !== null) {
promises.push(handleAttachment(decrypted.group.avatar));
}
}
promises.push(textsecure.storage.groups.getNumbers(decrypted.group.id).then(function(existingGroup) { promises.push(textsecure.storage.groups.getNumbers(decrypted.group.id).then(function(existingGroup) {
if (existingGroup === undefined) { if (existingGroup === undefined) {
if (decrypted.group.type != textsecure.protobuf.GroupContext.Type.UPDATE) { if (decrypted.group.type != textsecure.protobuf.GroupContext.Type.UPDATE) {
throw new Error("Got message for unknown group"); throw new Error("Got message for unknown group");
} }
if (decrypted.group.avatar !== null) {
promises.push(handleAttachment(decrypted.group.avatar));
}
return textsecure.storage.groups.createNewGroup(decrypted.group.members, decrypted.group.id); return textsecure.storage.groups.createNewGroup(decrypted.group.members, decrypted.group.id);
} else { } else {
var fromIndex = existingGroup.indexOf(source); var fromIndex = existingGroup.indexOf(source);
@ -189,9 +193,6 @@ function processDecrypted(decrypted, source) {
switch(decrypted.group.type) { switch(decrypted.group.type) {
case textsecure.protobuf.GroupContext.Type.UPDATE: case textsecure.protobuf.GroupContext.Type.UPDATE:
if (decrypted.group.avatar !== null)
promises.push(handleAttachment(decrypted.group.avatar));
return textsecure.storage.groups.updateNumbers( return textsecure.storage.groups.updateNumbers(
decrypted.group.id, decrypted.group.members decrypted.group.id, decrypted.group.members
).then(function(added) { ).then(function(added) {