From 472dbe5f2bedbd24d4a640b6da47770951ac100a Mon Sep 17 00:00:00 2001 From: Rodi Date: Thu, 19 May 2022 12:55:43 +0100 Subject: [PATCH] Fix save to camera roll in message context menu. --- .../conversations/MessageInterceptor.kt | 5 +- .../features/conversations/StealthFeature.kt | 4 +- .../snapmod/features/saving/ChatSaving.kt | 71 ++++++++++--------- app/src/main/res/xml/root_preferences.xml | 6 -- snap.ds | 14 ++++ 5 files changed, 57 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/xyz/rodit/snapmod/features/conversations/MessageInterceptor.kt b/app/src/main/java/xyz/rodit/snapmod/features/conversations/MessageInterceptor.kt index 1527929..756882c 100644 --- a/app/src/main/java/xyz/rodit/snapmod/features/conversations/MessageInterceptor.kt +++ b/app/src/main/java/xyz/rodit/snapmod/features/conversations/MessageInterceptor.kt @@ -12,7 +12,10 @@ class MessageInterceptor(context: FeatureContext) : StealthFeature(context) { putFilters( ConversationManager.sendMessageWithContent, { LocalMessageContent.wrap(it.args[1]).contentType }, - { MessageDestinations.wrap(it.args[0]).conversations[0].toUUIDString() }, + { + val conversations = MessageDestinations.wrap(it.args[0]).conversations + if (conversations.isNotEmpty()) conversations[0].toUUIDString() else null + }, ObjectFilter( context, "hide_screenshot", diff --git a/app/src/main/java/xyz/rodit/snapmod/features/conversations/StealthFeature.kt b/app/src/main/java/xyz/rodit/snapmod/features/conversations/StealthFeature.kt index 06f1b14..8f09d04 100644 --- a/app/src/main/java/xyz/rodit/snapmod/features/conversations/StealthFeature.kt +++ b/app/src/main/java/xyz/rodit/snapmod/features/conversations/StealthFeature.kt @@ -10,7 +10,7 @@ import xyz.rodit.snapmod.features.FeatureContext import xyz.rodit.snapmod.features.shared.Filter typealias FilterObjectSupplier = (MethodHookParam) -> Any? -typealias ConversationIdSupplier = (MethodHookParam) -> String +typealias ConversationIdSupplier = (MethodHookParam) -> String? abstract class StealthFeature(context: FeatureContext) : Feature(context) { @@ -55,7 +55,7 @@ abstract class StealthFeature(context: FeatureContext) : Feature(context) { MappedObject.hook(className, methodName, object : XC_MethodHook() { override fun beforeHookedMethod(param: MethodHookParam) { val obj = supplier?.invoke(param) - val id = conversationIdSupplier!!.invoke(param) + val id = conversationIdSupplier?.invoke(param) ?: return val stealth = context.stealth.isEnabled(id) if (filters[methodName]!!.any { f -> diff --git a/app/src/main/java/xyz/rodit/snapmod/features/saving/ChatSaving.kt b/app/src/main/java/xyz/rodit/snapmod/features/saving/ChatSaving.kt index 20fca01..dbe7730 100644 --- a/app/src/main/java/xyz/rodit/snapmod/features/saving/ChatSaving.kt +++ b/app/src/main/java/xyz/rodit/snapmod/features/saving/ChatSaving.kt @@ -65,40 +65,43 @@ class ChatSaving(context: FeatureContext) : Feature(context) { val base = ChatModelBase.wrap(it.args[2]) lastMessageData = base.messageData - if (ChatModelLiveSnap.isInstance(it.args[2])) { - // Convert live snap to saved snap. - val hashCode = it.args[2].hashCode() - val media = LiveSnapMedia.wrap(chatMediaMap[hashCode]) - it.args[2] = ChatModelSavedSnap( - base.context, - base.messageData, - base.senderId, - emptyMap(), - true, - base.reactionsViewModel, - true, - 0, - 0, - media, - null, - base.status, - true, - true - ).instance - } else if (ChatModelAudioNote.isInstance(it.args[2])) { - val audio = ChatModelAudioNote.wrap(it.args[2]) - resolveAndDownload(audio.uri, base.messageData) - - it.result = null - } else if (ChatModelPlugin.isInstance(it.args[2])) { - val messageData = base.messageData - - if (messageData.type != "audio_note") return@before - val media = GallerySnapMedia.wrap(messageData.media.instance).media - val uri = createMediaUri(messageData.arroyoMessageId, media.id) - - resolveAndDownload(uri, messageData) - it.result = null + when { + ChatModelLiveSnap.isInstance(it.args[2]) -> { + // Convert live snap to saved snap. + val hashCode = it.args[2].hashCode() + val media = LiveSnapMedia.wrap(chatMediaMap[hashCode]) + it.args[2] = ChatModelSavedSnap( + base.context, + base.messageData, + base.senderId, + emptyMap(), + true, + base.reactionsViewModel, + true, + 0, + 0, + media, + null, + base.status, + true, + true + ).instance + } + ChatModelAudioNote.isInstance(it.args[2]) -> { + val audio = ChatModelAudioNote.wrap(it.args[2]) + resolveAndDownload(audio.uri, base.messageData) + it.result = null + } + ChatModelPlugin.isInstance(it.args[2]) -> { + val messageData = base.messageData + + if (messageData.type != "audio_note") return@before + val media = GallerySnapMedia.wrap(messageData.media.instance).media + val uri = createMediaUri(messageData.arroyoMessageId, media.id) + + resolveAndDownload(uri, messageData) + it.result = null + } } } diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index c9e8c63..e3cf605 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -91,12 +91,6 @@ - -