mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 05:07:46 +02:00
Merge branch 'main' into refactor_2_0_0
# Conflicts: # app/build.gradle.kts # app/src/main/kotlin/me/rhunk/snapenhance/config/ConfigProperty.kt # core/.gitignore # core/src/main/kotlin/me/rhunk/snapenhance/features/impl/tweaks/GalleryMediaSendOverride.kt
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
"check_for_updates": "Check for updates",
|
||||
"export_chat_messages": "Export chat messages"
|
||||
},
|
||||
|
||||
|
||||
"property": {
|
||||
"message_logger": {
|
||||
"name": "Message Logger",
|
||||
@ -294,7 +294,7 @@
|
||||
"abandon_video": "Missed Video Call"
|
||||
},
|
||||
"gallery_media_send_override": {
|
||||
"OFF": "Off",
|
||||
"ORIGINAL": "Original",
|
||||
"NOTE": "Audio Note",
|
||||
"SNAP": "Snap",
|
||||
"LIVE_SNAP": "Snap with audio"
|
||||
@ -363,6 +363,10 @@
|
||||
"close": "Close"
|
||||
},
|
||||
|
||||
"gallery_media_send_override": {
|
||||
"multiple_media_toast": "You can only send one media at a time"
|
||||
},
|
||||
|
||||
"conversation_preview": {
|
||||
"streak_expiration": "expires in {day} days {hour} hours {minute} minutes",
|
||||
"total_messages": "Total sent/received messages: {count}",
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.rhunk.snapenhance.features.impl.tweaks
|
||||
|
||||
import android.app.AlertDialog
|
||||
import me.rhunk.snapenhance.config.ConfigProperty
|
||||
import me.rhunk.snapenhance.data.ContentType
|
||||
import me.rhunk.snapenhance.data.MessageSender
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.MessageContent
|
||||
@ -12,36 +14,62 @@ import me.rhunk.snapenhance.util.protobuf.ProtoReader
|
||||
|
||||
class GalleryMediaSendOverride : Feature("Gallery Media Send Override", loadParams = FeatureLoadParams.INIT_SYNC) {
|
||||
override fun init() {
|
||||
Hooker.hook(context.classCache.conversationManager, "sendMessageWithContent", HookStage.BEFORE) { param ->
|
||||
val overrideType = context.config.messaging.galleryMediaSendOverride.getNullable() ?: return@hook
|
||||
val typeNames = listOf(
|
||||
"ORIGINAL",
|
||||
"SNAP",
|
||||
"LIVE_SNAP",
|
||||
"NOTE"
|
||||
).associateWith {
|
||||
context.translation[ConfigProperty.GALLERY_MEDIA_SEND_OVERRIDE.getOptionTranslationKey(it)]
|
||||
}
|
||||
|
||||
Hooker.hook(context.classCache.conversationManager, "sendMessageWithContent", HookStage.BEFORE, {
|
||||
context.config.bool(ConfigProperty.GALLERY_MEDIA_SEND_OVERRIDE)
|
||||
}) { param ->
|
||||
val localMessageContent = MessageContent(param.arg(1))
|
||||
if (localMessageContent.contentType != ContentType.EXTERNAL_MEDIA) return@hook
|
||||
//story replies
|
||||
|
||||
//prevent story replies
|
||||
val messageProtoReader = ProtoReader(localMessageContent.content)
|
||||
if (messageProtoReader.exists(7)) return@hook
|
||||
|
||||
if (messageProtoReader.readPath(3)?.getCount(3) != 1) {
|
||||
context.runOnUiThread {
|
||||
ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity!!)
|
||||
.setMessage("You can only send one media at a time")
|
||||
.setPositiveButton("OK", null)
|
||||
.show()
|
||||
}
|
||||
param.setResult(null)
|
||||
return@hook
|
||||
}
|
||||
param.setResult(null)
|
||||
|
||||
when (overrideType) {
|
||||
"SNAP", "LIVE_SNAP" -> {
|
||||
localMessageContent.contentType = ContentType.SNAP
|
||||
localMessageContent.content = MessageSender.redSnapProto(overrideType == "LIVE_SNAP")
|
||||
}
|
||||
"NOTE" -> {
|
||||
localMessageContent.contentType = ContentType.NOTE
|
||||
val mediaDuration = messageProtoReader.getLong(3, 3, 5, 1, 1, 15) ?: 0
|
||||
localMessageContent.content = MessageSender.audioNoteProto(mediaDuration)
|
||||
}
|
||||
context.runOnUiThread {
|
||||
ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity!!)
|
||||
.setItems(typeNames.values.toTypedArray()) { dialog, which ->
|
||||
dialog.dismiss()
|
||||
val overrideType = typeNames.keys.toTypedArray()[which]
|
||||
|
||||
if (overrideType != "ORIGINAL" && messageProtoReader.readPath(3)?.getCount(3) != 1) {
|
||||
context.runOnUiThread {
|
||||
ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity!!)
|
||||
.setMessage(context.translation["gallery_media_send_override.multiple_media_toast"])
|
||||
.setPositiveButton(context.translation["button.ok"], null)
|
||||
.show()
|
||||
}
|
||||
return@setItems
|
||||
}
|
||||
|
||||
when (overrideType) {
|
||||
"SNAP", "LIVE_SNAP" -> {
|
||||
localMessageContent.contentType = ContentType.SNAP
|
||||
localMessageContent.content = MessageSender.redSnapProto(overrideType == "LIVE_SNAP")
|
||||
}
|
||||
|
||||
"NOTE" -> {
|
||||
localMessageContent.contentType = ContentType.NOTE
|
||||
val mediaDuration =
|
||||
messageProtoReader.getLong(3, 3, 5, 1, 1, 15) ?: 0
|
||||
localMessageContent.content =
|
||||
MessageSender.audioNoteProto(mediaDuration)
|
||||
}
|
||||
}
|
||||
|
||||
param.invokeOriginal()
|
||||
}
|
||||
.setNegativeButton(context.translation["button.cancel"], null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user