diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2017-01-12 12:20:10 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2017-01-12 12:20:10 +0100 |
commit | 2c1d3ef96807b56037451278d1be90337666617d (patch) | |
tree | f50b297c70c7bc4acc4c8b7080abaaf6c602cede /src | |
parent | f0c3b31a42ac6269a0ca299f2fa470586f6120be (diff) |
fixed avatar republish missing the mime type
Diffstat (limited to 'src')
3 files changed, 14 insertions, 15 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java index 1f532370..e5e7b203 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java @@ -23,7 +23,6 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import eu.siacs.conversations.Config; -import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.jid.Jid; diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 3239ce3d..bc9ed259 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -555,6 +555,7 @@ public class FileBackend { File file = new File(getAvatarPath(hash)); FileInputStream is = null; try { + avatar.size = file.length(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(file.getAbsolutePath(), options); @@ -574,6 +575,7 @@ public class FileBackend { avatar.image = new String(mByteArrayOutputStream.toByteArray()); avatar.height = options.outHeight; avatar.width = options.outWidth; + avatar.type = options.outMimeType; return avatar; } catch (IOException e) { return null; @@ -593,6 +595,7 @@ public class FileBackend { File file; if (isAvatarCached(avatar)) { file = new File(getAvatarPath(avatar.getFilename())); + avatar.size = file.length(); } else { String filename = getAvatarPath(avatar.getFilename()); file = new File(filename + ".tmp"); @@ -604,7 +607,8 @@ public class FileBackend { MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.reset(); DigestOutputStream mDigestOutputStream = new DigestOutputStream(os, digest); - mDigestOutputStream.write(avatar.getImageAsBytes()); + final byte[] bytes = avatar.getImageAsBytes(); + mDigestOutputStream.write(bytes); mDigestOutputStream.flush(); mDigestOutputStream.close(); String sha1sum = CryptoHelper.bytesToHex(digest.digest()); @@ -615,13 +619,13 @@ public class FileBackend { file.delete(); return false; } + avatar.size = bytes.length; } catch (IllegalArgumentException | IOException | NoSuchAlgorithmException e) { return false; } finally { close(os); } } - avatar.size = file.length(); return true; } @@ -691,7 +695,7 @@ public class FileBackend { Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dest); canvas.drawBitmap(source, null, targetRect, null); - if (source != null && !source.isRecycled()) { + if (source.isRecycled()) { source.recycle(); } return dest; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index ce49b2b6..e53b2524 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2639,14 +2639,13 @@ public class XmppConnectionService extends Service { } public void publishAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) { - final IqPacket packet = this.mIqGenerator.publishAvatar(avatar); + IqPacket packet = this.mIqGenerator.publishAvatar(avatar); this.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket result) { if (result.getType() == IqPacket.TYPE.RESULT) { - final IqPacket packet = XmppConnectionService.this.mIqGenerator - .publishAvatarMetadata(avatar); + final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar); sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket result) { @@ -2655,25 +2654,22 @@ public class XmppConnectionService extends Service { getAvatarService().clear(account); databaseBackend.updateAccount(account); } + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": published avatar "+(avatar.size/1024)+"KiB"); if (callback != null) { callback.success(avatar); - } else { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": published avatar"); } } else { if (callback != null) { - callback.error( - R.string.error_publish_avatar_server_reject, - avatar); + callback.error(R.string.error_publish_avatar_server_reject,avatar); } } } }); } else { + Element error = result.findChild("error"); + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": server rejected avatar "+(avatar.size/1024)+"KiB "+(error!=null?error.toString():"")); if (callback != null) { - callback.error( - R.string.error_publish_avatar_server_reject, - avatar); + callback.error(R.string.error_publish_avatar_server_reject, avatar); } } } |