mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 05:07:46 +02:00
refactor: message logger
- send timestamp - sender/conversation usernames
This commit is contained in:
@ -7,6 +7,7 @@ import android.graphics.drawable.shapes.Shape
|
||||
import android.os.DeadObjectException
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import me.rhunk.snapenhance.bridge.logger.BridgeLoggedMessage
|
||||
import me.rhunk.snapenhance.common.data.ContentType
|
||||
import me.rhunk.snapenhance.common.data.MessageState
|
||||
import me.rhunk.snapenhance.common.data.QuotedMessageContentStatus
|
||||
@ -40,6 +41,9 @@ class MessageLogger : Feature("MessageLogger",
|
||||
|
||||
private val threadPool = Executors.newFixedThreadPool(10)
|
||||
|
||||
private val usernameCache = EvictingMap<String, String>(500) // user id -> username
|
||||
private val groupTitleCache = EvictingMap<String, String?>(500) // conversation id -> group title
|
||||
|
||||
private val cachedIdLinks = EvictingMap<Long, Long>(500) // client id -> server id
|
||||
private val fetchedMessages = mutableListOf<Long>() // list of unique message ids
|
||||
private val deletedMessageCache = EvictingMap<Long, JsonObject>(200) // unique message id -> message json object
|
||||
@ -127,7 +131,21 @@ class MessageLogger : Feature("MessageLogger",
|
||||
|
||||
threadPool.execute {
|
||||
try {
|
||||
loggerInterface.addMessage(conversationId, uniqueMessageIdentifier, context.gson.toJson(messageInstance).toByteArray(Charsets.UTF_8))
|
||||
loggerInterface.addMessage(
|
||||
BridgeLoggedMessage().also {
|
||||
it.messageId = uniqueMessageIdentifier
|
||||
it.conversationId = conversationId
|
||||
it.userId = event.message.senderId.toString()
|
||||
it.username = usernameCache.getOrPut(it.userId) {
|
||||
context.database.getFriendInfo(it.userId)?.mutableUsername ?: it.userId
|
||||
}
|
||||
it.sendTimestamp = event.message.messageMetadata?.createdAt ?: System.currentTimeMillis()
|
||||
it.groupTitle = groupTitleCache.getOrPut(conversationId) {
|
||||
context.database.getFeedEntryByConversationId(conversationId)?.feedDisplayName ?: conversationId
|
||||
}
|
||||
it.messageData = context.gson.toJson(messageInstance).toByteArray(Charsets.UTF_8)
|
||||
}
|
||||
)
|
||||
} catch (ignored: DeadObjectException) {}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user