diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-01-14 22:14:12 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-01-14 22:14:12 +0100 |
commit | c986110abec636e8cb6b691d4f7fb4a39f9ecf37 (patch) | |
tree | 52844bb51067c0c6b9824b1f1db3f57ef91a53de /src/main/java | |
parent | 51de021fb736f4ef5921d94cd0406f768915af54 (diff) |
fixed avatar republish missing the mime type
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 10 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 18 |
2 files changed, 14 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 147226b79..5436cd0ce 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -564,6 +564,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); @@ -583,6 +584,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; @@ -602,6 +604,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"); @@ -613,7 +616,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()); @@ -624,13 +628,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; } @@ -700,7 +704,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/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 1ce2b1922..c99888bde 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -2824,14 +2824,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) { @@ -2840,25 +2839,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); } } } |