mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Fixes #1483
This commit is contained in:
parent
1354bccb59
commit
8c31c83fc5
@ -298,6 +298,13 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
private val reverseMessageList = false
|
||||
|
||||
private val adapter by lazy {
|
||||
|
||||
// To prevent repeated attachment download jobs being spawned we'll keep a set of what
|
||||
// attachmentId / mmsId pairs we've already attempted to download and only spawn the job
|
||||
// if we haven't already done so. Without this then when the retry limit for a failed job
|
||||
// hits another job is immediately spawned (endlessly).
|
||||
var alreadyAttemptedAttachmentDownloadPairs = mutableSetOf<Pair<Long, Long>>()
|
||||
|
||||
val cursor = mmsSmsDb.getConversation(viewModel.threadId, reverseMessageList)
|
||||
val adapter = ConversationAdapter(
|
||||
this,
|
||||
@ -325,9 +332,15 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
},
|
||||
onAttachmentNeedsDownload = { attachmentId, mmsId ->
|
||||
// Start download (on IO thread)
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
JobQueue.shared.add(AttachmentDownloadJob(attachmentId, mmsId))
|
||||
// Keep track of this specific attachment so we don't download it again
|
||||
val pair = Pair(attachmentId, mmsId)
|
||||
if (!alreadyAttemptedAttachmentDownloadPairs.contains(pair)) {
|
||||
alreadyAttemptedAttachmentDownloadPairs.add(pair)
|
||||
|
||||
// Start download (on IO thread)
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
JobQueue.shared.add(AttachmentDownloadJob(attachmentId, mmsId))
|
||||
}
|
||||
}
|
||||
},
|
||||
glide = glide,
|
||||
@ -335,8 +348,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
)
|
||||
adapter.visibleMessageViewDelegate = this
|
||||
|
||||
// Register an AdapterDataObserver to scroll us to the bottom of the RecyclerView if we're
|
||||
// already near the the bottom and the data changes.
|
||||
// Register an AdapterDataObserver to scroll us to the bottom of the RecyclerView for if
|
||||
// we're already near the the bottom and the data changes.
|
||||
adapter.registerAdapterDataObserver(ConversationAdapterDataObserver(binding?.conversationRecyclerView!!, adapter))
|
||||
|
||||
adapter
|
||||
|
@ -305,7 +305,12 @@ public class MmsSmsDatabase extends Database {
|
||||
}
|
||||
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_SENT + " DESC";
|
||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
||||
|
||||
// As the MmsSmsDatabase.ADDRESS column never contains the sender address we have to get creative to filter down all the
|
||||
// messages that have been sent without interrogating each MessageRecord returned by the cursor. One way to do this is
|
||||
// via the fact that the `ADDRESS_DEVICE_ID` is always null for incoming messages, but always has a value (such as 1) for
|
||||
// outgoing messages - so we'll filter our query for only records with non-null ADDRESS_DEVICE_IDs in the current thread.
|
||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " + MmsSmsColumns.ADDRESS_DEVICE_ID + " IS NOT NULL";
|
||||
|
||||
// Try everything with resources so that they auto-close on end of scope
|
||||
try (Cursor cursor = queryTables(PROJECTION, selection, order, null)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user