π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(ensu): improve mobile chat interruption and keyboard UX
Prateek Sunal7d4e68701877
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.ktindex 15d933583b..609eb3c37c 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt@@ -85,11 +85,6 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {}}- val email = credentialStore.getEmail()- if (credentialStore.isLoggedIn() && !email.isNullOrBlank()) {- store.signIn(email)- }-viewModelScope.launch {authService.storedEndpointFlow.collectLatest { endpoint ->authService.updateEndpoint(endpoint)@@ -105,6 +100,11 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {store.hydrateModelDownloadRequested(sessionPreferences.modelDownloadRequested.first())store.bootstrap(viewModelScope)+ val email = credentialStore.getEmail()+ if (credentialStore.isLoggedIn() && !email.isNullOrBlank()) {+ store.signIn(email)+ }+advancedSettingsDataStore.settingsFlow.drop(1).collectLatest { settings ->store.applyPersistedSettings(developerSettings = settings.developerSettings,diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.ktindex 0d1f8d68c9..5f9da2c4bb 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt@@ -632,16 +632,18 @@ private fun AssistantMessageBubble(showMenu = showMenu,pressOffset = pressOffset,onDismiss = { showMenu = false },- actions = listOf(- MessageAction("Copy", HugeIcons.Copy01Icon) {+ actions = buildList {+ add(MessageAction("Copy", HugeIcons.Copy01Icon) {haptic.perform(HapticFeedbackType.TextHandleMove)clipboard.setText(AnnotatedString(stripHiddenMessageParts(message.text)))- },- MessageAction("Retry", HugeIcons.RepeatIcon) {- haptic.perform(HapticFeedbackType.TextHandleMove)- onRetry()+ })+ if (!message.isSynthetic) {+ add(MessageAction("Retry", HugeIcons.RepeatIcon) {+ haptic.perform(HapticFeedbackType.TextHandleMove)+ onRetry()+ })}- )+ })}diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.ktindex cb116f5d4a..6a2aeea4fe 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatView.kt@@ -11,11 +11,19 @@ import androidx.compose.animation.togetherWithimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.WindowInsetsimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.imeimport androidx.compose.foundation.layout.imePaddingimport androidx.compose.foundation.layout.navigationBarsPaddingimport androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.rounded.KeyboardArrowDown+import androidx.compose.material3.Icon+import androidx.compose.material3.IconButtonimport androidx.compose.runtime.Composableimport androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.derivedStateOf@@ -24,7 +32,10 @@ import androidx.compose.runtime.keyimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue+import androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifier+import androidx.compose.ui.layout.onGloballyPositioned+import androidx.compose.ui.platform.LocalDensityimport androidx.compose.ui.platform.LocalFocusManagerimport androidx.compose.ui.unit.dpimport io.ente.ensu.designsystem.EnsuColor@@ -54,6 +65,9 @@ fun ChatView(onOverflowTrim: () -> Unit,onOverflowCancel: () -> Unit) {+ val density = LocalDensity.current+ var inputBarHeightDp by remember { mutableStateOf(0.dp) }+val showDownloadOnboarding by remember(chatState.isModelDownloaded,chatState.messages,@@ -177,7 +191,10 @@ fun ChatView(modifier = Modifier.fillMaxWidth().navigationBarsPadding()- .background(EnsuColor.backgroundBase()),+ .background(EnsuColor.backgroundBase())+ .onGloballyPositioned { coords ->+ inputBarHeightDp = with(density) { coords.size.height.toDp() }+ },messageText = chatState.messageText,attachments = chatState.attachments,editingMessage = editingMessage,@@ -201,6 +218,31 @@ fun ChatView(}}+ val imeVisible = WindowInsets.ime.getBottom(density) > 0+ if (imeVisible && inputBarHeightDp > 0.dp) {+ IconButton(+ onClick = { focusManager.clearFocus() },+ modifier = Modifier+ .align(Alignment.BottomEnd)+ .imePadding()+ .padding(+ end = EnsuSpacing.pageHorizontal.dp,+ bottom = inputBarHeightDp + EnsuSpacing.sm.dp+ )+ .background(+ color = EnsuColor.fillFaint(),+ shape = CircleShape+ )+ ) {+ Icon(+ imageVector = Icons.Rounded.KeyboardArrowDown,+ contentDescription = "Dismiss keyboard",+ modifier = Modifier.padding(7.dp),+ tint = EnsuColor.textPrimary()+ )+ }+ }+val status = chatState.downloadStatusval isLoading = status?.contains("Loading", ignoreCase = true) == trueval showToast by remember(status, chatState.isDownloading, showDownloadOnboarding, isLoading) {diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/ChatModels.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/ChatModels.ktindex e17a7800d6..3e7793fbab 100644--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/ChatModels.kt+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/ChatModels.kt@@ -16,6 +16,7 @@ data class ChatMessage(val timestampMillis: Long,val attachments: List<Attachment> = emptyList(),val isInterrupted: Boolean = false,+ val isSynthetic: Boolean = false,val tokensPerSecond: Double? = null,val branchCount: Int = 1)diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.ktindex 258af2166a..e93a2f0eba 100644--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt@@ -277,6 +277,7 @@ internal class ChatStoreActions(fun stopGeneration() {stopRequested = truellmProvider.stopGeneration()+ generationJob?.cancel()}fun retryAssistantMessage(messageId: String) {@@ -936,7 +937,25 @@ internal class ChatStoreActions(message.copy(branchCount = max(1, siblings.size))}- return displayMessages to branchSelectionIndices+ val finalMessages = if (+ displayMessages.size >= 2+ && displayMessages.last().author == MessageAuthor.User+ && !state.value.chat.isGenerating+ ) {+ val lastUser = displayMessages.last()+ displayMessages + ChatMessage(+ id = "interrupted-placeholder-${lastUser.id}",+ sessionId = sessionId,+ parentId = lastUser.id,+ author = MessageAuthor.Assistant,+ text = "Response was interrupted",+ timestampMillis = lastUser.timestampMillis,+ isInterrupted = true,+ isSynthetic = true+ )+ } else displayMessages++ return finalMessages to branchSelectionIndices}private fun buildSelectedPath(sessionId: String): List<ChatMessage> {diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swiftindex d4c9f1de9f..863a59b864 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift@@ -370,6 +370,28 @@ struct ChatView: View {.background(EnsuColor.backgroundBase).zIndex(2)}++ #if os(iOS)+ if keyboard.isVisible {+ Button {+ viewState.didDismissKeyboard = true+ isInputFocused = false+ hideKeyboard()+ } label: {+ Image(systemName: "chevron.down")+ .font(.system(size: 14, weight: .semibold))+ .foregroundStyle(EnsuColor.textPrimary)+ .frame(width: 32, height: 32)+ .background(.ultraThinMaterial)+ .clipShape(Circle())+ .shadow(color: .black.opacity(0.15), radius: 4, y: 2)+ }+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)+ .padding(.trailing, EnsuSpacing.pageHorizontal)+ .padding(.bottom, viewState.inputBarHeight + EnsuSpacing.sm)+ .zIndex(3)+ }+ #endif}.animation(.easeInOut(duration: 0.32), value: viewState.sessionTransitionId)}diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swiftindex b50179f18d..c3b872681d 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift@@ -1170,6 +1170,7 @@ final class ChatViewModel: ObservableObject {func stopGenerating() {stopRequested = trueprovider.stopGeneration()+ generationTask?.cancel()}func confirmOverflowTrim() {@@ -2188,11 +2189,26 @@ final class ChatViewModel: ObservableObject {timestamp: node.timestamp,attachments: node.attachments,isInterrupted: node.isInterrupted,+ isSynthetic: false,tokensPerSecond: node.tokensPerSecond,branchIndex: max(1, index + 1),branchCount: max(1, siblings.count))}++ if messages.count >= 2,+ let lastMessage = messages.last,+ lastMessage.role == .user,+ !isGenerating {+ messages.append(ChatMessage(+ id: UUID(),+ role: .assistant,+ text: "Response was interrupted",+ timestamp: lastMessage.timestamp,+ isInterrupted: true,+ isSynthetic: true+ ))+ }}private func buildSelectedPath(for sessionId: UUID, childrenMap: [UUID: [MessageNode]]) -> [MessageNode] {diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swiftindex 443ba394e0..f9cba5826f 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift@@ -188,14 +188,16 @@ struct AssistantMessageBubbleView: View {hapticTap()onCopy()}- Button("Retry") {- hapticMedium()- onRetry()+ if !message.isSynthetic {+ Button("Retry") {+ hapticMedium()+ onRetry()+ }}}#endif- if showsMetadata {+ if showsMetadata && !message.isSynthetic {HStack(spacing: EnsuSpacing.sm) {TimestampView(date: message.timestamp)if message.branchCount > 1 {diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swiftindex b173c936ae..4ae2ebf36b 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift@@ -285,7 +285,7 @@ struct MessageListView: View {let fallbackPadding = EnsuSpacing.xxxl + EnsuSpacing.xxl + 60let measuredPadding = inputBarHeight > 0 ? inputBarHeight + EnsuSpacing.md : fallbackPaddinglet basePadding = max(fallbackPadding, measuredPadding)- return basePadding+ return basePadding + keyboardHeight}private func scheduleInitialScroll(_ proxy: ScrollViewProxy) {diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swiftindex d1630ae32a..9a33caca4a 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/Models/ChatModels.swift@@ -74,6 +74,7 @@ struct ChatMessage: Identifiable, Equatable {var timestamp: Datevar attachments: [ChatAttachment]var isInterrupted: Bool+ var isSynthetic: Boolvar tokensPerSecond: Double?var branchIndex: Intvar branchCount: Int@@ -85,6 +86,7 @@ struct ChatMessage: Identifiable, Equatable {timestamp: Date = Date(),attachments: [ChatAttachment] = [],isInterrupted: Bool = false,+ isSynthetic: Bool = false,tokensPerSecond: Double? = nil,branchIndex: Int = 1,branchCount: Int = 1@@ -95,6 +97,7 @@ struct ChatMessage: Identifiable, Equatable {self.timestamp = timestampself.attachments = attachmentsself.isInterrupted = isInterrupted+ self.isSynthetic = isSyntheticself.tokensPerSecond = tokensPerSecondself.branchIndex = branchIndexself.branchCount = branchCount