mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
fix: notify update for attachment's thread ID on setting audio extras
This commit is contained in:
parent
0b51b8f0b3
commit
683b5243bd
@ -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
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -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<InputStream> {
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user