π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
resolve feedbacks
Prateek Sunal9f4e7c6babb8
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 87932624a6..be4e13a6e1 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@@ -36,7 +36,6 @@ import androidx.compose.material.icons.outlined.Descriptionimport androidx.compose.material.icons.outlined.Downloadimport androidx.compose.material.icons.outlined.Imageimport androidx.compose.material.icons.outlined.Refresh-import androidx.compose.material.icons.outlined.Codeimport androidx.compose.material.icons.outlined.Closeimport androidx.compose.material3.CircularProgressIndicatorimport androidx.compose.material3.Icon@@ -55,10 +54,14 @@ import androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.SolidColorimport androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.ui.hapticfeedback.HapticFeedbackType+import androidx.compose.ui.platform.LocalHapticFeedback+import androidx.compose.ui.text.AnnotatedStringimport androidx.compose.ui.text.input.KeyboardCapitalizationimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dp+import androidx.compose.ui.platform.LocalClipboardManagerimport io.ente.ensu.components.ActionButtonimport io.ente.ensu.components.BranchSwitcherimport io.ente.ensu.designsystem.EnsuColor@@ -170,7 +173,10 @@ private fun MessageList(}val listState = rememberLazyListState()+ val haptic = LocalHapticFeedback.currentvar autoScrollEnabled by remember { mutableStateOf(true) }+ var lastHapticLength by remember { mutableStateOf(0) }+ var shouldJumpToBottomOnLoad by remember { mutableStateOf(true) }val isAtBottom by remember {derivedStateOf {val layoutInfo = listState.layoutInfo@@ -187,6 +193,14 @@ private fun MessageList(LaunchedEffect(isGenerating) {if (isGenerating) {autoScrollEnabled = true+ lastHapticLength = 0+ }+ }++ LaunchedEffect(messages.size) {+ if (shouldJumpToBottomOnLoad && messages.isNotEmpty()) {+ listState.scrollToItem(messages.size)+ shouldJumpToBottomOnLoad = false}}@@ -196,10 +210,24 @@ private fun MessageList(}}+ LaunchedEffect(isAtBottom, isGenerating) {+ if (isGenerating && isAtBottom) {+ autoScrollEnabled = true+ }+ }++ LaunchedEffect(streamingResponse, isGenerating) {+ if (!isGenerating) return@LaunchedEffect+ val length = streamingResponse.length+ if (length > lastHapticLength) {+ haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)+ lastHapticLength = length+ }+ }+LaunchedEffect(messages.size, streamingResponse, streamingParentId, isGenerating, autoScrollEnabled) {if (!autoScrollEnabled) return@LaunchedEffect- if (messages.isEmpty()) return@LaunchedEffect- val targetIndex = messages.lastIndex+ val targetIndex = messages.sizeif (targetIndex >= 0) {listState.animateScrollToItem(targetIndex)}@@ -243,6 +271,10 @@ private fun MessageList(StreamingMessageBubble(text = streamingResponse)}}++ item(key = "bottom") {+ Spacer(modifier = Modifier.height(1.dp))+ }}}@@ -270,6 +302,8 @@ private fun UserMessageBubble(onBranchChange: (String, Int) -> Unit,onOpenAttachment: (Attachment) -> Unit) {+ val clipboard = LocalClipboardManager.current+Column(modifier = Modifier.fillMaxWidth()@@ -316,7 +350,7 @@ private fun UserMessageBubble()ActionButton(icon = Icons.Outlined.ContentCopy,- onTap = {},+ onTap = { clipboard.setText(AnnotatedString(message.text)) },contentDescription = "Copy")}@@ -352,6 +386,8 @@ private fun AssistantMessageBubble(onRetry: () -> Unit,onBranchChange: (String, Int) -> Unit) {+ val clipboard = LocalClipboardManager.current+Column(modifier = Modifier.fillMaxWidth()@@ -374,26 +410,14 @@ private fun AssistantMessageBubble(Row(verticalAlignment = Alignment.CenterVertically) {ActionButton(icon = Icons.Outlined.ContentCopy,- onTap = {},+ onTap = { clipboard.setText(AnnotatedString(message.text)) },contentDescription = "Copy")- ActionButton(- icon = Icons.Outlined.Code,- onTap = {},- contentDescription = "Raw"- )ActionButton(icon = Icons.Outlined.Refresh,onTap = onRetry,contentDescription = "Retry")- message.tokensPerSecond?.let { tokPerSec ->- Text(- text = String.format(Locale.US, "%.1f tok/s", tokPerSec),- style = EnsuTypography.mini,- color = EnsuColor.textMuted()- )- }}Spacer(modifier = Modifier.height(EnsuSpacing.xs.dp))@@ -429,11 +453,7 @@ private fun StreamingMessageBubble(text: String) {if (text.isBlank()) {LoadingDotsText()} else {- Text(- text = text,- style = EnsuTypography.message,- color = EnsuColor.textPrimary()- )+ MarkdownView(markdown = text)}}}diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/MarkdownRenderer.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/MarkdownRenderer.ktindex 47aaf6d076..d03839faec 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/MarkdownRenderer.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/MarkdownRenderer.kt@@ -131,9 +131,9 @@ private fun CodeBlockView(code: String) {.horizontalScroll(rememberScrollState()).padding(start = EnsuSpacing.cardPadding.dp,- end = (EnsuSpacing.cardPadding + 28).dp,+ end = (EnsuSpacing.cardPadding + 32).dp,top = EnsuSpacing.cardPadding.dp,- bottom = EnsuSpacing.cardPadding.dp+ bottom = (EnsuSpacing.cardPadding + 32).dp)) {Text(@@ -146,14 +146,15 @@ private fun CodeBlockView(code: String) {IconButton(onClick = { clipboard.setText(AnnotatedString(code)) },modifier = Modifier- .align(Alignment.TopEnd)+ .align(Alignment.BottomEnd).padding(EnsuSpacing.xs.dp).size(28.dp)) {Icon(imageVector = Icons.Outlined.ContentCopy,contentDescription = "Copy code",- tint = EnsuColor.textMuted()+ tint = EnsuColor.textMuted(),+ modifier = Modifier.size(16.dp))}}diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ChatState.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ChatState.ktindex d1bfdb4f56..0bcf4e2d7b 100644--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ChatState.kt+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ChatState.kt@@ -22,5 +22,7 @@ data class ChatState(val isProcessingAttachments: Boolean = false,val attachmentDownloads: List<io.ente.ensu.domain.model.AttachmentDownloadItem> = emptyList(),val attachmentDownloadProgress: Int? = null,- val isAttachmentDownloadBlocked: Boolean = false+ val isAttachmentDownloadBlocked: Boolean = false,+ val transientAssistantError: String? = null,+ val transientAssistantParentId: String? = null)diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swiftindex 9d777bcde7..09f2c8df50 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatView.swift@@ -8,7 +8,6 @@ struct ChatView: View {@State private var isDrawerOpen = false@State private var showModelSettings = false- @State private var rawMessage: ChatMessage?@State private var toastMessage: ToastMessage?@State private var deleteSession: ChatSession?@State private var developerTapCount = 0@@ -85,9 +84,6 @@ struct ChatView: View {showToast(message, duration: 2)}}- .sheet(item: $rawMessage) { message in- RawMessageDialog(text: message.text)- }.alert("Developer settings", isPresented: $showDeveloperAlert) {Button("Yes") {showDeveloperSettings = true@@ -162,9 +158,6 @@ struct ChatView: View {copyToPasteboard(message.text)showToast("Copied to clipboard", duration: 1)},- onShowRaw: { message in- rawMessage = message- },onRetry: { message inviewModel.retryAssistantResponse(message)},diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swiftindex 1551ecc077..56b85febe6 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift@@ -1,5 +1,8 @@import SwiftUIimport QuickLook+#if os(iOS)+import UIKit+#endifstruct MessageListView: View {let messages: [ChatMessage]@@ -8,13 +11,16 @@ struct MessageListView: View {let isGenerating: Boollet onEdit: (ChatMessage) -> Voidlet onCopy: (ChatMessage) -> Void- let onShowRaw: (ChatMessage) -> Voidlet onRetry: (ChatMessage) -> Voidlet onBranchChange: (ChatMessage, Int) -> Void@State private var isAtBottom = true@State private var autoScrollEnabled = true@State private var previewItem: AttachmentPreviewItem?+ @State private var lastHapticLength = 0+ #if os(iOS)+ @State private var haptic = UIImpactFeedbackGenerator(style: .medium)+ #endifvar body: some View {GeometryReader { proxy in@@ -42,7 +48,6 @@ struct MessageListView: View {AssistantMessageBubbleView(message: message,onCopy: { onCopy(message) },- onShowRaw: { onShowRaw(message) },onRetry: { onRetry(message) },onBranchChange: { delta in onBranchChange(message, delta) },onOpenAttachment: openAttachment@@ -87,16 +92,39 @@ struct MessageListView: View {.onChange(of: messages.count) { _ inscrollToBottom(scrollProxy)}- .onChange(of: streamingResponse) { _ in+ .onChange(of: streamingResponse) { newValue in+ #if os(iOS)+ if isGenerating {+ let length = newValue.count+ if length > lastHapticLength {+ haptic.impactOccurred()+ haptic.prepare()+ lastHapticLength = length+ }+ }+ #endifscrollToBottom(scrollProxy)}.onChange(of: isGenerating) { newValue inif newValue {+ autoScrollEnabled = true+ lastHapticLength = 0+ #if os(iOS)+ haptic.prepare()+ #endif+ scrollToBottom(scrollProxy, force: true)+ }+ }+ .onChange(of: isAtBottom) { newValue in+ if newValue && isGenerating {autoScrollEnabled = truescrollToBottom(scrollProxy, force: true)}}.onAppear {+ #if os(iOS)+ haptic.prepare()+ #endifscrollToBottom(scrollProxy, force: true)}}@@ -229,7 +257,6 @@ private struct UserMessageBubbleView: View {private struct AssistantMessageBubbleView: View {let message: ChatMessagelet onCopy: () -> Void- let onShowRaw: () -> Voidlet onRetry: () -> Voidlet onBranchChange: (Int) -> Voidlet onOpenAttachment: (ChatAttachment) -> Void@@ -248,15 +275,7 @@ private struct AssistantMessageBubbleView: View {HStack(spacing: EnsuSpacing.xs) {ActionButton(icon: "doc.on.doc", action: onCopy)- ActionButton(icon: "chevron.left.slash.chevron.right", action: onShowRaw)ActionButton(icon: "arrow.clockwise", action: onRetry)-- if let tokensPerSecond = message.tokensPerSecond {- Text(String(format: "%.1f tok/s", tokensPerSecond))- .font(EnsuTypography.mini)- .italic()- .foregroundStyle(EnsuColor.textMuted)- }}HStack(spacing: EnsuSpacing.sm) {@@ -787,60 +806,3 @@ private struct BlockQuoteView: View {}}-struct RawMessageDialog: View {- let text: String-- @Environment(\.dismiss) private var dismiss-- var body: some View {- Group {- #if os(iOS)- NavigationStack {- content- .navigationTitle("Raw message")- .toolbar {- ToolbarItem(placement: .primaryAction) {- Button("Close") {- dismiss()- }- }- }- }- #else- content- #endif- }- #if os(macOS)- .safeAreaInset(edge: .top) {- MacSheetHeader(- leading: {- EmptyView()- },- center: {- Text("Raw message")- .font(EnsuTypography.large)- .foregroundStyle(EnsuColor.textPrimary)- },- trailing: {- Button("Close") {- dismiss()- }- .font(EnsuTypography.small)- .foregroundStyle(EnsuColor.textMuted)- .buttonStyle(.plain)- }- )- }- #endif- }-- private var content: some View {- ScrollView {- Text(text)- .font(EnsuTypography.message)- .foregroundStyle(EnsuColor.textPrimary)- .textSelection(.enabled)- .padding(EnsuSpacing.lg)- }- }-}