commit a49c4e9a450d0238be2827b682d7b570e8124b87 parent 12eacf5e53aef2e0a27495de75df9a4d20a43273 Author: rhunk <101876869+rhunk@users.noreply.github.com> Date: Wed, 23 Aug 2023 01:15:43 +0200 feat: prevent self auto download Diffstat:
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/core/src/main/assets/lang/en_US.json b/core/src/main/assets/lang/en_US.json @@ -103,9 +103,13 @@ "name": "Save Folder", "description": "The directory where all media is saved" }, - "auto_download_options": { - "name": "Auto Download Options", - "description": "Select which medias to auto download" + "auto_download_sources": { + "name": "Auto Download Sources", + "description": "Select the sources to automatically download from" + }, + "prevent_self_auto_download": { + "name": "Prevent Self Auto Download", + "description": "Prevents your own Snaps from being downloaded automatically" }, "path_format": { "name": "Path Format", @@ -356,7 +360,7 @@ "append_date_time": "Add the date and time to the file name", "append_type": "Add the media type to the file name" }, - "auto_download_options": { + "auto_download_sources": { "friend_snaps": "Friend Snaps", "friend_stories": "Friend Stories", "public_stories": "Public Stories", diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/DownloaderConfig.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/DownloaderConfig.kt @@ -6,12 +6,13 @@ import me.rhunk.snapenhance.core.config.FeatureNotice class DownloaderConfig : ConfigContainer() { val saveFolder = string("save_folder") { addFlags(ConfigFlag.FOLDER) } - val autoDownloadOptions = multiple("auto_download_options", + val autoDownloadSources = multiple("auto_download_sources", "friend_snaps", "friend_stories", "public_stories", "spotlight" ) + val preventSelfAutoDownload = boolean("prevent_self_auto_download") val pathFormat = multiple("path_format", "create_user_folder", "append_hash", diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/features/impl/downloader/MediaDownloader.kt b/core/src/main/kotlin/me/rhunk/snapenhance/features/impl/downloader/MediaDownloader.kt @@ -235,6 +235,8 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp return } + if (!forceDownload && context.config.downloader.preventSelfAutoDownload.get() && senderId == context.database.myUserId) return + val author = context.database.getFriendInfo(senderId) ?: return val authorUsername = author.usernameForSorting!! @@ -270,6 +272,7 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp conversationParticipants.firstOrNull { it != conversationMessage.senderId } } + if (!forceDownload && context.config.downloader.preventSelfAutoDownload.get() && storyUserId == context.database.myUserId) return val author = context.database.getFriendInfo( if (storyUserId == null || storyUserId == "null") @@ -278,6 +281,8 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp ) ?: throw Exception("Friend not found in database") val authorName = author.usernameForSorting!! + if (!forceDownload && canUseRule(author.userId!!)) return + downloadOperaMedia(provideDownloadManagerClient( pathSuffix = authorName, mediaIdentifier = paramMap["MEDIA_ID"].toString(), @@ -362,7 +367,7 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp } private fun canAutoDownload(keyFilter: String? = null): Boolean { - val options by context.config.downloader.autoDownloadOptions + val options by context.config.downloader.autoDownloadSources return options.any { keyFilter == null || it.contains(keyFilter, true) } }