mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-01 17:47:25 +00:00
fix: getting local user's ID if message is outgoing to check against that value in attachment download
This commit is contained in:
parent
1ee1d1795d
commit
fa06a57ec3
@ -119,6 +119,13 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
|||||||
), threadId)
|
), threadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isMmsOutgoing(mmsMessageId: Long): Boolean {
|
||||||
|
val mmsDb = DatabaseFactory.getMmsDatabase(context)
|
||||||
|
return mmsDb.getMessage(mmsMessageId).use { cursor ->
|
||||||
|
mmsDb.readerFor(cursor).next
|
||||||
|
}.isOutgoing
|
||||||
|
}
|
||||||
|
|
||||||
override fun isOutgoingMessage(timestamp: Long): Boolean {
|
override fun isOutgoingMessage(timestamp: Long): Boolean {
|
||||||
val smsDatabase = DatabaseFactory.getSmsDatabase(context)
|
val smsDatabase = DatabaseFactory.getSmsDatabase(context)
|
||||||
val mmsDatabase = DatabaseFactory.getMmsDatabase(context)
|
val mmsDatabase = DatabaseFactory.getMmsDatabase(context)
|
||||||
|
@ -22,7 +22,8 @@ interface MessageDataProvider {
|
|||||||
fun setAttachmentState(attachmentState: AttachmentState, attachmentId: AttachmentId, messageID: Long)
|
fun setAttachmentState(attachmentState: AttachmentState, attachmentId: AttachmentId, messageID: Long)
|
||||||
fun insertAttachment(messageId: Long, attachmentId: AttachmentId, stream : InputStream)
|
fun insertAttachment(messageId: Long, attachmentId: AttachmentId, stream : InputStream)
|
||||||
fun updateAudioAttachmentDuration(attachmentId: AttachmentId, durationMs: Long, threadId: Long)
|
fun updateAudioAttachmentDuration(attachmentId: AttachmentId, durationMs: Long, threadId: Long)
|
||||||
fun isOutgoingMessage(timestamp: Long): Boolean
|
fun isMmsOutgoing(mmsMessageId: Long): Boolean
|
||||||
|
fun isOutgoingMessage(mmsId: Long): Boolean
|
||||||
fun handleSuccessfulAttachmentUpload(attachmentId: Long, attachmentStream: SignalServiceAttachmentStream, attachmentKey: ByteArray, uploadResult: UploadResult)
|
fun handleSuccessfulAttachmentUpload(attachmentId: Long, attachmentStream: SignalServiceAttachmentStream, attachmentKey: ByteArray, uploadResult: UploadResult)
|
||||||
fun handleFailedAttachmentUpload(attachmentId: Long)
|
fun handleFailedAttachmentUpload(attachmentId: Long)
|
||||||
fun getMessageForQuote(timestamp: Long, author: Address): Pair<Long, Boolean>?
|
fun getMessageForQuote(timestamp: Long, author: Address): Pair<Long, Boolean>?
|
||||||
|
@ -29,6 +29,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
|
|||||||
object NoAttachment : Error("No such attachment.")
|
object NoAttachment : Error("No such attachment.")
|
||||||
object NoThread: Error("Thread no longer exists")
|
object NoThread: Error("Thread no longer exists")
|
||||||
object NoSender: Error("Thread recipient or sender does not exist")
|
object NoSender: Error("Thread recipient or sender does not exist")
|
||||||
|
object DuplicateData: Error("Attachment already downloaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
@ -64,20 +65,24 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (threadID < 0) {
|
if (threadID < 0) {
|
||||||
Log.e("Loki", "Thread doesn't exist for database message ID $databaseMessageID")
|
|
||||||
handleFailure(Error.NoThread, null)
|
handleFailure(Error.NoThread, null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val threadRecipient = storage.getRecipientForThread(threadID)
|
val threadRecipient = storage.getRecipientForThread(threadID)
|
||||||
val sender = messageDataProvider.getIndividualRecipientForMms(databaseMessageID)
|
val sender = if (messageDataProvider.isMmsOutgoing(databaseMessageID)) {
|
||||||
val contact = sender?.address?.let { storage.getContactWithSessionID(it.serialize()) }
|
storage.getUserPublicKey()
|
||||||
|
} else {
|
||||||
|
messageDataProvider.getIndividualRecipientForMms(databaseMessageID)?.address?.serialize()
|
||||||
|
}
|
||||||
|
val contact = sender?.let { storage.getContactWithSessionID(it) }
|
||||||
if (threadRecipient == null || sender == null || contact == null) {
|
if (threadRecipient == null || sender == null || contact == null) {
|
||||||
handleFailure(Error.NoSender, null)
|
handleFailure(Error.NoSender, null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!threadRecipient.isGroupRecipient && !(contact.isTrusted || storage.getUserPublicKey() != sender.address.serialize())) {
|
if (!threadRecipient.isGroupRecipient && (!contact.isTrusted && storage.getUserPublicKey() != sender)) {
|
||||||
Log.e("Loki", "Thread isn't a group recipient, or contact isn't trusted or self-send")
|
// if we aren't receiving a group message, a message from ourselves (self-send) and the contact sending is not trusted:
|
||||||
|
// do not continue, but do not fail
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +91,8 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
|
|||||||
val attachment = messageDataProvider.getDatabaseAttachment(attachmentID)
|
val attachment = messageDataProvider.getDatabaseAttachment(attachmentID)
|
||||||
?: return handleFailure(Error.NoAttachment, null)
|
?: return handleFailure(Error.NoAttachment, null)
|
||||||
if (attachment.hasData()) {
|
if (attachment.hasData()) {
|
||||||
Log.d("Loki", "The attachment $attachmentID already has data")
|
handleFailure(Error.DuplicateData, attachment.attachmentId)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
messageDataProvider.setAttachmentState(AttachmentState.STARTED, attachment.attachmentId, this.databaseMessageID)
|
messageDataProvider.setAttachmentState(AttachmentState.STARTED, attachment.attachmentId, this.databaseMessageID)
|
||||||
tempFile = createTempFile()
|
tempFile = createTempFile()
|
||||||
|
@ -20,7 +20,7 @@ class JobQueue : JobDelegate {
|
|||||||
private val jobTimestampMap = ConcurrentHashMap<Long, AtomicInteger>()
|
private val jobTimestampMap = ConcurrentHashMap<Long, AtomicInteger>()
|
||||||
private val rxDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
private val rxDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||||
private val txDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
private val txDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||||
private val attachmentDispatcher = Executors.newFixedThreadPool(2).asCoroutineDispatcher()
|
private val attachmentDispatcher = Executors.newFixedThreadPool(4).asCoroutineDispatcher()
|
||||||
private val scope = GlobalScope + SupervisorJob()
|
private val scope = GlobalScope + SupervisorJob()
|
||||||
private val queue = Channel<Job>(UNLIMITED)
|
private val queue = Channel<Job>(UNLIMITED)
|
||||||
private val pendingJobIds = mutableSetOf<String>()
|
private val pendingJobIds = mutableSetOf<String>()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user