anti auto download

This commit is contained in:
rhunk
2023-05-15 23:54:29 +02:00
parent 69158c70fc
commit c4349dbcd3
6 changed files with 57 additions and 45 deletions

View File

@@ -22,7 +22,7 @@ class FileAccessRequest(
} }
enum class FileType(val value: Int) { enum class FileType(val value: Int) {
CONFIG(0), MAPPINGS(1), STEALTH(2); CONFIG(0), MAPPINGS(1), STEALTH(2), ANTI_AUTO_DOWNLOAD(3);
companion object { companion object {
fun fromValue(value: Int): FileType? { fun fromValue(value: Int): FileType? {

View File

@@ -17,6 +17,7 @@ class BridgeService : Service() {
const val MAPPINGS_FILE = "mappings.json" const val MAPPINGS_FILE = "mappings.json"
const val STEALTH_FILE = "stealth.txt" const val STEALTH_FILE = "stealth.txt"
const val MESSAGE_LOGGER_DATABASE = "message_logger" const val MESSAGE_LOGGER_DATABASE = "message_logger"
const val ANTI_AUTO_DOWNLOAD_FILE = "anti_auto_download.txt"
} }
lateinit var messageLoggerDatabase: SQLiteDatabase lateinit var messageLoggerDatabase: SQLiteDatabase
@@ -144,6 +145,7 @@ class BridgeService : Service() {
FileAccessRequest.FileType.CONFIG -> CONFIG_FILE FileAccessRequest.FileType.CONFIG -> CONFIG_FILE
FileAccessRequest.FileType.MAPPINGS -> MAPPINGS_FILE FileAccessRequest.FileType.MAPPINGS -> MAPPINGS_FILE
FileAccessRequest.FileType.STEALTH -> STEALTH_FILE FileAccessRequest.FileType.STEALTH -> STEALTH_FILE
FileAccessRequest.FileType.ANTI_AUTO_DOWNLOAD -> ANTI_AUTO_DOWNLOAD_FILE
else -> throw Exception("Unknown file type: " + msg.fileType) else -> throw Exception("Unknown file type: " + msg.fileType)
}.let { File(filesDir, it) } }.let { File(filesDir, it) }

View File

@@ -37,27 +37,33 @@ enum class ConfigProperty(
), ),
MESSAGE_LOGGER("message_logger", "description.message_logger", ConfigCategory.SPY, false), MESSAGE_LOGGER("message_logger", "description.message_logger", ConfigCategory.SPY, false),
MEDIA_DOWNLOADER_FEATURE( MEDIA_DOWNLOADER(
"media_downloader_feature", "media_downloader",
"description.media_downloader_feature", "description.media_downloader",
ConfigCategory.MEDIA_DOWNLOADER, ConfigCategory.MEDIA_DOWNLOADER,
true true
), ),
DOWNLOAD_STORIES( AUTO_DOWNLOAD_SNAPS(
"download_stories", "auto_download_snaps",
"description.download_stories", "description.auto_download_snaps",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
AUTO_DOWNLOAD_STORIES(
"auto_download_stories",
"description.auto_download_stories",
ConfigCategory.MEDIA_DOWNLOADER, ConfigCategory.MEDIA_DOWNLOADER,
false false
), ),
DOWNLOAD_PUBLIC_STORIES( AUTO_DOWNLOAD_PUBLIC_STORIES(
"download_public_stories", "auto_download_public_stories",
"description.download_public_stories", "description.auto_download_public_stories",
ConfigCategory.MEDIA_DOWNLOADER, ConfigCategory.MEDIA_DOWNLOADER,
false false
), ),
DOWNLOAD_SPOTLIGHT( AUTO_DOWNLOAD_SPOTLIGHT(
"download_spotlight", "auto_download_spotlight",
"description.download_spotlight", "description.auto_download_spotlight",
ConfigCategory.MEDIA_DOWNLOADER, ConfigCategory.MEDIA_DOWNLOADER,
false false
), ),
@@ -73,6 +79,12 @@ enum class ConfigProperty(
ConfigCategory.MEDIA_DOWNLOADER, ConfigCategory.MEDIA_DOWNLOADER,
true true
), ),
ANTI_DOWNLOAD_BUTTON(
"anti_download_button",
"description.anti_download_button",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
DISABLE_METRICS("disable_metrics", "description.disable_metrics", ConfigCategory.PRIVACY, true), DISABLE_METRICS("disable_metrics", "description.disable_metrics", ConfigCategory.PRIVACY, true),
PREVENT_SCREENSHOTS( PREVENT_SCREENSHOTS(

View File

@@ -241,10 +241,16 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
forceDownload: Boolean forceDownload: Boolean
) { ) {
//messages //messages
if (paramMap.containsKey("MESSAGE_ID")) { if (paramMap.containsKey("MESSAGE_ID") &&
(forceDownload || context.config.bool(ConfigProperty.AUTO_DOWNLOAD_SNAPS))) {
val id = paramMap["MESSAGE_ID"].toString() val id = paramMap["MESSAGE_ID"].toString()
val messageId = id.substring(id.lastIndexOf(":") + 1).toLong() val messageId = id.substring(id.lastIndexOf(":") + 1).toLong()
val senderId: String = context.database.getConversationMessageFromId(messageId)!!.sender_id!! val senderId: String = context.database.getConversationMessageFromId(messageId)!!.sender_id!!
if (context.feature(AntiAutoDownload::class).isUserIgnored(senderId)) {
return
}
val author = context.database.getFriendInfo(senderId)!!.usernameForSorting!! val author = context.database.getFriendInfo(senderId)!!.usernameForSorting!!
downloadOperaMedia(mediaInfoMap, author) downloadOperaMedia(mediaInfoMap, author)
return return
@@ -255,7 +261,7 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
if (paramMap.containsKey("PLAYLIST_V2_GROUP")) paramMap["PLAYLIST_V2_GROUP"].toString() else null if (paramMap.containsKey("PLAYLIST_V2_GROUP")) paramMap["PLAYLIST_V2_GROUP"].toString() else null
if (playlistV2Group != null && if (playlistV2Group != null &&
playlistV2Group.contains("storyUserId=") && playlistV2Group.contains("storyUserId=") &&
(forceDownload || context.config.bool(ConfigProperty.DOWNLOAD_STORIES)) (forceDownload || context.config.bool(ConfigProperty.AUTO_DOWNLOAD_STORIES))
) { ) {
val storyIdStartIndex = playlistV2Group.indexOf("storyUserId=") + 12 val storyIdStartIndex = playlistV2Group.indexOf("storyUserId=") + 12
val storyUserId = playlistV2Group.substring(storyIdStartIndex, playlistV2Group.indexOf(",", storyIdStartIndex)) val storyUserId = playlistV2Group.substring(storyIdStartIndex, playlistV2Group.indexOf(",", storyIdStartIndex))
@@ -266,7 +272,7 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
val snapSource = paramMap["SNAP_SOURCE"].toString() val snapSource = paramMap["SNAP_SOURCE"].toString()
//public stories //public stories
if (snapSource == "PUBLIC_USER" && (forceDownload || context.config.bool(ConfigProperty.DOWNLOAD_PUBLIC_STORIES))) { if (snapSource == "PUBLIC_USER" && (forceDownload || context.config.bool(ConfigProperty.AUTO_DOWNLOAD_PUBLIC_STORIES))) {
val userDisplayName = (if (paramMap.containsKey("USER_DISPLAY_NAME")) paramMap["USER_DISPLAY_NAME"].toString() else "").replace( val userDisplayName = (if (paramMap.containsKey("USER_DISPLAY_NAME")) paramMap["USER_DISPLAY_NAME"].toString() else "").replace(
"[^\\x00-\\x7F]".toRegex(), "[^\\x00-\\x7F]".toRegex(),
"") "")
@@ -274,7 +280,7 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
} }
//spotlight //spotlight
if (snapSource == "SINGLE_SNAP_STORY" && (forceDownload || context.config.bool(ConfigProperty.DOWNLOAD_SPOTLIGHT))) { if (snapSource == "SINGLE_SNAP_STORY" && (forceDownload || context.config.bool(ConfigProperty.AUTO_DOWNLOAD_SPOTLIGHT))) {
downloadOperaMedia(mediaInfoMap, "Spotlight") downloadOperaMedia(mediaInfoMap, "Spotlight")
} }
} }
@@ -283,6 +289,8 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
val operaViewerControllerClass: Class<*> = context.mappings.getMappedClass("OperaPageViewController", "Class") val operaViewerControllerClass: Class<*> = context.mappings.getMappedClass("OperaPageViewController", "Class")
val onOperaViewStateCallback: (HookAdapter) -> Unit = onOperaViewStateCallback@{ param -> val onOperaViewStateCallback: (HookAdapter) -> Unit = onOperaViewStateCallback@{ param ->
if (!context.config.bool(ConfigProperty.MEDIA_DOWNLOADER)) return@onOperaViewStateCallback
val viewState = (param.thisObject() as Any).getObjectField(context.mappings.getMappedValue("OperaPageViewController", "viewStateField")).toString() val viewState = (param.thisObject() as Any).getObjectField(context.mappings.getMappedValue("OperaPageViewController", "viewStateField")).toString()
if (viewState != "FULLY_DISPLAYED") { if (viewState != "FULLY_DISPLAYED") {
return@onOperaViewStateCallback return@onOperaViewStateCallback
@@ -304,7 +312,6 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
} }
lastSeenMapParams = mediaParamMap lastSeenMapParams = mediaParamMap
lastSeenMediaInfoMap = mediaInfoMap lastSeenMediaInfoMap = mediaInfoMap
if (!context.config.bool(ConfigProperty.MEDIA_DOWNLOADER_FEATURE)) return@onOperaViewStateCallback
context.executeAsync { context.executeAsync {
try { try {

View File

@@ -20,6 +20,7 @@ import me.rhunk.snapenhance.database.objects.ConversationMessage
import me.rhunk.snapenhance.database.objects.FriendInfo import me.rhunk.snapenhance.database.objects.FriendInfo
import me.rhunk.snapenhance.database.objects.UserConversationLink import me.rhunk.snapenhance.database.objects.UserConversationLink
import me.rhunk.snapenhance.features.impl.Messaging import me.rhunk.snapenhance.features.impl.Messaging
import me.rhunk.snapenhance.features.impl.downloader.AntiAutoDownload
import me.rhunk.snapenhance.features.impl.spy.StealthMode import me.rhunk.snapenhance.features.impl.spy.StealthMode
import me.rhunk.snapenhance.features.impl.ui.menus.AbstractMenu import me.rhunk.snapenhance.features.impl.ui.menus.AbstractMenu
import me.rhunk.snapenhance.features.impl.ui.menus.ViewAppearanceHelper.applyTheme import me.rhunk.snapenhance.features.impl.ui.menus.ViewAppearanceHelper.applyTheme
@@ -185,16 +186,6 @@ class FriendFeedInfoMenu : AbstractMenu() {
) )
} }
//export conversation
/*val exportButton = Button(viewModel.context)
exportButton.setText(context.translation.get("conversation_export"))
applyTheme(viewModel, exportButton)
exportButton.setOnClickListener { event: View? ->
conversationExport.exportConversation(
SnapUUID(conversationId)
)
}*/
//stealth switch //stealth switch
val stealthSwitch = Switch(viewModel.context) val stealthSwitch = Switch(viewModel.context)
stealthSwitch.text = context.translation.get("stealth_mode") stealthSwitch.text = context.translation.get("stealth_mode")
@@ -207,23 +198,21 @@ class FriendFeedInfoMenu : AbstractMenu() {
) )
} }
/*//click to delete switch if (context.config.bool(ConfigProperty.ANTI_DOWNLOAD_BUTTON)) {
val clickToDeleteSwitch = Switch(viewModel.context) val userId = context.database.getFriendFeedInfoByConversationId(conversationId)?.friendUserId ?: return
clickToDeleteSwitch.setText(context.translation.get("click_to_delete"))
clickToDeleteSwitch.isChecked = clickToDelete.isClickToDelete(conversationId) val antiAutoDownload = Switch(viewModel.context)
applyTheme(viewModel, clickToDeleteSwitch) antiAutoDownload.text = context.translation.get("anti_auto_download")
clickToDeleteSwitch.setOnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean -> antiAutoDownload.isChecked = context.feature(AntiAutoDownload::class).isUserIgnored(userId)
clickToDelete.setClickToDelete( applyTheme(viewModel, antiAutoDownload)
conversationId, antiAutoDownload.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
context.feature(AntiAutoDownload::class).setUserIgnored(
userId,
isChecked isChecked
) )
}*/ }
/* if (configManager.getBoolean(ConfigCategory.EXTRAS, "conversation_export") viewConsumer(antiAutoDownload)
.isState() }
) viewConsumer.accept(exportButton)
if (configManager.getBoolean(ConfigCategory.PRIVACY, "click_to_delete")
.isState()
) viewConsumer.accept(clickToDeleteSwitch)*/
viewConsumer(stealthSwitch) viewConsumer(stealthSwitch)
viewConsumer(previewButton) viewConsumer(previewButton)
} }

View File

@@ -6,6 +6,7 @@ import me.rhunk.snapenhance.features.Feature
import me.rhunk.snapenhance.features.FeatureLoadParams import me.rhunk.snapenhance.features.FeatureLoadParams
import me.rhunk.snapenhance.features.impl.ConfigEnumKeys import me.rhunk.snapenhance.features.impl.ConfigEnumKeys
import me.rhunk.snapenhance.features.impl.Messaging import me.rhunk.snapenhance.features.impl.Messaging
import me.rhunk.snapenhance.features.impl.downloader.AntiAutoDownload
import me.rhunk.snapenhance.features.impl.downloader.MediaDownloader import me.rhunk.snapenhance.features.impl.downloader.MediaDownloader
import me.rhunk.snapenhance.features.impl.extras.AutoSave import me.rhunk.snapenhance.features.impl.extras.AutoSave
import me.rhunk.snapenhance.features.impl.extras.Notifications import me.rhunk.snapenhance.features.impl.extras.Notifications
@@ -56,6 +57,7 @@ class FeatureManager(private val context: ModContext) : Manager {
register(AutoSave::class) register(AutoSave::class)
register(UITweaks::class) register(UITweaks::class)
register(ConfigEnumKeys::class) register(ConfigEnumKeys::class)
register(AntiAutoDownload::class)
initializeFeatures() initializeFeatures()
} }