use of org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException in project Signal-Android by WhisperSystems.
the class AttachmentDownloadJob method retrieveAttachment.
private void retrieveAttachment(MasterSecret masterSecret, long messageId, final AttachmentId attachmentId, final Attachment attachment) throws IOException {
AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context);
File attachmentFile = null;
try {
attachmentFile = createTempFile();
SignalServiceAttachmentPointer pointer = createAttachmentPointer(masterSecret, attachment);
InputStream stream = messageReceiver.retrieveAttachment(pointer, attachmentFile, MAX_ATTACHMENT_SIZE, new ProgressListener() {
@Override
public void onAttachmentProgress(long total, long progress) {
EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
}
});
database.insertAttachmentsForPlaceholder(masterSecret, messageId, attachmentId, stream);
} catch (InvalidPartException | NonSuccessfulResponseCodeException | InvalidMessageException | MmsException e) {
Log.w(TAG, e);
markFailed(messageId, attachmentId);
} finally {
if (attachmentFile != null)
attachmentFile.delete();
}
}
use of org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException in project Signal-Android by WhisperSystems.
the class AvatarDownloadJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
GroupDatabase.GroupRecord record = database.getGroup(groupId);
File attachment = null;
try {
if (record != null) {
long avatarId = record.getAvatarId();
String contentType = record.getAvatarContentType();
byte[] key = record.getAvatarKey();
String relay = record.getRelay();
Optional<byte[]> digest = Optional.fromNullable(record.getAvatarDigest());
if (avatarId == -1 || key == null) {
return;
}
if (digest.isPresent()) {
Log.w(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
}
attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
attachment.deleteOnExit();
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay, digest);
InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, MAX_AVATAR_SIZE);
Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key), 500, 500);
database.updateAvatar(groupId, avatar);
inputStream.close();
}
} catch (BitmapDecodingException | NonSuccessfulResponseCodeException | InvalidMessageException e) {
Log.w(TAG, e);
} finally {
if (attachment != null)
attachment.delete();
}
}
Aggregations