fix(core/media_downloader): public stories author

This commit is contained in:
rhunk
2023-12-14 22:04:26 +01:00
parent d0ff3c35ef
commit abfbe86a91

View File

@ -100,7 +100,7 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp
context.shortToast(translations["download_started_toast"]) context.shortToast(translations["download_started_toast"])
} }
val outputPath = createNewFilePath(generatedHash, downloadSource, mediaAuthor, creationTimestamp) val outputPath = createNewFilePath(generatedHash.substring(0, generatedHash.length.coerceAtMost(8)), downloadSource, mediaAuthor, creationTimestamp)
return DownloadManagerClient( return DownloadManagerClient(
context = context, context = context,
@ -166,7 +166,7 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp
finalPath.append(downloadSource.pathName).append("/") finalPath.append(downloadSource.pathName).append("/")
} }
if (pathFormat.contains("append_hash")) { if (pathFormat.contains("append_hash")) {
appendFileName(hexHash.substring(0, hexHash.length.coerceAtMost(8))) appendFileName(hexHash)
} }
if (pathFormat.contains("append_source")) { if (pathFormat.contains("append_source")) {
appendFileName(downloadSource.pathName) appendFileName(downloadSource.pathName)
@ -329,9 +329,7 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp
val playlistGroupString = playlistGroup.toString() val playlistGroupString = playlistGroup.toString()
val storyUserId = paramMap["TOPIC_SNAP_CREATOR_USER_ID"]?.toString() ?: if (playlistGroupString.contains("storyUserId=")) { val storyUserId = paramMap["TOPIC_SNAP_CREATOR_USER_ID"]?.toString() ?: if (playlistGroupString.contains("storyUserId=")) {
(playlistGroupString.indexOf("storyUserId=") + 12).let { playlistGroupString.substringAfter("storyUserId=").substringBefore(",")
playlistGroupString.substring(it, playlistGroupString.indexOf(",", it))
}
} else { } else {
//story replies //story replies
val arroyoMessageId = playlistGroup::class.java.methods.firstOrNull { it.name == "getId" } val arroyoMessageId = playlistGroup::class.java.methods.firstOrNull { it.name == "getId" }
@ -372,16 +370,24 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp
//public stories //public stories
if ((snapSource == "PUBLIC_USER" || snapSource == "SAVED_STORY") && if ((snapSource == "PUBLIC_USER" || snapSource == "SAVED_STORY") &&
(forceDownload || canAutoDownload("public_stories"))) { (forceDownload || canAutoDownload("public_stories"))) {
val username = (
paramMap["USERNAME"]?.toString()?.substringAfter("value=") val author = (
?.substringBefore(")")?.substringBefore(",") paramMap["USER_ID"]?.let { context.database.getFriendInfo(it.toString())?.mutableUsername } // only for following users
?: paramMap["USER_DISPLAY_NAME"]?.toString() ?: paramMap["USERNAME"]?.toString()?.takeIf {
it.contains("value=")
}?.substringAfter("value=")?.substringBefore(")")?.substringBefore(",")
?: paramMap["CONTEXT_USER_IDENTITY"]?.toString()?.takeIf {
it.contains("username=")
}?.substringAfter("username=")?.substringBefore(",")
// fallback display name
?: paramMap["USER_DISPLAY_NAME"]?.toString()?.takeIf { it.isNotEmpty() }
?: paramMap["TIME_STAMP"]?.toString()
?: "unknown" ?: "unknown"
).sanitizeForPath() ).sanitizeForPath()
downloadOperaMedia(provideDownloadManagerClient( downloadOperaMedia(provideDownloadManagerClient(
mediaIdentifier = paramMap["SNAP_ID"].toString(), mediaIdentifier = paramMap["SNAP_ID"].toString(),
mediaAuthor = username, mediaAuthor = author,
downloadSource = MediaDownloadSource.PUBLIC_STORY, downloadSource = MediaDownloadSource.PUBLIC_STORY,
creationTimestamp = paramMap["SNAP_TIMESTAMP"]?.toString()?.toLongOrNull(), creationTimestamp = paramMap["SNAP_TIMESTAMP"]?.toString()?.toLongOrNull(),
), mediaInfoMap) ), mediaInfoMap)