mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-07 18:04:32 +02:00
feat(message_logger): quoted messages support
This commit is contained in:
parent
ec0fd2cf08
commit
a95c75a0b6
@ -158,4 +158,13 @@ enum class MixerStoryType(
|
||||
return entries.firstOrNull { it.index == index } ?: UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class QuotedMessageContentStatus {
|
||||
UNKNOWN,
|
||||
AVAILABLE,
|
||||
DELETED,
|
||||
JOINEDAFTERORIGINALMESSAGESENT,
|
||||
UNAVAILABLE,
|
||||
STORYMEDIADELETEDBYPOSTER
|
||||
}
|
@ -27,9 +27,9 @@ class EventBus(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T : Event> subscribe(event: KClass<T>, priority: Int? = null, crossinline listener: (T) -> Unit) = subscribe(event, { true }, priority, listener)
|
||||
fun <T : Event> subscribe(event: KClass<T>, priority: Int? = null, listener: (T) -> Unit) = subscribe(event, { true }, priority, listener)
|
||||
|
||||
inline fun <T : Event> subscribe(event: KClass<T>, crossinline filter: (T) -> Boolean, priority: Int? = null, crossinline listener: (T) -> Unit): () -> Unit {
|
||||
fun <T : Event> subscribe(event: KClass<T>, filter: (T) -> Boolean, priority: Int? = null, listener: (T) -> Unit): () -> Unit {
|
||||
val obj = object : IListener<T> {
|
||||
override fun handle(event: T) {
|
||||
if (!filter(event)) return
|
||||
|
@ -9,6 +9,7 @@ import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import me.rhunk.snapenhance.common.data.ContentType
|
||||
import me.rhunk.snapenhance.common.data.MessageState
|
||||
import me.rhunk.snapenhance.common.data.QuotedMessageContentStatus
|
||||
import me.rhunk.snapenhance.common.util.ktx.longHashCode
|
||||
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
|
||||
import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent
|
||||
@ -38,7 +39,7 @@ class MessageLogger : Feature("MessageLogger",
|
||||
|
||||
private val threadPool = Executors.newFixedThreadPool(10)
|
||||
|
||||
private val cachedIdLinks = mutableMapOf<Long, Long>() // client id -> server id
|
||||
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
|
||||
|
||||
@ -112,8 +113,11 @@ class MessageLogger : Feature("MessageLogger",
|
||||
|
||||
val uniqueMessageIdentifier = computeMessageIdentifier(conversationId, event.message.orderKey!!)
|
||||
val messageContentType = event.message.messageContent!!.contentType
|
||||
val isMessageDeleted = messageContentType == ContentType.STATUS || event.message.messageContent!!.quotedMessage?.status?.let {
|
||||
it == QuotedMessageContentStatus.DELETED || it == QuotedMessageContentStatus.STORYMEDIADELETEDBYPOSTER
|
||||
} == true
|
||||
|
||||
if (messageContentType != ContentType.STATUS) {
|
||||
if (!isMessageDeleted) {
|
||||
if (messageFilter.isNotEmpty() && !messageFilter.contains(messageContentType?.name)) return@subscribe
|
||||
if (fetchedMessages.contains(uniqueMessageIdentifier)) return@subscribe
|
||||
fetchedMessages.add(uniqueMessageIdentifier)
|
||||
@ -136,18 +140,16 @@ class MessageLogger : Feature("MessageLogger",
|
||||
}
|
||||
} ?: return@subscribe
|
||||
|
||||
val messageJsonObject = deletedMessageObject.asJsonObject
|
||||
|
||||
//if the message is a snap make it playable
|
||||
if (messageJsonObject["mMessageContent"]?.asJsonObject?.get("mContentType")?.asString == "SNAP") {
|
||||
messageJsonObject["mMetadata"].asJsonObject.addProperty("mPlayableSnapState", "PLAYABLE")
|
||||
if (deletedMessageObject["mMessageContent"]?.asJsonObject?.get("mContentType")?.asString == "SNAP") {
|
||||
deletedMessageObject["mMetadata"].asJsonObject.addProperty("mPlayableSnapState", "PLAYABLE")
|
||||
}
|
||||
|
||||
//serialize all properties of messageJsonObject and put mMessageContent & mMetadata in the message object
|
||||
messageInstance.javaClass.declaredFields.forEach { field ->
|
||||
messageInstance::class.java.declaredFields.forEach { field ->
|
||||
if (field.name != "mMessageContent" && field.name != "mMetadata") return@forEach
|
||||
field.isAccessible = true
|
||||
messageJsonObject[field.name]?.let { fieldValue ->
|
||||
deletedMessageObject[field.name]?.let { fieldValue ->
|
||||
field.set(messageInstance, context.gson.fromJson(fieldValue, field.type))
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ abstract class AbstractWrapper(
|
||||
protected fun <T> field(fieldName: String, mapper: ((Any?) -> T?)? = null) = FieldAccessor(fieldName, mapper)
|
||||
|
||||
fun <T : Enum<*>> getEnumValue(fieldName: String, defaultValue: T?): T? {
|
||||
if (defaultValue == null) return null
|
||||
if (defaultValue == null || instance == null) return null
|
||||
val mContentType = XposedHelpers.getObjectField(instance, fieldName) as? Enum<*> ?: return null
|
||||
return java.lang.Enum.valueOf(defaultValue::class.java, mContentType.name)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.rhunk.snapenhance.core.wrapper.impl
|
||||
|
||||
import me.rhunk.snapenhance.common.data.QuotedMessageContentStatus
|
||||
import me.rhunk.snapenhance.core.wrapper.AbstractWrapper
|
||||
import org.mozilla.javascript.annotations.JSGetter
|
||||
import org.mozilla.javascript.annotations.JSSetter
|
||||
@ -7,4 +8,6 @@ import org.mozilla.javascript.annotations.JSSetter
|
||||
class QuotedMessage(obj: Any?) : AbstractWrapper(obj) {
|
||||
@get:JSGetter @set:JSSetter
|
||||
var content by field("mContent") { QuotedMessageContent(it) }
|
||||
@get:JSGetter
|
||||
val status by enum("mStatus", QuotedMessageContentStatus.UNKNOWN)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user