feat: prevent self auto download

This commit is contained in:
rhunk 2023-08-23 01:15:43 +02:00
parent 12eacf5e53
commit a49c4e9a45
3 changed files with 16 additions and 6 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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) }
}