Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove obsolete attachment download state

Manav Rathic246f922e4b9
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt
index b3ba03ce24..54d1b0f32e 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt
@@ -55,7 +55,6 @@ class AppStore(
)
fun bootstrap(scope: CoroutineScope) {
chatActions.setScope(scope)
- attachmentActions.setScope(scope)
modelSettingsActions.setScope(scope)
refreshDeviceCapability(scope)
chatActions.bootstrap(scope)
@@ -185,6 +184,4 @@ class AppStore(
modelSettingsActions.hydratePersistedModelSettings(modelSettings)
}
- fun cancelAttachmentDownload(attachmentId: String) =
- attachmentActions.cancelAttachmentDownload(attachmentId)
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeDialogs.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeDialogs.kt
index 2447c2141c..bc2e83b0fd 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeDialogs.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeDialogs.kt
@@ -28,9 +28,6 @@ import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.designsystem.EnsuCornerRadius
import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
-import io.ente.ensu.chat.AttachmentDownloadItem
-import io.ente.ensu.chat.AttachmentDownloadStatus
-import io.ente.ensu.format.formattedFileSize
@Composable
internal fun ComingSoonDialog(
@@ -76,74 +73,3 @@ internal fun ComingSoonDialog(
containerColor = EnsuColor.backgroundBase()
)
}
-
-@Composable
-internal fun AttachmentDownloadsDialog(
- downloads: List<AttachmentDownloadItem>,
- onCancel: (String) -> Unit,
- onDismiss: () -> Unit
-) {
- AlertDialog(
- onDismissRequest = onDismiss,
- title = { Text(text = "Attachment downloads", style = EnsuTypography.h3Bold) },
- text = {
- if (downloads.isEmpty()) {
- Text(text = "No pending downloads", style = EnsuTypography.body, color = EnsuColor.textMuted())
- } else {
- Column(
- modifier = Modifier
- .heightIn(max = 320.dp)
- .verticalScroll(rememberScrollState())
- ) {
- downloads.forEach { item ->
- Row(
- modifier = Modifier.padding(vertical = EnsuSpacing.xs.dp),
- verticalAlignment = Alignment.CenterVertically
- ) {
- Column(modifier = Modifier.weight(1f)) {
- Text(text = item.name, style = EnsuTypography.body, color = EnsuColor.textPrimary())
- Text(
- text = "Session ${item.sessionId.take(6)} β€’ ${item.sizeBytes.formattedFileSize()}",
- style = EnsuTypography.mini,
- color = EnsuColor.textMuted()
- )
- }
- Text(
- text = statusLabel(item.status),
- style = EnsuTypography.mini,
- color = EnsuColor.textMuted(),
- modifier = Modifier.padding(end = EnsuSpacing.xs.dp)
- )
- if (item.status == AttachmentDownloadStatus.Queued || item.status == AttachmentDownloadStatus.Downloading) {
- TextButton(
- onClick = { onCancel(item.id) },
- colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
- ) {
- Text(text = "Cancel", style = EnsuTypography.mini)
- }
- }
- }
- }
- }
- }
- },
- confirmButton = {
- TextButton(
- onClick = onDismiss,
- colors = ButtonDefaults.textButtonColors(contentColor = EnsuColor.textPrimary())
- ) {
- Text(text = "Close", style = EnsuTypography.small)
- }
- }
- )
-}
-
-private fun statusLabel(status: AttachmentDownloadStatus): String {
- return when (status) {
- AttachmentDownloadStatus.Queued -> "Queued"
- AttachmentDownloadStatus.Downloading -> "Downloading"
- AttachmentDownloadStatus.Completed -> "Completed"
- AttachmentDownloadStatus.Failed -> "Failed"
- AttachmentDownloadStatus.Canceled -> "Canceled"
- }
-}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt
index 879b45eb7d..a4f442cbbf 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt
@@ -53,7 +53,6 @@ internal fun HomeNavigation(
onSignIn: () -> Unit,
onOpenDrawer: () -> Unit,
onNewChat: () -> Unit,
- onAttachmentDownloads: () -> Unit,
onShowLogShareDialog: () -> Unit,
onAttachmentSelected: (AttachmentType) -> Unit,
onOpenAttachment: (Attachment) -> Unit
@@ -68,13 +67,10 @@ internal fun HomeNavigation(
TopBar(
sessionTitle = currentSession?.title,
showBrand = appState.chat.messages.isEmpty(),
- attachmentDownloads = appState.chat.attachmentDownloads,
- attachmentDownloadProgress = appState.chat.attachmentDownloadProgress,
modelDownloadStatus = appState.chat.downloadStatus,
modelDownloadPercent = appState.chat.downloadPercent,
onOpenDrawer = onOpenDrawer,
- onNewChat = onNewChat,
- onAttachmentDownloads = onAttachmentDownloads
+ onNewChat = onNewChat
)
androidx.compose.material3.HorizontalDivider(color = EnsuColor.border())
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeTopBars.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeTopBars.kt
index 7b97a8337f..9aa454e4d7 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeTopBars.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeTopBars.kt
@@ -2,8 +2,6 @@
package io.ente.ensu
-import androidx.compose.foundation.layout.PaddingValues
-import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
@@ -12,13 +10,11 @@ import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
@@ -28,20 +24,15 @@ import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
import io.ente.ensu.designsystem.HugeIcons
-import io.ente.ensu.chat.AttachmentDownloadItem
-import io.ente.ensu.chat.AttachmentDownloadStatus
@Composable
internal fun TopBar(
sessionTitle: String?,
showBrand: Boolean,
- attachmentDownloads: List<AttachmentDownloadItem>,
- attachmentDownloadProgress: Int?,
modelDownloadStatus: String?,
modelDownloadPercent: Int?,
onOpenDrawer: () -> Unit,
- onNewChat: () -> Unit,
- onAttachmentDownloads: () -> Unit
+ onNewChat: () -> Unit
) {
val titleText = sessionTitle?.takeIf { it.isNotBlank() } ?: "New Chat"
@@ -69,49 +60,15 @@ internal fun TopBar(
actions = {
val isLoading = modelDownloadStatus?.contains("Loading", ignoreCase = true) == true
val showModelProgress = isLoading
- val hasPending = attachmentDownloads.any {
- it.status == AttachmentDownloadStatus.Queued ||
- it.status == AttachmentDownloadStatus.Downloading ||
- it.status == AttachmentDownloadStatus.Failed
- }
-
- if (hasPending) {
- val active = attachmentDownloads.filter { it.status != AttachmentDownloadStatus.Canceled }
- val completed = active.count { it.status == AttachmentDownloadStatus.Completed }
- val total = active.size
- TextButton(
- onClick = onAttachmentDownloads,
- contentPadding = PaddingValues(horizontal = 8.dp, vertical = 0.dp)
- ) {
- Row(verticalAlignment = Alignment.CenterVertically) {
- Icon(
- painter = painterResource(HugeIcons.Upload01Icon),
- contentDescription = "Attachment downloads",
- tint = EnsuColor.textPrimary()
- )
- Text(
- text = "$completed/$total",
- style = EnsuTypography.mini,
- color = EnsuColor.textMuted(),
- maxLines = 1,
- softWrap = false,
- modifier = Modifier.padding(start = 6.dp)
- )
- }
- }
- }
if (showModelProgress) {
- if (hasPending) {
- Spacer(modifier = Modifier.width(EnsuSpacing.md.dp))
- }
ModelProgressIndicator(
isLoading = isLoading,
progressPercent = modelDownloadPercent
)
}
- if (hasPending || showModelProgress) {
+ if (showModelProgress) {
Spacer(modifier = Modifier.width(EnsuSpacing.sm.dp))
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt
index d391974c7a..58f8cec99e 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt
@@ -92,7 +92,6 @@ fun HomeView(
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route ?: HomeRoute.Chat
val isChatRoute = currentRoute == HomeRoute.Chat
- var showAttachmentDownloads by remember { mutableStateOf(false) }
var deleteSessionTarget by remember { mutableStateOf<io.ente.ensu.chat.ChatSession?>(null) }
var showLogShareDialog by remember { mutableStateOf(false) }
var showSignInComingSoon by remember { mutableStateOf(false) }
@@ -257,7 +256,6 @@ fun HomeView(
store.startNewSessionDraft()
store.persistSelectedSession(scope, null)
},
- onAttachmentDownloads = { showAttachmentDownloads = true },
onShowLogShareDialog = { showLogShareDialog = true },
onAttachmentSelected = handleAttachmentSelected,
onOpenAttachment = { attachment ->
@@ -286,14 +284,6 @@ fun HomeView(
)
}
- if (showAttachmentDownloads) {
- AttachmentDownloadsDialog(
- downloads = appState.chat.attachmentDownloads,
- onCancel = { store.cancelAttachmentDownload(it) },
- onDismiss = { showAttachmentDownloads = false }
- )
- }
-
pendingWhatsNew?.let { pending ->
WhatsNewDialog(
entries = pending.entries,
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentDownload.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentDownload.kt
deleted file mode 100644
index 5ce6148d56..0000000000
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentDownload.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package io.ente.ensu.chat
-
-enum class AttachmentDownloadStatus {
- Queued,
- Downloading,
- Completed,
- Failed,
- Canceled
-}
-
-data class AttachmentDownloadItem(
- val id: String,
- val sessionId: String,
- val name: String,
- val sizeBytes: Long,
- val status: AttachmentDownloadStatus
-)
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentStoreActions.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentStoreActions.kt
index 8999477237..3129566bcb 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentStoreActions.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/AttachmentStoreActions.kt
@@ -1,37 +1,18 @@
package io.ente.ensu.chat
import io.ente.ensu.chat.Attachment
-import io.ente.ensu.chat.AttachmentDownloadItem
-import io.ente.ensu.chat.AttachmentDownloadStatus
import io.ente.ensu.chat.AttachmentType
import io.ente.ensu.chat.ChatMessage
import io.ente.ensu.chat.MaxImageAttachmentsPerMessage
import io.ente.ensu.AppState
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
import java.io.File
-import java.util.concurrent.ConcurrentHashMap
-import java.util.concurrent.ConcurrentLinkedDeque
internal class AttachmentStoreActions(
private val state: MutableStateFlow<AppState>,
private val messageStore: MutableMap<String, MutableList<ChatMessage>>
) {
- private val attachmentDownloads = ConcurrentHashMap<String, AttachmentDownloadItem>()
- private val attachmentDownloadQueue = ConcurrentLinkedDeque<String>()
- private val attachmentDownloadActive = ConcurrentHashMap<String, Job>()
- private val maxAttachmentDownloadConcurrency = 2
- private var scope: CoroutineScope? = null
-
- fun setScope(scope: CoroutineScope) {
- this.scope = scope
- }
-
fun setAttachmentProcessing(isProcessing: Boolean) {
state.update { appState ->
appState.copy(chat = appState.chat.copy(isProcessingAttachments = isProcessing))
@@ -47,7 +28,6 @@ internal class AttachmentStoreActions(
MaxImageAttachmentsPerMessage
if (chat.isGenerating ||
chat.isDownloading ||
- chat.isAttachmentDownloadBlocked ||
imageLimitReached
) {
appState.copy(
@@ -81,157 +61,10 @@ internal class AttachmentStoreActions(
attachments.forEach(::deleteIfUnstored)
}
- fun cancelAttachmentDownload(attachmentId: String) {
- attachmentDownloadActive[attachmentId]?.cancel()
- attachmentDownloadActive.remove(attachmentId)
- attachmentDownloadQueue.removeIf { it == attachmentId }
- attachmentDownloads[attachmentId]?.let { item ->
- attachmentDownloads[attachmentId] = item.copy(status = AttachmentDownloadStatus.Canceled)
- }
- updateAttachmentDownloadState()
- startNextAttachmentDownloads()
- }
-
- fun ensureAttachmentsAvailable(sessionId: String) {
- val missing = missingAttachments(sessionId)
- if (missing.isEmpty()) {
- updateAttachmentDownloadState()
- return
- }
- queueAttachmentDownloads(missing)
- updateAttachmentDownloadState()
- }
-
- fun missingAttachments(sessionId: String): List<AttachmentDownloadItem> {
- val messages = messageStore[sessionId].orEmpty()
- if (messages.isEmpty()) return emptyList()
- val seen = mutableSetOf<String>()
- val missing = mutableListOf<AttachmentDownloadItem>()
-
- for (message in messages) {
- for (attachment in message.attachments) {
- if (!seen.add(attachment.id)) continue
- val path = attachment.localPath
- if (path != null && File(path).exists()) {
- attachmentDownloadActive[attachment.id]?.cancel()
- attachmentDownloadActive.remove(attachment.id)
- attachmentDownloadQueue.removeIf { it == attachment.id }
- attachmentDownloads.remove(attachment.id)
- continue
- }
- val existing = attachmentDownloads[attachment.id]
- val status = existing?.status ?: AttachmentDownloadStatus.Queued
- missing.add(
- AttachmentDownloadItem(
- id = attachment.id,
- sessionId = sessionId,
- name = attachment.name,
- sizeBytes = attachment.sizeBytes,
- status = status
- )
- )
- }
- }
-
- return missing
- }
-
- fun purgeAttachmentDownloads(sessionId: String) {
- val ids = attachmentDownloads.values.filter { it.sessionId == sessionId }.map { it.id }
- ids.forEach { id ->
- attachmentDownloadActive[id]?.cancel()
- attachmentDownloadActive.remove(id)
- attachmentDownloadQueue.removeIf { it == id }
- attachmentDownloads.remove(id)
- }
- updateAttachmentDownloadState()
- }
-
- fun refreshAttachmentDownloadState() {
- updateAttachmentDownloadState()
- }
-
private fun deleteIfUnstored(attachment: Attachment) {
val stored = messageStore.values.any { messages ->
messages.any { message -> message.attachments.any { it.id == attachment.id } }
}
if (!stored) attachment.localPath?.let { File(it).delete() }
}
-
- private fun queueAttachmentDownloads(items: List<AttachmentDownloadItem>) {
- items.forEach { item ->
- val existing = attachmentDownloads[item.id]
- val updated = if (existing == null ||
- existing.status == AttachmentDownloadStatus.Failed ||
- existing.status == AttachmentDownloadStatus.Canceled
- ) {
- item
- } else {
- existing
- }
- attachmentDownloads[item.id] = updated
- if (updated.status != AttachmentDownloadStatus.Completed &&
- updated.status != AttachmentDownloadStatus.Canceled &&
- attachmentDownloadActive[item.id] == null &&
- !attachmentDownloadQueue.contains(item.id)
- ) {
- attachmentDownloadQueue.addLast(item.id)
- }
- }
- startNextAttachmentDownloads()
- }
-
- private fun startNextAttachmentDownloads() {
- val scope = scope ?: return
- while (attachmentDownloadActive.size < maxAttachmentDownloadConcurrency && attachmentDownloadQueue.isNotEmpty()) {
- val id = attachmentDownloadQueue.pollFirst() ?: continue
- if (attachmentDownloadActive.containsKey(id)) {
- continue
- }
- val item = attachmentDownloads[id] ?: continue
- if (item.status == AttachmentDownloadStatus.Completed || item.status == AttachmentDownloadStatus.Canceled) {
- continue
- }
- attachmentDownloads[id] = item.copy(status = AttachmentDownloadStatus.Downloading)
- updateAttachmentDownloadState()
-
- val job = scope.launch(Dispatchers.IO) {
- withContext(Dispatchers.Main) {
- attachmentDownloads[id]?.let { current ->
- if (current.status != AttachmentDownloadStatus.Canceled) {
- attachmentDownloads[id] = current.copy(status = AttachmentDownloadStatus.Failed)
- }
- }
- attachmentDownloadActive.remove(id)
- updateAttachmentDownloadState()
- startNextAttachmentDownloads()
- }
- }
- attachmentDownloadActive[id] = job
- }
- }
-
- private fun updateAttachmentDownloadState() {
- val currentSessionId = state.value.chat.currentSessionId
- val missing = currentSessionId?.let { missingAttachments(it) }.orEmpty()
- val items = attachmentDownloads.values.sortedBy { it.name }
- val active = items.filter { it.status != AttachmentDownloadStatus.Canceled }
- val total = active.size
- val completed = active.count { it.status == AttachmentDownloadStatus.Completed }
- val hasPending = active.any {
- it.status == AttachmentDownloadStatus.Queued ||
- it.status == AttachmentDownloadStatus.Downloading ||
- it.status == AttachmentDownloadStatus.Failed
- }
- val progress = if (total > 0 && hasPending) (completed * 100 / total) else null
- state.update { appState ->
- appState.copy(
- chat = appState.chat.copy(
- attachmentDownloads = items,
- attachmentDownloadProgress = progress,
- isAttachmentDownloadBlocked = missing.isNotEmpty()
- )
- )
- }
- }
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatInputBar.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatInputBar.kt
index c0e781f417..7c0f73dc0f 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatInputBar.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatInputBar.kt
@@ -72,8 +72,6 @@ internal fun MessageInput(
isProcessingAttachments: Boolean,
isGenerating: Boolean,
isDownloading: Boolean,
- isAttachmentDownloadBlocked: Boolean,
- attachmentDownloadPercent: Int?,
onMessageChange: (String) -> Unit,
onSend: () -> Unit,
onStop: () -> Unit,
@@ -85,13 +83,7 @@ internal fun MessageInput(
focusRequestId: Int
) {
val haptic = rememberHaptics()
- val placeholder = when {
- isAttachmentDownloadBlocked -> {
- val percent = attachmentDownloadPercent?.let { " ($it%)" } ?: ""
- "Downloading attachments...$percent"
- }
- else -> "Write a message..."
- }
+ val placeholder = "Write a message..."
val focusRequester = remember { FocusRequester() }
var fieldValue by remember {
@@ -269,7 +261,6 @@ internal fun MessageInput(
if (editingMessage == null) {
val canAddImageAttachment = !isGenerating &&
!isDownloading &&
- !isAttachmentDownloadBlocked &&
!isImageAttachmentLimitReached
IconButton(
onClick = {
@@ -293,7 +284,6 @@ internal fun MessageInput(
val canUseVoice = voiceInputState.isRecording ||
(!isGenerating &&
!isDownloading &&
- !isAttachmentDownloadBlocked &&
!isVoiceBusy)
IconButton(
@@ -342,7 +332,7 @@ internal fun MessageInput(
onSend()
}
},
- enabled = isGenerating || (!isDownloading && !isAttachmentDownloadBlocked && canSend),
+ enabled = isGenerating || (!isDownloading && canSend),
modifier = Modifier.size(36.dp)
) {
val iconRes = when {
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt
index 7a3e8142cc..768ee3cfe4 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt
@@ -528,10 +528,16 @@ private fun UserMessageBubble(
} else {
io.ente.ensu.components.AttachmentChip(
name = attachment.name,
- size = attachment.sizeBytes.formattedFileSize(),
+ size = if (attachment.localPath == null) {
+ "Unavailable on this device"
+ } else {
+ attachment.sizeBytes.formattedFileSize()
+ },
iconRes = HugeIcons.Attachment01Icon,
isUploading = attachment.isUploading,
- onClick = { onOpenAttachment(attachment) }
+ onClick = if (attachment.localPath == null) null else {
+ { onOpenAttachment(attachment) }
+ }
)
}
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatOverlays.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatOverlays.kt
index 7a54b9ee6a..eff8ce90cf 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatOverlays.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatOverlays.kt
@@ -29,14 +29,12 @@ import io.ente.ensu.designsystem.EnsuCornerRadius
import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
import io.ente.ensu.designsystem.HugeIcons
-import io.ente.ensu.chat.OverflowDialogState
import io.ente.ensu.format.formatBytes
import io.ente.ensu.platform.rememberHaptics
import kotlin.math.roundToLong
@Composable
internal fun OverflowDialog(
- state: OverflowDialogState,
onTrim: () -> Unit,
onCancel: () -> Unit
) {
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatRepository.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatRepository.kt
index a7ef2bb2da..6e8c046d00 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatRepository.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatRepository.kt
@@ -77,6 +77,7 @@ class ChatRepository(
text = message.text,
timestampMillis = message.createdAtUs / 1000,
attachments = message.attachments.map { meta ->
+ val file = File(attachmentsDir, meta.id)
Attachment(
id = meta.id,
name = meta.name,
@@ -85,7 +86,7 @@ class ChatRepository(
DbAttachmentKind.IMAGE -> AttachmentType.Image
DbAttachmentKind.DOCUMENT -> AttachmentType.Document
},
- localPath = File(attachmentsDir, meta.id).absolutePath,
+ localPath = file.takeIf { it.exists() }?.absolutePath,
isUploading = false
)
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatState.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatState.kt
index 48db17683e..4b5aa68ff4 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatState.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatState.kt
@@ -23,9 +23,6 @@ data class ChatState(
val editingMessageId: String? = null,
val branchSelections: Map<String, Int> = emptyMap(),
val isProcessingAttachments: Boolean = false,
- val attachmentDownloads: List<io.ente.ensu.chat.AttachmentDownloadItem> = emptyList(),
- val attachmentDownloadProgress: Int? = null,
- val isAttachmentDownloadBlocked: Boolean = false,
val transientAssistantError: String? = null,
val transientAssistantParentId: String? = null,
val isModelDownloaded: Boolean = false,
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt
index 38aa783bde..dbe036ea68 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt
@@ -115,7 +115,6 @@ internal class ChatStoreActions(
markSessionAccess(session.id)
trimSessionCaches()
rebuildChatState(session.id)
- attachmentActions.refreshAttachmentDownloadState()
logRepository.log(LogLevel.Info, "Session created", tag = "Chat")
return session.id
}
@@ -137,7 +136,6 @@ internal class ChatStoreActions(
)
)
}
- attachmentActions.refreshAttachmentDownloadState()
}
fun selectSession(sessionId: String) {
@@ -153,7 +151,6 @@ internal class ChatStoreActions(
scope.launch(Dispatchers.IO) {
loadMessagesFromDb(sessionId)
rebuildChatState(sessionId)
- attachmentActions.ensureAttachmentsAvailable(sessionId)
}
}
@@ -168,7 +165,6 @@ internal class ChatStoreActions(
chatRepository.deleteSession(sessionId)
if (isCurrent) attachmentActions.discardAttachments(currentState.chat.attachments)
removeSessionCaches(sessionId)
- attachmentActions.purgeAttachmentDownloads(sessionId)
sessionSummaries.remove(sessionKey(sessionId))
scope?.launch { sessionPreferences.setSessionSummary(sessionId, null) }
@@ -207,7 +203,6 @@ internal class ChatStoreActions(
scope.launch(Dispatchers.IO) {
loadMessagesFromDb(newCurrent)
rebuildChatState(newCurrent)
- attachmentActions.ensureAttachmentsAvailable(newCurrent)
}
} else {
state.update { appState ->
@@ -309,10 +304,6 @@ internal class ChatStoreActions(
messageStore[sessionId]?.firstOrNull { it.id == parentId }
} ?: return
- if (attachmentActions.missingAttachments(sessionId).isNotEmpty()) {
- attachmentActions.ensureAttachmentsAvailable(sessionId)
- return
- }
llmProvider.resetContext()
startGeneration(sessionId, parent)
}
@@ -326,10 +317,6 @@ internal class ChatStoreActions(
if (text.isEmpty() && attachments.isEmpty()) return
val sessionId = currentState.chat.currentSessionId ?: createNewSession()
- if (attachmentActions.missingAttachments(sessionId).isNotEmpty()) {
- attachmentActions.ensureAttachmentsAvailable(sessionId)
- return
- }
val timestamp = clock()
val editingMessageId = currentState.chat.editingMessageId
@@ -436,8 +423,6 @@ internal class ChatStoreActions(
if (sessionStillExists && currentSessionId != null) {
loadMessagesFromDb(currentSessionId)
rebuildChatState(currentSessionId)
- } else {
- attachmentActions.refreshAttachmentDownloadState()
}
trimSessionCaches(sessions.map { it.id }.toSet())
}
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt
index 6822d6e8c1..8c7585d141 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt
@@ -102,7 +102,6 @@ fun ChatView(
}
val canStartVoiceInput = !chatState.isGenerating &&
!chatState.isDownloading &&
- !chatState.isAttachmentDownloadBlocked &&
!isChatUnsupported &&
editingMessage == null
val latestCanStartVoiceInput by rememberUpdatedState(canStartVoiceInput)
@@ -234,9 +233,8 @@ fun ChatView(
}
}
- chatState.overflowDialog?.let { overflow ->
+ if (chatState.overflowDialog != null) {
OverflowDialog(
- state = overflow,
onTrim = onOverflowTrim,
onCancel = onOverflowCancel
)
@@ -267,8 +265,6 @@ fun ChatView(
isProcessingAttachments = chatState.isProcessingAttachments,
isGenerating = chatState.isGenerating,
isDownloading = chatState.isDownloading,
- isAttachmentDownloadBlocked = chatState.isAttachmentDownloadBlocked,
- attachmentDownloadPercent = chatState.attachmentDownloadProgress,
onMessageChange = onMessageChange,
onSend = {
focusManager.clearFocus()
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift
index a34ce74ec7..9c823b260b 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift
@@ -159,14 +159,6 @@ struct ChatView: View {
handleSignInRequest()
}
}
- .sheet(isPresented: $viewState.showAttachmentDownloads) {
- AttachmentDownloadsSheet(
- downloads: viewModel.attachmentDownloads,
- sessionTitle: { viewModel.sessionTitle(for: $0) },
- onCancel: { viewModel.cancelAttachmentDownload($0) },
- onDismiss: { viewState.showAttachmentDownloads = false }
- )
- }
.sheet(item: $viewState.pendingWhatsNew, onDismiss: {
markWhatsNewSeen()
}) { pending in
@@ -239,7 +231,6 @@ struct ChatView: View {
showBrand: viewModel.messages.isEmpty,
showSignIn: false,
showsMenuButton: showsMenuButton,
- attachmentDownloadSummary: viewModel.attachmentDownloadSummary,
modelDownloadState: viewModel.downloadToast,
onMenu: { viewState.isDrawerOpen.toggle() },
onSignIn: {
@@ -248,9 +239,6 @@ struct ChatView: View {
onNewChat: {
viewModel.startNewSession()
viewState.isDrawerOpen = false
- },
- onAttachmentDownloads: {
- viewState.showAttachmentDownloads = true
}
)
@@ -323,7 +311,6 @@ struct ChatView: View {
isDownloading: viewModel.isDownloading,
editingMessage: editingMessage,
isProcessingAttachments: viewModel.isProcessingAttachments,
- isAttachmentDownloadBlocked: viewModel.isAttachmentDownloadBlocked,
voiceInputState: viewModel.voiceInputState,
moveCursorToEndToken: viewModel.draftCursorMoveToken,
onSend: {
@@ -484,7 +471,6 @@ private final class ChatViewState: ObservableObject {
@Published var showSettings = false
@Published var toastMessage: ToastMessage?
@Published var deleteSession: ChatSession?
- @Published var showAttachmentDownloads = false
@Published var showSignInComingSoon = false
@Published var pendingSignInRequest = false
@Published var didAutoFocusInput = false
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift
index f48158354f..89d6d34e77 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift
@@ -71,8 +71,6 @@ final class ChatViewModel: ObservableObject {
@Published var hasRequestedModelDownload: Bool = false
@Published var deviceCapability: ChatDeviceCapability = .unknown
@Published var showUnsupportedDeviceDialog: Bool = false
- @Published var attachmentDownloads: [AttachmentDownloadItem] = []
- @Published var currentSessionMissingAttachments: [AttachmentDownloadItem] = []
@Published var generationErrorMessage: String?
@Published var voiceInputState: VoiceInputState = .idle
@Published var draftCursorMoveToken = UUID()
@@ -107,10 +105,6 @@ final class ChatViewModel: ObservableObject {
private var pendingOverflow: PendingOverflow?
private var overflowBypassMessageId: UUID?
- private var attachmentDownloadQueue: [String] = []
- private var attachmentDownloadTasks: [String: Task<Void, Never>] = [:]
- private let maxAttachmentDownloads = 2
-
init() {
logger.info("Initializing")
let summaries = Self.loadSessionSummaries().reduce(into: [String: String]()) { result, item in
@@ -182,8 +176,6 @@ final class ChatViewModel: ObservableObject {
if let current = self.currentSessionId {
loadMessagesFromDb(for: current)
- } else {
- refreshAttachmentDownloadState()
}
refreshDeviceCapability()
@@ -254,42 +246,6 @@ final class ChatViewModel: ObservableObject {
return sessions.first { $0.id == currentSessionId }
}
- var isAttachmentDownloadBlocked: Bool {
- !currentSessionMissingAttachments.isEmpty
- }
-
- var attachmentDownloadProgress: Double? {
- let active = attachmentDownloads.filter { $0.status != AttachmentDownloadItem.Status.canceled }
- let total = active.count
- guard total > 0 else { return nil }
-
- let hasPending = active.contains { item in
- item.status == AttachmentDownloadItem.Status.queued ||
- item.status == AttachmentDownloadItem.Status.downloading ||
- item.status == AttachmentDownloadItem.Status.failed
- }
- guard hasPending else { return nil }
-
- let completed = active.filter { $0.status == AttachmentDownloadItem.Status.completed }.count
- return Double(completed) / Double(total)
- }
-
- var attachmentDownloadSummary: (completed: Int, total: Int)? {
- let active = attachmentDownloads.filter { $0.status != AttachmentDownloadItem.Status.canceled }
- let total = active.count
- guard total > 0 else { return nil }
-
- let hasPending = active.contains { item in
- item.status == AttachmentDownloadItem.Status.queued ||
- item.status == AttachmentDownloadItem.Status.downloading ||
- item.status == AttachmentDownloadItem.Status.failed
- }
- guard hasPending else { return nil }
-
- let completed = active.filter { $0.status == AttachmentDownloadItem.Status.completed }.count
- return (completed, total)
- }
-
var modelDownloadSizeText: String {
guard let bytes = modelDownloadSizeBytes else { return "Approx. size varies by model" }
return "Approx. \(bytes.formattedFileSize)"
@@ -325,7 +281,6 @@ final class ChatViewModel: ObservableObject {
currentSessionId = nil
messages = []
- refreshAttachmentDownloadState()
}
func selectSession(_ session: ChatSession) {
@@ -363,7 +318,6 @@ final class ChatViewModel: ObservableObject {
messageStore[session.id] = nil
branchSelections[session.id] = nil
childrenByParentCache[session.id] = nil
- purgeAttachmentDownloads(for: session.id)
if currentSessionId == session.id {
currentSessionId = sessions.first?.id
if let next = currentSessionId {
@@ -371,7 +325,6 @@ final class ChatViewModel: ObservableObject {
loadMessagesFromDb(for: next)
} else {
messages = []
- refreshAttachmentDownloadState()
}
}
}
@@ -409,7 +362,6 @@ final class ChatViewModel: ObservableObject {
guard !isGenerating,
!isDownloading,
- !isAttachmentDownloadBlocked,
editingMessageId == nil else {
return
}
@@ -424,7 +376,6 @@ final class ChatViewModel: ObservableObject {
return self.currentSessionId == voiceSessionId &&
!self.isGenerating &&
!self.isDownloading &&
- !self.isAttachmentDownloadBlocked &&
self.editingMessageId == nil
}
)
@@ -472,7 +423,6 @@ final class ChatViewModel: ObservableObject {
func addImageAttachment(data: Data, fileName: String?) {
guard !isGenerating,
!isDownloading,
- !isAttachmentDownloadBlocked,
draftImageAttachmentCount < ChatAttachmentLimits.maxImagesPerMessage else { return }
isProcessingAttachments = true
@@ -532,7 +482,7 @@ final class ChatViewModel: ObservableObject {
}
func addDocumentAttachment(url: URL) {
- guard !isGenerating && !isDownloading && !isAttachmentDownloadBlocked else { return }
+ guard !isGenerating && !isDownloading else { return }
isProcessingAttachments = true
Task.detached { [weak self] in
@@ -599,7 +549,7 @@ final class ChatViewModel: ObservableObject {
}
func sendDraft() {
- guard !isGenerating && !isDownloading && !isAttachmentDownloadBlocked else { return }
+ guard !isGenerating && !isDownloading else { return }
guard !isChatUnsupported else {
showUnsupportedDeviceDialog = true
return
@@ -633,11 +583,6 @@ final class ChatViewModel: ObservableObject {
}
let sessionId = self.currentSessionId ?? self.createSessionForDraft()
- let missing = await self.missingAttachments(for: sessionId)
- if !missing.isEmpty {
- self.queueMissingAttachments(for: sessionId, missing: missing)
- return
- }
self.sendDraftMessage(trimmed: trimmed, attachments: attachments, sessionId: sessionId)
}
}
@@ -971,15 +916,8 @@ final class ChatViewModel: ObservableObject {
userNode = messageStore[sessionId]?.first(where: { $0.id == parentId })
}
guard let userNode else { return }
- Task { @MainActor in
- let missing = await self.missingAttachments(for: sessionId)
- if !missing.isEmpty {
- self.queueMissingAttachments(for: sessionId, missing: missing)
- return
- }
- self.provider.resetContext()
- self.startGeneration(for: userNode)
- }
+ provider.resetContext()
+ startGeneration(for: userNode)
}
func changeBranch(for message: RenderedChatMessage, delta: Int) {
@@ -1012,7 +950,6 @@ final class ChatViewModel: ObservableObject {
messageStore[session.id] = []
branchSelections[session.id] = [:]
invalidateChildrenCache(for: session.id)
- refreshAttachmentDownloadState()
return session.id
}
@@ -1383,165 +1320,6 @@ final class ChatViewModel: ObservableObject {
return (progress, isDownloaded)
}
- private func queueMissingAttachments(for sessionId: UUID, missing: [AttachmentDownloadItem]? = nil) {
- Task { @MainActor in
- let resolvedMissing: [AttachmentDownloadItem]
- if let missing {
- resolvedMissing = missing
- } else {
- resolvedMissing = await self.missingAttachments(for: sessionId)
- }
-
- guard !resolvedMissing.isEmpty else {
- self.refreshAttachmentDownloadState(missing: [])
- return
- }
-
- var updated = self.attachmentDownloads
- for item in resolvedMissing {
- if let existingIndex = updated.firstIndex(where: { $0.id == item.id }) {
- if updated[existingIndex].status == AttachmentDownloadItem.Status.failed ||
- updated[existingIndex].status == AttachmentDownloadItem.Status.canceled {
- updated[existingIndex].status = AttachmentDownloadItem.Status.queued
- updated[existingIndex].errorMessage = nil
- }
- } else {
- updated.append(item)
- }
- }
-
- self.attachmentDownloads = updated
- for item in resolvedMissing {
- if !self.attachmentDownloadQueue.contains(item.id) && self.attachmentDownloadTasks[item.id] == nil {
- self.attachmentDownloadQueue.append(item.id)
- }
- }
-
- self.refreshAttachmentDownloadState(missing: resolvedMissing)
- self.startNextAttachmentDownloads()
- }
- }
-
- private func missingAttachments(for sessionId: UUID) async -> [AttachmentDownloadItem] {
- guard let nodes = messageStore[sessionId], !nodes.isEmpty else { return [] }
- let attachments = nodes.flatMap { $0.attachments }
- let existingDownloads = attachmentDownloads
- let attachmentsDir = attachmentsDir
-
- let result: (missing: [AttachmentDownloadItem], availableIds: Set<String>) = await Task.detached {
- var seen = Set<String>()
- var missing: [AttachmentDownloadItem] = []
- var availableIds = Set<String>()
-
- for attachment in attachments {
- let id = attachment.id.uuidString.lowercased()
- if seen.contains(id) { continue }
- seen.insert(id)
- let path = attachmentsDir.appendingPathComponent(id).path
- if FileManager.default.fileExists(atPath: path) {
- availableIds.insert(id)
- continue
- }
- let existing = existingDownloads.first { $0.id == id }
- let status = existing?.status ?? AttachmentDownloadItem.Status.queued
- missing.append(AttachmentDownloadItem(
- id: id,
- sessionId: sessionId,
- name: attachment.name,
- size: attachment.size,
- status: status,
- errorMessage: existing?.errorMessage
- ))
- }
-
- return (missing, availableIds)
- }.value
-
- if !result.availableIds.isEmpty {
- for id in result.availableIds {
- attachmentDownloadTasks[id]?.cancel()
- attachmentDownloadTasks[id] = nil
- }
- attachmentDownloadQueue.removeAll { result.availableIds.contains($0) }
- attachmentDownloads.removeAll { result.availableIds.contains($0.id) }
- }
-
- return result.missing
- }
-
- private func startNextAttachmentDownloads() {
- guard attachmentDownloadTasks.count < maxAttachmentDownloads else { return }
-
- while attachmentDownloadTasks.count < maxAttachmentDownloads, !attachmentDownloadQueue.isEmpty {
- let id = attachmentDownloadQueue.removeFirst()
- guard let index = attachmentDownloads.firstIndex(where: { $0.id == id }) else { continue }
- if attachmentDownloads[index].status == AttachmentDownloadItem.Status.canceled ||
- attachmentDownloads[index].status == AttachmentDownloadItem.Status.completed {
- continue
- }
- attachmentDownloads[index].status = AttachmentDownloadItem.Status.failed
- attachmentDownloads[index].errorMessage = "Attachment is not available on this device."
- }
- refreshAttachmentDownloadState()
- }
-
- private func updateAttachmentDownloadStatus(
- id: String,
- status: AttachmentDownloadItem.Status,
- errorMessage: String?
- ) {
- if let index = attachmentDownloads.firstIndex(where: { $0.id == id }) {
- if attachmentDownloads[index].status != AttachmentDownloadItem.Status.canceled {
- attachmentDownloads[index].status = status
- attachmentDownloads[index].errorMessage = status == AttachmentDownloadItem.Status.failed ? errorMessage : nil
- }
- }
- attachmentDownloadTasks[id] = nil
- refreshAttachmentDownloadState()
- startNextAttachmentDownloads()
- }
-
- private func refreshAttachmentDownloadState(missing: [AttachmentDownloadItem]? = nil) {
- guard let sessionId = currentSessionId else {
- currentSessionMissingAttachments = []
- return
- }
-
- if let missing {
- currentSessionMissingAttachments = missing
- return
- }
-
- Task { @MainActor in
- self.currentSessionMissingAttachments = await self.missingAttachments(for: sessionId)
- }
- }
-
- func cancelAttachmentDownload(_ id: String) {
- if let task = attachmentDownloadTasks[id] {
- task.cancel()
- attachmentDownloadTasks[id] = nil
- }
- if let index = attachmentDownloads.firstIndex(where: { $0.id == id }) {
- attachmentDownloads[index].status = AttachmentDownloadItem.Status.canceled
- }
- attachmentDownloadQueue.removeAll { $0 == id }
- refreshAttachmentDownloadState()
- startNextAttachmentDownloads()
- }
-
- private func purgeAttachmentDownloads(for sessionId: UUID) {
- let ids = attachmentDownloads.filter { $0.sessionId == sessionId }.map { $0.id }
- for id in ids {
- attachmentDownloadTasks[id]?.cancel()
- attachmentDownloadTasks[id] = nil
- attachmentDownloadQueue.removeAll { $0 == id }
- attachmentDownloads.removeAll { $0.id == id }
- }
- refreshAttachmentDownloadState()
- startNextAttachmentDownloads()
- }
-
private nonisolated static func buildSessions(
from loaded: [DbSession],
chatDb: EnsuDb,
@@ -1621,8 +1399,6 @@ final class ChatViewModel: ObservableObject {
if let current = resolved {
self.loadMessagesFromDb(for: current)
- } else {
- self.refreshAttachmentDownloadState()
}
}
}
@@ -1652,13 +1428,13 @@ final class ChatViewModel: ObservableObject {
let attachments: [ChatAttachment] = msg.attachments.compactMap { meta in
guard let attachmentId = UUID(uuidString: meta.id) else { return nil }
let kind: ChatAttachment.Kind = (meta.kind == .image) ? .image : .document
- let url = attachmentsDir.appendingPathComponent(meta.id)
+ let file = attachmentsDir.appendingPathComponent(meta.id)
return ChatAttachment(
id: attachmentId,
name: meta.name,
size: meta.size,
kind: kind,
- url: url,
+ url: FileManager.default.fileExists(atPath: file.path) ? file : nil,
isUploading: false
)
}
@@ -1684,7 +1460,6 @@ final class ChatViewModel: ObservableObject {
self.invalidateChildrenCache(for: sessionId)
if self.currentSessionId == sessionId {
self.rebuildMessages(for: sessionId)
- self.queueMissingAttachments(for: sessionId)
}
}
}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift
index 0a5d0efd11..6d26e66c91 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift
@@ -157,109 +157,15 @@ struct SignInComingSoonDialog: View {
}
}
-struct AttachmentDownloadsSheet: View {
- let downloads: [AttachmentDownloadItem]
- let sessionTitle: (UUID) -> String
- let onCancel: (String) -> Void
- let onDismiss: () -> Void
-
- var body: some View {
- VStack(spacing: 0) {
- HStack {
- Text("Attachment downloads")
- .font(EnsuTypography.h3Bold)
- Spacer()
- Button("Close", action: onDismiss)
- .font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.action)
- }
- .padding(.horizontal, EnsuSpacing.pageHorizontal)
- .padding(.vertical, EnsuSpacing.sm)
-
- Divider()
- .background(EnsuColor.border)
-
- if downloads.isEmpty {
- Text("No pending downloads")
- .font(EnsuTypography.body)
- .foregroundStyle(EnsuColor.textMuted)
- .padding(.top, EnsuSpacing.lg)
- Spacer()
- } else {
- List(downloads) { item in
- HStack(spacing: EnsuSpacing.md) {
- VStack(alignment: .leading, spacing: 4) {
- Text(item.name)
- .font(EnsuTypography.body)
- .foregroundStyle(EnsuColor.textPrimary)
- .lineLimit(1)
- Text("\(sessionTitle(item.sessionId)) β€’ \(item.formattedSize)")
- .font(EnsuTypography.mini)
- .foregroundStyle(EnsuColor.textMuted)
- if item.status == .failed, let errorMessage = item.errorMessage, !errorMessage.isEmpty {
- Text(errorMessage)
- .font(EnsuTypography.mini)
- .foregroundStyle(EnsuColor.error)
- .lineLimit(2)
- }
- }
-
- Spacer()
-
- Text(statusText(for: item.status))
- .font(EnsuTypography.mini)
- .foregroundStyle(EnsuColor.textMuted)
-
- if item.status == .queued || item.status == .downloading {
- Button(action: {
- hapticWarning()
- onCancel(item.id)
- }) {
- Image("Cancel01Icon")
- .resizable()
- .scaledToFit()
- .frame(width: 18, height: 18)
- .foregroundStyle(EnsuColor.textMuted)
- }
- .buttonStyle(.plain)
- }
- }
- .padding(.vertical, 4)
- }
- .listStyle(.plain)
- }
- }
- .frame(minHeight: 320)
- .background(EnsuColor.backgroundBase)
- }
-
- private func statusText(for status: AttachmentDownloadItem.Status) -> String {
- switch status {
- case .queued:
- return "Queued"
- case .downloading:
- return "Downloading"
- case .completed:
- return "Completed"
- case .failed:
- return "Failed"
- case .canceled:
- return "Canceled"
- }
- }
-}
-
struct ChatAppBar: View {
let sessionTitle: String
let showBrand: Bool
let showSignIn: Bool
let showsMenuButton: Bool
- let attachmentDownloadSummary: (completed: Int, total: Int)?
let modelDownloadState: DownloadToastState?
let onMenu: () -> Void
let onSignIn: () -> Void
let onNewChat: () -> Void
- let onAttachmentDownloads: () -> Void
private let centerInset: CGFloat = 72
@@ -310,28 +216,6 @@ struct ChatAppBar: View {
}
.buttonStyle(.plain)
} else {
- if let summary = attachmentDownloadSummary {
- Button(action: {
- hapticTap()
- onAttachmentDownloads()
- }) {
- HStack(spacing: 6) {
- Image("Upload01Icon")
- .resizable()
- .scaledToFit()
- .frame(width: 14, height: 14)
- .foregroundStyle(EnsuColor.textPrimary)
- Text("\(summary.completed)/\(summary.total)")
- .font(EnsuTypography.mini)
- .foregroundStyle(EnsuColor.textMuted)
- }
- .padding(.horizontal, 8)
- .padding(.vertical, 6)
- .background(EnsuColor.fillFaint)
- .clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
- }
- .buttonStyle(.plain)
- }
if let progress = modelProgressState {
ModelProgressIndicator(state: progress)
}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift
index 06aa7327be..5d329738c8 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift
@@ -10,7 +10,6 @@ struct MessageInputView: View {
let isDownloading: Bool
let editingMessage: RenderedChatMessage?
let isProcessingAttachments: Bool
- let isAttachmentDownloadBlocked: Bool
let voiceInputState: VoiceInputState
let moveCursorToEndToken: UUID
let onSend: () -> Void
@@ -28,21 +27,16 @@ struct MessageInputView: View {
@State private var selectedPhotoItem: PhotosPickerItem?
@State private var inputResetToken = UUID()
- private var placeholder: String {
- if isAttachmentDownloadBlocked {
- return "Downloading attachments..."
- }
- return "Write a message..."
- }
+ private let placeholder = "Write a message..."
private var canSend: Bool {
let hasContent = !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || !attachments.isEmpty
- return hasContent && !isGenerating && !isDownloading && !isAttachmentDownloadBlocked && !voiceInputState.blocksSend
+ return hasContent && !isGenerating && !isDownloading && !voiceInputState.blocksSend
}
private var isSendEnabled: Bool {
let hasContent = !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || !attachments.isEmpty
- return hasContent && !isDownloading && !isAttachmentDownloadBlocked && !voiceInputState.blocksSend
+ return hasContent && !isDownloading && !voiceInputState.blocksSend
}
private var isImageAttachmentLimitReached: Bool {
@@ -162,7 +156,6 @@ struct MessageInputView: View {
if editingMessage == nil {
let canUseAttachment = !isGenerating &&
!isDownloading &&
- !isAttachmentDownloadBlocked &&
!isImageAttachmentLimitReached
PhotosPicker(selection: $selectedPhotoItem, matching: .images) {
Image("Upload01Icon")
@@ -199,7 +192,7 @@ struct MessageInputView: View {
if editingMessage == nil {
let isVoiceBusy = voiceInputState.isTranscriptionBusy
let canUseVoice = voiceInputState.isRecording ||
- (!isGenerating && !isDownloading && !isAttachmentDownloadBlocked && !isVoiceBusy)
+ (!isGenerating && !isDownloading && !isVoiceBusy)
Button {
if voiceInputState.isRecording {
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift
index 70eba5e7ba..c38aea4bd7 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift
@@ -181,7 +181,9 @@ struct UserMessageBubbleView: View {
} else {
AttachmentChip(
name: attachment.name,
- size: attachment.formattedSize,
+ size: attachment.url == nil
+ ? "Unavailable on this device"
+ : attachment.formattedSize,
icon: attachment.iconName,
isUploading: attachment.isUploading
)
@@ -189,6 +191,7 @@ struct UserMessageBubbleView: View {
hapticTap()
onOpenAttachment(attachment)
}
+ .allowsHitTesting(attachment.url != nil)
}
}
}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/Models/ChatModels.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/Models/ChatModels.swift
index 4f8abfff31..50ee316315 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/Models/ChatModels.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/Models/ChatModels.swift
@@ -45,27 +45,6 @@ enum ChatAttachmentLimits {
static let maxImagesPerMessage = 2
}
-struct AttachmentDownloadItem: Identifiable, Equatable {
- enum Status {
- case queued
- case downloading
- case completed
- case failed
- case canceled
- }
-
- let id: String
- let sessionId: UUID
- let name: String
- let size: Int64
- var status: Status
- var errorMessage: String? = nil
-
- var formattedSize: String {
- size.formattedFileSize
- }
-}
-
struct RenderedChatMessage: Identifiable, Equatable {
enum Role: String {
case user
diff --git a/rust/crates/ensu/src/db/chat/mod.rs b/rust/crates/ensu/src/db/chat/mod.rs
index d6a4f8ba21..e6fc697f0d 100644
--- a/rust/crates/ensu/src/db/chat/mod.rs
+++ b/rust/crates/ensu/src/db/chat/mod.rs
@@ -1,5 +1,5 @@
-pub mod migrations;
-pub mod schema;
+mod migrations;
+mod schema;
use std::collections::BTreeSet;
use std::sync::Arc;
@@ -287,19 +287,6 @@ impl<B: Backend> ChatDb<B> {
})
}
- pub fn delete_message(&self, uuid: Uuid) -> Result<()> {
- let updated_at = self.clock.now_us();
- self.backend.transaction(|tx| {
- let session_uuid = message_session_uuid(tx, uuid)?;
- let affected = tx.execute(
- "DELETE FROM messages WHERE message_uuid = ?",
- &[Value::Text(uuid.to_string())],
- )?;
- ensure_row_updated(affected, EntityType::Message, uuid)?;
- self.touch_session(tx, session_uuid, updated_at)
- })
- }
-
fn session_from_row(&self, row: &crate::db::backend::Row) -> Result<Session> {
Ok(Session {
uuid: Uuid::parse_str(&row.get_string(0)?)?,
diff --git a/rust/crates/ensu/src/db/chat/schema.rs b/rust/crates/ensu/src/db/chat/schema.rs
index ed9c23d940..43a170f61f 100644
--- a/rust/crates/ensu/src/db/chat/schema.rs
+++ b/rust/crates/ensu/src/db/chat/schema.rs
@@ -1,9 +1,9 @@
-pub const CREATE_INDEXES: &str = "
+pub(super) const CREATE_INDEXES: &str = "
CREATE INDEX IF NOT EXISTS idx_messages_order ON messages(session_uuid, created_at, message_uuid);
CREATE INDEX IF NOT EXISTS idx_sessions_updated ON sessions(updated_at);
";
-pub const CREATE_ALL: &str = "
+pub(super) const CREATE_ALL: &str = "
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS sessions (