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) {
CONFIG(0), MAPPINGS(1), STEALTH(2);
CONFIG(0), MAPPINGS(1), STEALTH(2), ANTI_AUTO_DOWNLOAD(3);
companion object {
fun fromValue(value: Int): FileType? {

View File

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

View File

@@ -37,27 +37,33 @@ enum class ConfigProperty(
),
MESSAGE_LOGGER("message_logger", "description.message_logger", ConfigCategory.SPY, false),
MEDIA_DOWNLOADER_FEATURE(
"media_downloader_feature",
"description.media_downloader_feature",
MEDIA_DOWNLOADER(
"media_downloader",
"description.media_downloader",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
DOWNLOAD_STORIES(
"download_stories",
"description.download_stories",
AUTO_DOWNLOAD_SNAPS(
"auto_download_snaps",
"description.auto_download_snaps",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
AUTO_DOWNLOAD_STORIES(
"auto_download_stories",
"description.auto_download_stories",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
DOWNLOAD_PUBLIC_STORIES(
"download_public_stories",
"description.download_public_stories",
AUTO_DOWNLOAD_PUBLIC_STORIES(
"auto_download_public_stories",
"description.auto_download_public_stories",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
DOWNLOAD_SPOTLIGHT(
"download_spotlight",
"description.download_spotlight",
AUTO_DOWNLOAD_SPOTLIGHT(
"auto_download_spotlight",
"description.auto_download_spotlight",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
@@ -73,6 +79,12 @@ enum class ConfigProperty(
ConfigCategory.MEDIA_DOWNLOADER,
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),
PREVENT_SCREENSHOTS(

View File

@@ -241,10 +241,16 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
forceDownload: Boolean
) {
//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 messageId = id.substring(id.lastIndexOf(":") + 1).toLong()
val senderId: String = context.database.getConversationMessageFromId(messageId)!!.sender_id!!
if (context.feature(AntiAutoDownload::class).isUserIgnored(senderId)) {
return
}
val author = context.database.getFriendInfo(senderId)!!.usernameForSorting!!
downloadOperaMedia(mediaInfoMap, author)
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 (playlistV2Group != null &&
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 storyUserId = playlistV2Group.substring(storyIdStartIndex, playlistV2Group.indexOf(",", storyIdStartIndex))
@@ -266,7 +272,7 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
val snapSource = paramMap["SNAP_SOURCE"].toString()
//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(
"[^\\x00-\\x7F]".toRegex(),
"")
@@ -274,7 +280,7 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
}
//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")
}
}
@@ -283,6 +289,8 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
val operaViewerControllerClass: Class<*> = context.mappings.getMappedClass("OperaPageViewController", "Class")
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()
if (viewState != "FULLY_DISPLAYED") {
return@onOperaViewStateCallback
@@ -304,7 +312,6 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
}
lastSeenMapParams = mediaParamMap
lastSeenMediaInfoMap = mediaInfoMap
if (!context.config.bool(ConfigProperty.MEDIA_DOWNLOADER_FEATURE)) return@onOperaViewStateCallback
context.executeAsync {
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.UserConversationLink
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.ui.menus.AbstractMenu
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
val stealthSwitch = Switch(viewModel.context)
stealthSwitch.text = context.translation.get("stealth_mode")
@@ -207,23 +198,21 @@ class FriendFeedInfoMenu : AbstractMenu() {
)
}
/*//click to delete switch
val clickToDeleteSwitch = Switch(viewModel.context)
clickToDeleteSwitch.setText(context.translation.get("click_to_delete"))
clickToDeleteSwitch.isChecked = clickToDelete.isClickToDelete(conversationId)
applyTheme(viewModel, clickToDeleteSwitch)
clickToDeleteSwitch.setOnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
clickToDelete.setClickToDelete(
conversationId,
isChecked
)
}*/
/* if (configManager.getBoolean(ConfigCategory.EXTRAS, "conversation_export")
.isState()
) viewConsumer.accept(exportButton)
if (configManager.getBoolean(ConfigCategory.PRIVACY, "click_to_delete")
.isState()
) viewConsumer.accept(clickToDeleteSwitch)*/
if (context.config.bool(ConfigProperty.ANTI_DOWNLOAD_BUTTON)) {
val userId = context.database.getFriendFeedInfoByConversationId(conversationId)?.friendUserId ?: return
val antiAutoDownload = Switch(viewModel.context)
antiAutoDownload.text = context.translation.get("anti_auto_download")
antiAutoDownload.isChecked = context.feature(AntiAutoDownload::class).isUserIgnored(userId)
applyTheme(viewModel, antiAutoDownload)
antiAutoDownload.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
context.feature(AntiAutoDownload::class).setUserIgnored(
userId,
isChecked
)
}
viewConsumer(antiAutoDownload)
}
viewConsumer(stealthSwitch)
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.impl.ConfigEnumKeys
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.extras.AutoSave
import me.rhunk.snapenhance.features.impl.extras.Notifications
@@ -56,6 +57,7 @@ class FeatureManager(private val context: ModContext) : Manager {
register(AutoSave::class)
register(UITweaks::class)
register(ConfigEnumKeys::class)
register(AntiAutoDownload::class)
initializeFeatures()
}