mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Merge pull request #1492 from simophin/ses-1931-fix-debouncer
[SES-1931] - Fix debouncer crash
This commit is contained in:
commit
410e298bca
@ -5,9 +5,9 @@ import android.content.Context
|
||||
import org.session.libsession.utilities.Debouncer
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
|
||||
class ConversationNotificationDebouncer(private val context: Context) {
|
||||
class ConversationNotificationDebouncer(private val context: ApplicationContext) {
|
||||
private val threadIDs = mutableSetOf<Long>()
|
||||
private val handler = (context.applicationContext as ApplicationContext).conversationListNotificationHandler
|
||||
private val handler = context.conversationListNotificationHandler
|
||||
private val debouncer = Debouncer(handler, 100)
|
||||
|
||||
companion object {
|
||||
@ -17,20 +17,28 @@ class ConversationNotificationDebouncer(private val context: Context) {
|
||||
@Synchronized
|
||||
fun get(context: Context): ConversationNotificationDebouncer {
|
||||
if (::shared.isInitialized) { return shared }
|
||||
shared = ConversationNotificationDebouncer(context)
|
||||
shared = ConversationNotificationDebouncer(context.applicationContext as ApplicationContext)
|
||||
return shared
|
||||
}
|
||||
}
|
||||
|
||||
fun notify(threadID: Long) {
|
||||
threadIDs.add(threadID)
|
||||
synchronized(threadIDs) {
|
||||
threadIDs.add(threadID)
|
||||
}
|
||||
|
||||
debouncer.publish { publish() }
|
||||
}
|
||||
|
||||
private fun publish() {
|
||||
for (threadID in threadIDs.toList()) {
|
||||
val toNotify = synchronized(threadIDs) {
|
||||
val copy = threadIDs.toList()
|
||||
threadIDs.clear()
|
||||
copy
|
||||
}
|
||||
|
||||
for (threadID in toNotify) {
|
||||
context.contentResolver.notifyChange(DatabaseContentProviders.Conversation.getUriForThread(threadID), null)
|
||||
}
|
||||
threadIDs.clear()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user