From 5242108e15aad820a7b3403e294be05bac8ceea8 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 26 Jun 2015 12:23:57 -0700 Subject: [PATCH] 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 --- js/libtextsecure.js | 13 +++++++------ libtextsecure/helpers.js | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 5cc5c142..b96d184f 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38781,14 +38781,18 @@ function processDecrypted(decrypted, source) { if (decrypted.group !== null) { 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) { if (existingGroup === undefined) { if (decrypted.group.type != textsecure.protobuf.GroupContext.Type.UPDATE) { 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); } else { var fromIndex = existingGroup.indexOf(source); @@ -38800,9 +38804,6 @@ function processDecrypted(decrypted, source) { switch(decrypted.group.type) { case textsecure.protobuf.GroupContext.Type.UPDATE: - if (decrypted.group.avatar !== null) - promises.push(handleAttachment(decrypted.group.avatar)); - return textsecure.storage.groups.updateNumbers( decrypted.group.id, decrypted.group.members ).then(function(added) { diff --git a/libtextsecure/helpers.js b/libtextsecure/helpers.js index 90e50fdc..2332c44b 100644 --- a/libtextsecure/helpers.js +++ b/libtextsecure/helpers.js @@ -170,14 +170,18 @@ function processDecrypted(decrypted, source) { if (decrypted.group !== null) { 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) { if (existingGroup === undefined) { if (decrypted.group.type != textsecure.protobuf.GroupContext.Type.UPDATE) { 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); } else { var fromIndex = existingGroup.indexOf(source); @@ -189,9 +193,6 @@ function processDecrypted(decrypted, source) { switch(decrypted.group.type) { case textsecure.protobuf.GroupContext.Type.UPDATE: - if (decrypted.group.avatar !== null) - promises.push(handleAttachment(decrypted.group.avatar)); - return textsecure.storage.groups.updateNumbers( decrypted.group.id, decrypted.group.members ).then(function(added) {