Skip to content

Commit

Permalink
Fix save to camera roll in message context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodit committed May 19, 2022
1 parent 7cc0e19 commit 472dbe5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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 ->
Expand Down
71 changes: 37 additions & 34 deletions app/src/main/java/xyz/rodit/snapmod/features/saving/ChatSaving.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any?, Any>(),
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<Any?, Any>(),
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
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@
<PreferenceCategory app:title="@string/tweaks_header"
app:iconSpaceReserved="false">

<SwitchPreferenceCompat
app:key="save_any"
app:title="@string/save_any_title"
app:summary="@string/save_any_description"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
app:key="allow_pin_chats"
app:title="@string/allow_pin_chats_title"
Expand Down
14 changes: 14 additions & 0 deletions snap.ds
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ class ChatModelBase {
[discard] boolean bm0()
[discard] boolean bm1()
[discard] boolean bm2()
[discard] boolean bm3()
[discard] boolean bm4()
[discard] boolean bm5()
[discard] boolean bm6()
[discard] boolean bm7()
[discard] boolean bm8()
[discard] boolean bm9()
[discard] boolean bm10()
[discard] boolean bm11()
[discard] boolean bm12()
[discard] boolean bm13()
[discard] boolean bm14()
[discard] boolean bm15()
[discard] boolean bm16()

boolean canSave()
!SaveType getSaveType()
Expand Down

0 comments on commit 472dbe5

Please sign in to comment.