diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt index 18b5ff78f5..47e4136656 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt @@ -9,12 +9,12 @@ import org.session.libsession.messaging.sending_receiving.attachments.* import org.session.libsession.utilities.Address import org.session.libsession.utilities.UploadResult import org.session.libsession.utilities.Util -import org.session.libsignal.utilities.guava.Optional import org.session.libsignal.messages.SignalServiceAttachment import org.session.libsignal.messages.SignalServiceAttachmentPointer import org.session.libsignal.messages.SignalServiceAttachmentStream import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.Log +import org.session.libsignal.utilities.guava.Optional import org.thoughtcrime.securesms.database.AttachmentDatabase import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.DatabaseFactory @@ -97,11 +97,16 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) attachmentDatabase.insertAttachmentsForPlaceholder(messageId, attachmentId, stream) } - override fun updateAudioAttachmentDuration(attachmentId: AttachmentId, durationMs: Long) { - DatabaseFactory.getAttachmentDatabase(context).setAttachmentAudioExtras(DatabaseAttachmentAudioExtras( - attachmentId = attachmentId, - visualSamples = byteArrayOf(), - durationMs = durationMs + override fun updateAudioAttachmentDuration( + attachmentId: AttachmentId, + durationMs: Long, + threadId: Long + ) { + val attachmentDb = DatabaseFactory.getAttachmentDatabase(context) + attachmentDb.setAttachmentAudioExtras(DatabaseAttachmentAudioExtras( + attachmentId = attachmentId, + visualSamples = byteArrayOf(), + durationMs = durationMs )) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java index 4b20ee202e..2f85f27d52 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java @@ -44,8 +44,8 @@ import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAt import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachmentAudioExtras; import org.session.libsession.utilities.MediaTypes; import org.session.libsession.utilities.Util; -import org.session.libsignal.utilities.JsonUtil; import org.session.libsignal.utilities.ExternalStorageUtil; +import org.session.libsignal.utilities.JsonUtil; import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.crypto.AttachmentSecret; import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream; @@ -820,7 +820,7 @@ public class AttachmentDatabase extends Database { * @return true if the update operation was successful. */ @Synchronized - public boolean setAttachmentAudioExtras(@NonNull DatabaseAttachmentAudioExtras extras) { + public boolean setAttachmentAudioExtras(@NonNull DatabaseAttachmentAudioExtras extras, long threadId) { ContentValues values = new ContentValues(); values.put(AUDIO_VISUAL_SAMPLES, extras.getVisualSamples()); values.put(AUDIO_DURATION, extras.getDurationMs()); @@ -830,9 +830,22 @@ public class AttachmentDatabase extends Database { PART_ID_WHERE + " AND " + PART_AUDIO_ONLY_WHERE, extras.getAttachmentId().toStrings()); + if (threadId >= 0) { + notifyConversationListeners(threadId); + } + return alteredRows > 0; } + /** + * Updates audio extra columns for the "audio/*" mime type attachments only. + * @return true if the update operation was successful. + */ + @Synchronized + public boolean setAttachmentAudioExtras(@NonNull DatabaseAttachmentAudioExtras extras) { + return setAttachmentAudioExtras(extras, -1); // -1 for no update + } + @VisibleForTesting class ThumbnailFetchCallable implements Callable { diff --git a/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt b/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt index 37d6d44e4a..39ca4854ce 100644 --- a/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt +++ b/libsession/src/main/java/org/session/libsession/database/MessageDataProvider.kt @@ -20,7 +20,7 @@ interface MessageDataProvider { fun getSignalAttachmentPointer(attachmentId: Long): SignalServiceAttachmentPointer? fun setAttachmentState(attachmentState: AttachmentState, attachmentId: Long, messageID: Long) fun insertAttachment(messageId: Long, attachmentId: AttachmentId, stream : InputStream) - fun updateAudioAttachmentDuration(attachmentId: AttachmentId, durationMs: Long) + fun updateAudioAttachmentDuration(attachmentId: AttachmentId, durationMs: Long, threadId: Long) fun isOutgoingMessage(timestamp: Long): Boolean fun handleSuccessfulAttachmentUpload(attachmentId: Long, attachmentStream: SignalServiceAttachmentStream, attachmentKey: ByteArray, uploadResult: UploadResult) fun handleFailedAttachmentUpload(attachmentId: Long) diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt index 605052f85c..d0a09dc771 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt @@ -1,8 +1,5 @@ package org.session.libsession.messaging.jobs -import android.content.ContentResolver -import android.media.MediaDataSource -import android.media.MediaExtractor import okhttp3.HttpUrl import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.open_groups.OpenGroupAPIV2 @@ -78,7 +75,11 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long) try { InputStreamMediaDataSource(getInputStream(tempFile, attachment)).use { mediaDataSource -> val durationMs = (DecodedAudio.create(mediaDataSource).totalDuration / 1000.0).toLong() - messageDataProvider.updateAudioAttachmentDuration(attachment.attachmentId, durationMs) + messageDataProvider.updateAudioAttachmentDuration( + attachment.attachmentId, + durationMs, + threadID + ) } } catch (e: Exception) { Log.e("Loki", "Couldn't process audio attachment", e) diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt index 332d674115..02475c39cb 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt @@ -14,15 +14,11 @@ import org.session.libsession.messaging.utilities.Data import org.session.libsession.utilities.DecodedAudio import org.session.libsession.utilities.InputStreamMediaDataSource import org.session.libsession.utilities.UploadResult -import org.session.libsignal.streams.AttachmentCipherOutputStream import org.session.libsignal.messages.SignalServiceAttachmentStream -import org.session.libsignal.streams.PaddingInputStream -import org.session.libsignal.utilities.PushAttachmentData -import org.session.libsignal.streams.AttachmentCipherOutputStreamFactory -import org.session.libsignal.streams.DigestingRequestBody -import org.session.libsignal.utilities.Util -import org.session.libsignal.streams.PlaintextOutputStreamFactory +import org.session.libsignal.streams.* import org.session.libsignal.utilities.Log +import org.session.libsignal.utilities.PushAttachmentData +import org.session.libsignal.utilities.Util class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val message: Message, val messageSendJobID: String) : Job { override var delegate: JobDelegate? = null @@ -119,7 +115,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess InputStreamMediaDataSource(inputStream).use { mediaDataSource -> val durationMs = (DecodedAudio.create(mediaDataSource).totalDuration / 1000.0).toLong() messageDataProvider.getDatabaseAttachment(attachmentID)?.attachmentId?.let { attachmentId -> - messageDataProvider.updateAudioAttachmentDuration(attachmentId, durationMs) + messageDataProvider.updateAudioAttachmentDuration(attachmentId, durationMs, threadID.toLong()) } } } catch (e: Exception) {