mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 05:07:46 +02:00
feat(core/message_logger): auto purge & message filter
- optimize bridge addMessage
This commit is contained in:
@ -15,12 +15,12 @@ interface MessageLoggerInterface {
|
||||
/**
|
||||
* Add a message to the message logger database if it is not already there
|
||||
*/
|
||||
boolean addMessage(String conversationId, long id, in byte[] message);
|
||||
oneway void addMessage(String conversationId, long id, in byte[] message);
|
||||
|
||||
/**
|
||||
* Delete a message from the message logger database
|
||||
*/
|
||||
void deleteMessage(String conversationId, long id);
|
||||
oneway void deleteMessage(String conversationId, long id);
|
||||
|
||||
/**
|
||||
* Add a story to the message logger database if it is not already there
|
||||
|
@ -405,7 +405,21 @@
|
||||
},
|
||||
"message_logger": {
|
||||
"name": "Message Logger",
|
||||
"description": "Prevents messages from being deleted"
|
||||
"description": "Prevents messages from being deleted",
|
||||
"properties": {
|
||||
"keep_my_own_messages": {
|
||||
"name": "Keep My Own Messages",
|
||||
"description": "Prevents your own messages from being deleted"
|
||||
},
|
||||
"auto_purge": {
|
||||
"name": "Auto Purge",
|
||||
"description": "Automatically deletes cached messages that are older than the specified amount of time"
|
||||
},
|
||||
"message_filter": {
|
||||
"name": "Message Filter",
|
||||
"description": "Select which messages should get logged (empty for all messages)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"auto_save_messages_in_conversations": {
|
||||
"name": "Auto Save Messages",
|
||||
@ -806,6 +820,20 @@
|
||||
"edit_text_override": {
|
||||
"multi_line_chat_input": "Multi Line Chat Input",
|
||||
"bypass_text_input_limit": "Bypass Text Input Limit"
|
||||
},
|
||||
"auto_purge": {
|
||||
"never": "Never",
|
||||
"1_hour": "1 Hour",
|
||||
"3_hours": "3 Hours",
|
||||
"6_hours": "6 Hours",
|
||||
"12_hours": "12 Hours",
|
||||
"1_day": "1 Day",
|
||||
"3_days": "3 Days",
|
||||
"1_week": "1 Week",
|
||||
"2_weeks": "2 Weeks",
|
||||
"1_month": "1 Month",
|
||||
"3_months": "3 Months",
|
||||
"6_months": "6 Months"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -26,12 +26,14 @@ class MessageLoggerWrapper(
|
||||
SQLiteDatabaseHelper.createTablesFromSchema(openedDatabase, mapOf(
|
||||
"messages" to listOf(
|
||||
"id INTEGER PRIMARY KEY",
|
||||
"added_timestamp BIGINT",
|
||||
"conversation_id VARCHAR",
|
||||
"message_id BIGINT",
|
||||
"message_data BLOB"
|
||||
),
|
||||
"stories" to listOf(
|
||||
"id INTEGER PRIMARY KEY",
|
||||
"added_timestamp BIGINT",
|
||||
"user_id VARCHAR",
|
||||
"posted_timestamp BIGINT",
|
||||
"created_timestamp BIGINT",
|
||||
@ -83,29 +85,33 @@ class MessageLoggerWrapper(
|
||||
return message
|
||||
}
|
||||
|
||||
override fun addMessage(conversationId: String, messageId: Long, serializedMessage: ByteArray): Boolean {
|
||||
override fun addMessage(conversationId: String, messageId: Long, serializedMessage: ByteArray) {
|
||||
val cursor = database.rawQuery("SELECT message_id FROM messages WHERE conversation_id = ? AND message_id = ?", arrayOf(conversationId, messageId.toString()))
|
||||
val state = cursor.moveToFirst()
|
||||
cursor.close()
|
||||
if (state) {
|
||||
return false
|
||||
}
|
||||
if (state) return
|
||||
runBlocking {
|
||||
withContext(coroutineScope.coroutineContext) {
|
||||
database.insert("messages", null, ContentValues().apply {
|
||||
put("added_timestamp", System.currentTimeMillis())
|
||||
put("conversation_id", conversationId)
|
||||
put("message_id", messageId)
|
||||
put("message_data", serializedMessage)
|
||||
})
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
fun purgeAll(maxAge: Long? = null) {
|
||||
coroutineScope.launch {
|
||||
database.execSQL("DELETE FROM messages")
|
||||
database.execSQL("DELETE FROM stories")
|
||||
maxAge?.let {
|
||||
val maxTime = System.currentTimeMillis() - it
|
||||
database.execSQL("DELETE FROM messages WHERE added_timestamp < ?", arrayOf(maxTime.toString()))
|
||||
database.execSQL("DELETE FROM stories WHERE added_timestamp < ?", arrayOf(maxTime.toString()))
|
||||
} ?: run {
|
||||
database.execSQL("DELETE FROM messages")
|
||||
database.execSQL("DELETE FROM stories")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,6 +147,7 @@ class MessageLoggerWrapper(
|
||||
withContext(coroutineScope.coroutineContext) {
|
||||
database.insert("stories", null, ContentValues().apply {
|
||||
put("user_id", userId)
|
||||
put("added_timestamp", System.currentTimeMillis())
|
||||
put("url", url)
|
||||
put("posted_timestamp", postedAt)
|
||||
put("created_timestamp", createdAt)
|
||||
|
@ -15,6 +15,39 @@ class MessagingTweaks : ConfigContainer() {
|
||||
}
|
||||
}
|
||||
|
||||
inner class MessageLoggerConfig : ConfigContainer(hasGlobalState = true) {
|
||||
val keepMyOwnMessages = boolean("keep_my_own_messages")
|
||||
private val autoPurge = unique("auto_purge", "1_hour", "3_hours", "6_hours", "12_hours", "1_day", "3_days", "1_week", "2_weeks", "1_month", "3_months", "6_months") {
|
||||
disabledKey = "features.options.auto_purge.never"
|
||||
}.apply { set("3_days") }
|
||||
|
||||
fun getAutoPurgeTime(): Long? {
|
||||
return when (autoPurge.getNullable()) {
|
||||
"1_hour" -> 3600000L
|
||||
"3_hours" -> 10800000L
|
||||
"6_hours" -> 21600000L
|
||||
"12_hours" -> 43200000L
|
||||
"1_day" -> 86400000L
|
||||
"3_days" -> 259200000L
|
||||
"1_week" -> 604800000L
|
||||
"2_weeks" -> 1209600000L
|
||||
"1_month" -> 2592000000L
|
||||
"3_months" -> 7776000000L
|
||||
"6_months" -> 15552000000L
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val messageFilter = multiple("message_filter", "CHAT",
|
||||
"SNAP",
|
||||
"NOTE",
|
||||
"EXTERNAL_MEDIA",
|
||||
"STICKER"
|
||||
) {
|
||||
customOptionTranslationPath = "content_type"
|
||||
}
|
||||
}
|
||||
|
||||
val bypassScreenshotDetection = boolean("bypass_screenshot_detection") { requireRestart() }
|
||||
val anonymousStoryViewing = boolean("anonymous_story_viewing")
|
||||
val preventStoryRewatchIndicator = boolean("prevent_story_rewatch_indicator") { requireRestart() }
|
||||
@ -42,7 +75,7 @@ class MessagingTweaks : ConfigContainer() {
|
||||
val notificationBlacklist = multiple("notification_blacklist", *NotificationType.getIncomingValues().map { it.key }.toTypedArray()) {
|
||||
customOptionTranslationPath = "features.options.notifications"
|
||||
}
|
||||
val messageLogger = boolean("message_logger") { addNotices(FeatureNotice.UNSTABLE); requireRestart() }
|
||||
val messageLogger = container("message_logger", MessageLoggerConfig()) { addNotices(FeatureNotice.UNSTABLE); requireRestart() }
|
||||
val galleryMediaSendOverride = boolean("gallery_media_send_override") { nativeHooks() }
|
||||
val stripMediaMetadata = multiple("strip_media_metadata", "hide_caption_text", "hide_snap_filters", "hide_extras", "remove_audio_note_duration", "remove_audio_note_transcript_capability") { requireRestart() }
|
||||
val bypassMessageRetentionPolicy = boolean("bypass_message_retention_policy") { addNotices(FeatureNotice.UNSTABLE); requireRestart() }
|
||||
|
Reference in New Issue
Block a user