Search in sources :

Example 1 with Downloader

use of eu.siacs.conversations.Downloader in project Zom-Android by zom.

the class ChatSessionAdapter method downloadMedia.

public String downloadMedia(String mediaLink, String msgId, String nickname) {
    String result = null;
    try {
        Downloader dl = new Downloader();
        File fileDownload = dl.openSecureStorageFile(mContactId + "", mediaLink);
        OutputStream storageStream = new info.guardianproject.iocipher.FileOutputStream(fileDownload);
        boolean downloaded = dl.get(mediaLink, storageStream);
        if (downloaded) {
            String mimeType = dl.getMimeType();
            try {
                // boolean isVerified = getDefaultOtrChatSession().isKeyVerified(bareUsername);
                // int type = isVerified ? Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED : Imps.MessageType.INCOMING_ENCRYPTED;
                int type = Imps.MessageType.INCOMING;
                if (mediaLink.startsWith("aesgcm"))
                    type = Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED;
                result = SecureMediaStore.vfsUri(fileDownload.getAbsolutePath()).toString();
                insertOrUpdateChat(result);
                // Imps.deleteMessageInDb(service.getContentResolver(),msgId);
                Uri messageUri = Imps.insertMessageInDb(service.getContentResolver(), mIsGroupChat, getId(), true, nickname, result, System.currentTimeMillis(), type, 0, msgId, mimeType);
                if (// error writing to database
                messageUri == null) {
                    Log.e(TAG, "error saving message to the db: " + msgId);
                    return null;
                }
                String sanitizedPath = Uri.parse(mediaLink).getLastPathSegment();
                try {
                    int N = mRemoteListeners.beginBroadcast();
                    for (int i = 0; i < N; i++) {
                        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
                        try {
                            listener.onIncomingFileTransferProgress(sanitizedPath, 100);
                        } catch (RemoteException e) {
                        // The RemoteCallbackList will take care of removing the
                        // dead listeners.
                        }
                    }
                    mRemoteListeners.finishBroadcast();
                } catch (Exception e) {
                    Log.e(TAG, "error notifying of new messages", e);
                }
            } catch (Exception e) {
                Log.e(ImApp.LOG_TAG, "Error updating file transfer progress", e);
            }
        }
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error downloading incoming media", e);
    }
    return result;
}
Also used : IChatListener(org.awesomeapp.messenger.service.IChatListener) OutputStream(java.io.OutputStream) Downloader(eu.siacs.conversations.Downloader) RemoteException(android.os.RemoteException) File(info.guardianproject.iocipher.File) Uri(android.net.Uri) FileNotFoundException(java.io.FileNotFoundException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RemoteException(android.os.RemoteException)

Aggregations

Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1 Downloader (eu.siacs.conversations.Downloader)1 File (info.guardianproject.iocipher.File)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 IChatListener (org.awesomeapp.messenger.service.IChatListener)1 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)1