Skip to content

Commit

Permalink
fix: disable memories snap feed
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Mar 8, 2024
1 parent db2cc0d commit b4f6e4f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class ConfigKeyInfo(
data class ConfigFilter(
val filter: (ConfigKeyInfo) -> Boolean,
val defaultValue: (ConfigKeyInfo) -> Any?,
val isAppExperiment: Boolean = false
val isAppExperiment: Boolean?
)

class ConfigurationOverride : Feature("Configuration Override", loadParams = FeatureLoadParams.INIT_SYNC) {
Expand Down Expand Up @@ -67,7 +67,6 @@ class ConfigurationOverride : Feature("Configuration Override", loadParams = Fea
arrayOf("CUSTOM_AD_TRACKER_URL", "CUSTOM_AD_INIT_SERVER_URL", "CUSTOM_AD_SERVER_URL", "INIT_PRIMARY_URL", "INIT_SHADOW_URL", "GRAPHENE_HOST").forEach {
overrideProperty(it, { context.config.global.blockAds.get() }, { "http://127.0.0.1" })
}
overrideProperty("ENABLE_SNAP_FEED", { context.config.global.disableMemoriesSnapFeed.get() }, { false })

classReference.getAsClass()?.hook(
getProperty.getAsString()!!,
Expand Down Expand Up @@ -110,7 +109,7 @@ class ConfigurationOverride : Feature("Configuration Override", loadParams = Fea
return@hook
}
propertyOverrides[keyInfo.name]?.let { (filter, value, isAppExperiment) ->
if (!isAppExperiment || !filter(keyInfo)) return@let
if (isAppExperiment != true || !filter(keyInfo)) return@let
param.setResult(value(keyInfo))
}
}
Expand All @@ -134,7 +133,7 @@ class ConfigurationOverride : Feature("Configuration Override", loadParams = Fea
}

val propertyOverride = propertyOverrides[keyInfo.name] ?: return@hook
if (propertyOverride.isAppExperiment && propertyOverride.filter(keyInfo)) param.setResult(true)
propertyOverride.isAppExperiment.takeIf { propertyOverride.filter(keyInfo) }?.let { param.setResult(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.rhunk.snapenhance.core.features.impl.global

import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.util.hook.HookStage
import me.rhunk.snapenhance.core.util.hook.hook
import me.rhunk.snapenhance.mapper.impl.MemoriesPresenterMapper

class DisableMemoriesSnapFeed : Feature("Disable Memories Snap Feed", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
override fun onActivityCreate() {
if (!context.config.global.disableMemoriesSnapFeed.get()) return

context.mappings.useMapper(MemoriesPresenterMapper::class) {
classReference.get()?.apply {
val getNameMethod = getMethod("getName") ?: return@apply

hook(onNavigationEventMethod.get()!!, HookStage.BEFORE) { param ->
val instance = param.thisObject<Any>()

if (getNameMethod.invoke(instance) == "MemoriesAsyncPresenterFragmentSubscriber") {
param.setResult(null)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class FeatureManager(
SessionEvents(),
DefaultVolumeControls(),
CallRecorder(),
DisableMemoriesSnapFeed(),
)

initializeFeatures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ClassMapper(
ViewBinderMapper(),
FriendingDataSourcesMapper(),
OperaViewerParamsMapper(),
MemoriesPresenterMapper(),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.rhunk.snapenhance.mapper.impl

import me.rhunk.snapenhance.mapper.AbstractClassMapper
import me.rhunk.snapenhance.mapper.ext.findConstString
import me.rhunk.snapenhance.mapper.ext.getClassName

class MemoriesPresenterMapper : AbstractClassMapper("MemoriesPresenter") {
val classReference = classReference("class")
val onNavigationEventMethod = string("onNavigationEventMethod")

init {
mapper {
for (clazz in classes) {
if (clazz.interfaces.size != 1) continue
val getNameMethod = clazz.methods.firstOrNull { it.name == "getName" } ?: continue
if (getNameMethod.implementation?.findConstString("MemoriesAsyncPresenterFragmentSubscriber") != true) continue

val onNavigationEvent = clazz.methods.firstOrNull { it.implementation?.findConstString("Memories") == true } ?: continue

classReference.set(clazz.getClassName())
onNavigationEventMethod.set(onNavigationEvent.name)
}
}
}
}

0 comments on commit b4f6e4f

Please sign in to comment.