mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 15:08:25 +00:00
Simplify MarkReadReceiver#process
This commit is contained in:
parent
17f41d76b8
commit
3d6c7dbae4
@ -56,43 +56,36 @@ class MarkReadReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun process(context: Context, markedReadMessages: List<MarkedMessageInfo>) {
|
fun process(context: Context, markedReadMessages: List<MarkedMessageInfo>) {
|
||||||
|
if (markedReadMessages.isEmpty()) return
|
||||||
|
|
||||||
val loki = DatabaseComponent.get(context).lokiMessageDatabase()
|
val loki = DatabaseComponent.get(context).lokiMessageDatabase()
|
||||||
|
|
||||||
task {
|
task {
|
||||||
val hashToInfo = markedReadMessages.associateByNotNull { loki.getMessageServerHash(it.expirationInfo.id) }
|
val hashToInfo = markedReadMessages.associateByNotNull { loki.getMessageServerHash(it.expirationInfo.id) }
|
||||||
|
|
||||||
if (hashToInfo.isEmpty()) return@task
|
if (hashToInfo.isEmpty()) return@task
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val hashToExpiry = SnodeAPI.getExpiries(hashToInfo.keys.toList(), TextSecurePreferences.getLocalNumber(context)!!)
|
val expiries = SnodeAPI.getExpiries(hashToInfo.keys.toList(), TextSecurePreferences.getLocalNumber(context)!!)
|
||||||
.get()["expiries"] as Map<String, Long>
|
.get()["expiries"] as Map<String, Long>
|
||||||
|
|
||||||
hashToInfo.forEach { (hash, info) -> hashToExpiry[hash]?.let { scheduleDeletion(context, info.expirationInfo, it - info.expirationInfo.expireStarted) } }
|
hashToInfo.forEach { (hash, info) -> expiries[hash]?.let { scheduleDeletion(context, info.expirationInfo, it - info.expirationInfo.expireStarted) } }
|
||||||
} fail {
|
} fail {
|
||||||
Log.e(TAG, "process() disappear after read failed", it)
|
Log.e(TAG, "process() disappear after read failed", it)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (markedReadMessages.isEmpty()) return
|
markedReadMessages.forEach { scheduleDeletion(context, it.expirationInfo) }
|
||||||
for (messageInfo in markedReadMessages) {
|
|
||||||
scheduleDeletion(context, messageInfo.expirationInfo)
|
|
||||||
}
|
|
||||||
if (!isReadReceiptsEnabled(context)) return
|
if (!isReadReceiptsEnabled(context)) return
|
||||||
|
|
||||||
val addressMap = Stream.of(markedReadMessages)
|
markedReadMessages.map { it.syncMessageId }
|
||||||
.map { it.syncMessageId }
|
.filter { shouldSendReadReceipt(Recipient.from(context, it.address, false)) }
|
||||||
.collect(Collectors.groupingBy { it.address } )
|
.groupBy { it.address }
|
||||||
|
.forEach { (address, messages) ->
|
||||||
for (address in addressMap.keys) {
|
messages.map { it.timetamp }
|
||||||
val timestamps = addressMap[address]!!.map { obj: SyncMessageId -> obj.timetamp }
|
.let(::ReadReceipt)
|
||||||
if (!shouldSendReadReceipt(Recipient.from(context, address, false))) {
|
.apply { sentTimestamp = nowWithOffset }
|
||||||
continue
|
.let { send(it, address) }
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadReceipt(timestamps)
|
|
||||||
.apply { sentTimestamp = nowWithOffset }
|
|
||||||
.let { send(it, address) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scheduleDeletion(
|
fun scheduleDeletion(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user