Fix excessive last sent calls
parent
cf13caaee4
commit
4904524af5
@ -0,0 +1,38 @@
|
|||||||
|
package org.thoughtcrime.securesms.database
|
||||||
|
|
||||||
|
import org.session.libsession.messaging.LastSentTimestampCache
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class LastSentTimestampCache @Inject constructor(
|
||||||
|
val mmsSmsDatabase: MmsSmsDatabase
|
||||||
|
): LastSentTimestampCache {
|
||||||
|
|
||||||
|
private val map = mutableMapOf<Long, Long>()
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun getTimestamp(threadId: Long): Long? = map[threadId]
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun submitTimestamp(threadId: Long, timestamp: Long) {
|
||||||
|
if (map[threadId]?.let { timestamp <= it } == true) return
|
||||||
|
|
||||||
|
map[threadId] = timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun delete(threadId: Long, timestamps: List<Long>) {
|
||||||
|
if (map[threadId]?.let { it !in timestamps } == true) return
|
||||||
|
map.remove(threadId)
|
||||||
|
refresh(threadId)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun refresh(threadId: Long) {
|
||||||
|
if (map[threadId]?.let { it > 0 } == true) return
|
||||||
|
val lastOutgoingTimestamp = mmsSmsDatabase.getLastOutgoingTimestamp(threadId)
|
||||||
|
if (lastOutgoingTimestamp <= 0) return
|
||||||
|
map[threadId] = lastOutgoingTimestamp
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package org.session.libsession.messaging
|
||||||
|
|
||||||
|
interface LastSentTimestampCache {
|
||||||
|
fun getTimestamp(threadId: Long): Long?
|
||||||
|
fun submitTimestamp(threadId: Long, timestamp: Long)
|
||||||
|
fun delete(threadId: Long, timestamps: List<Long>)
|
||||||
|
fun delete(threadId: Long, timestamp: Long) = delete(threadId, listOf(timestamp))
|
||||||
|
fun refresh(threadId: Long)
|
||||||
|
}
|
Loading…
Reference in New Issue