From 3f3dd956cb8fd32286194cc681310347519febed Mon Sep 17 00:00:00 2001 From: k1ngsterr1 Date: Mon, 2 Mar 2026 23:54:16 +0500 Subject: [PATCH] feat: enhance file opening logic in OtherProfileScreen to support local, downloaded, and blob files --- .../messenger/ui/settings/OtherProfileScreen.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt index 548a670..dcb252e 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/settings/OtherProfileScreen.kt @@ -1402,11 +1402,24 @@ private fun openUriInExternalApp(context: android.content.Context, uri: Uri, mim private fun openSharedFile(context: android.content.Context, file: SharedFileItem): Boolean { val mimeType = inferMimeType(file.fileName) + + // 1. Попробовать localUri if (file.localUri.isNotBlank()) { val local = runCatching { Uri.parse(file.localUri) }.getOrNull() if (local != null && openUriInExternalApp(context, local, mimeType)) return true } + // 2. Проверить rosetta_downloads (файлы скачанные через CDN в чате) + val downloadsDir = File(context.filesDir, "rosetta_downloads") + val downloadedFile = File(downloadsDir, file.fileName) + if (downloadedFile.exists() && downloadedFile.length() > 0) { + val uri = runCatching { + FileProvider.getUriForFile(context, "${context.packageName}.provider", downloadedFile) + }.getOrNull() + if (uri != null && openUriInExternalApp(context, uri, mimeType)) return true + } + + // 3. Попробовать blob (inline-файлы) val bytes = decodeBlobPayload(file.blob) ?: return false val extension = file.fileName.substringAfterLast('.', "").lowercase(Locale.getDefault()) val suffix = if (extension.isBlank()) ".bin" else ".$extension"