π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[ensu] Preserve background replies
setalp7678fdc56ad5
diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.ktindex 58327851b1..5646f47e57 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/AppStore.kt@@ -144,11 +144,6 @@ class AppStore()}- fun setForeground(foreground: Boolean, chatVisible: Boolean) {- chatActions.setForeground(foreground && chatVisible)- notesStore.setForeground(foreground)- }-fun createNewSession(): String = chatActions.createNewSession()fun startNewSessionDraft() = chatActions.startNewSessionDraft()diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.ktindex 6f37ca4e66..87658544ac 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt@@ -197,18 +197,17 @@ fun HomeView(scope.launch { drawerState.close() }}- DisposableEffect(lifecycleOwner, isChatRoute) {+ DisposableEffect(lifecycleOwner) {val observer = LifecycleEventObserver { _, event ->if (event == Lifecycle.Event.ON_RESUME) {- latestStore.setForeground(true, isChatRoute)+ latestStore.notesStore.setForeground(true)latestStore.refreshModelDownloadInfo()} else if (event == Lifecycle.Event.ON_STOP) {- latestStore.setForeground(false, isChatRoute)+ latestStore.notesStore.setForeground(false)}}- latestStore.setForeground(- lifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED),- isChatRoute,+ latestStore.notesStore.setForeground(+ lifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED))lifecycleOwner.lifecycle.addObserver(observer)onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.ktindex 36612da12d..b1c7d7b947 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt@@ -66,8 +66,6 @@ internal class ChatStoreActions(private var generationJob: Job? = nullprivate var sessionSummaryJob: Job? = null@Volatile private var stopRequested = false- private var isForeground = true- private var preparingGenerationToken: Long? = null@Volatile private var activePreparation: ConversationPreparationControl? = nullprivate var streamingParentId: String? = nullprivate var activeGenerationToken = 0L@@ -431,14 +429,6 @@ internal class ChatStoreActions(rebuildChatState(state.value.chat.currentSessionId)}- fun setForeground(foreground: Boolean) {- isForeground = foreground- if (!foreground && preparingGenerationToken != null) {- resetGenerationState()- rebuildChatState(state.value.chat.currentSessionId)- }- }-fun loadSessionsFromDb() {val scope = scope ?: returnscope.launch(Dispatchers.IO) {@@ -490,7 +480,6 @@ internal class ChatStoreActions(val scope = scope ?: returnif (!state.value.chat.deviceCapability.isChatSupported()) returnval prompt = buildPrompt(userMessage.text, userMessage.attachments)- if (!isForeground && prompt.imageFiles.isEmpty()) returnval priorGeneration = generationJobval priorSummary = sessionSummaryJobactivePreparation?.cancel()@@ -504,7 +493,6 @@ internal class ChatStoreActions(clearTransientAssistantError()val generationToken = nextGenerationToken()- preparingGenerationToken = generationToken.takeIf { prompt.imageFiles.isEmpty() }streamingParentId = userMessage.idstate.update { appState ->appState.copy(@@ -908,9 +896,8 @@ internal class ChatStoreActions(throw kotlinx.coroutines.CancellationException()chatRepository.validateConversation(preparation)withContext(Dispatchers.Main) {- if (!isActive() || !isForeground || stopRequested)+ if (!isActive() || stopRequested)throw kotlinx.coroutines.CancellationException()- preparingGenerationToken = nullstate.update { it.copy(chat = it.chat.copy(preparationStatus = null)) }}val generated = runCatching {@@ -1664,7 +1651,6 @@ internal class ChatStoreActions(private fun cancelGeneration() {clearTransientAssistantError()- preparingGenerationToken = nullactivePreparation?.cancel()generationJob?.cancel()llmProvider.stopGeneration()@@ -1674,7 +1660,6 @@ internal class ChatStoreActions(}private fun settleGenerationIfActive(token: Long, sessionId: String) {- if (preparingGenerationToken == token) preparingGenerationToken = nullif (!isGenerationActive(token, sessionId) || !state.value.chat.isGenerating) returnstreamingParentId = nullstate.update { appState ->diff --git a/apple/apps/ensu/Ensu/Chat/ChatView.swift b/apple/apps/ensu/Ensu/Chat/ChatView.swiftindex 5177468650..6ff6342326 100644--- a/apple/apps/ensu/Ensu/Chat/ChatView.swift+++ b/apple/apps/ensu/Ensu/Chat/ChatView.swift@@ -144,7 +144,6 @@ struct ChatView: View {viewModel.modelSelectionChanged()}.onChange(of: scenePhase) { newValue in- viewModel.setForeground(newValue == .active)viewModel.notesStore.setForeground(newValue == .active)if newValue == .active {viewModel.refreshModelDownloadInfo()@@ -154,10 +153,7 @@ struct ChatView: View {}}.environmentObject(viewModel.notesStore)- .onAppear {- viewModel.setForeground(scenePhase == .active)- viewModel.notesStore.setForeground(scenePhase == .active)- }+ .onAppear { viewModel.notesStore.setForeground(scenePhase == .active) }.sheet(isPresented: $viewState.showSettings) {SettingsView(knowledgeStore: viewModel.knowledgeStore,diff --git a/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift b/apple/apps/ensu/Ensu/Chat/ChatViewModel.swiftindex fe5759b2d4..1622538525 100644--- a/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift+++ b/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift@@ -115,8 +115,6 @@ final class ChatViewModel: ObservableObject {private var stopRequested = falseprivate var activeGenerationId: UUID?private var activeGenerationSessionId: UUID?- private var activeTextPreparation = false- private var isForeground = trueprivate var modelDownloadLoggedStart = falseprivate let downloadProgressTracker = DownloadProgressTracker()private var pendingOverflow: PendingOverflow?@@ -300,7 +298,6 @@ final class ChatViewModel: ObservableObject {self.stopRequested = stopRequestedactiveGenerationId = nilactiveGenerationSessionId = nil- activeTextPreparation = falseisGenerating = falseisDownloading = falsestreamingResponse = ""@@ -719,14 +716,6 @@ final class ChatViewModel: ObservableObject {refreshModelDownloadInfo()}- func setForeground(_ foreground: Bool) {- isForeground = foreground- if !foreground && activeTextPreparation {- resetGenerationState()- if let currentSessionId { rebuildMessages(for: currentSessionId) }- }- }-func confirmOverflowTrim() {guard let pendingOverflow else { return }guard@@ -1074,7 +1063,6 @@ final class ChatViewModel: ObservableObject {}let selection = modelSettings.currentSelection()let prompt = buildPrompt(text: userNode.text, attachments: userNode.attachments)- guard isForeground || !prompt.imageFiles.isEmpty else { return }let priorGeneration = generationTasklet priorSummary = sessionSummaryTaskpriorGeneration?.cancel()@@ -1086,7 +1074,6 @@ final class ChatViewModel: ObservableObject {let generationId = UUID()activeGenerationId = generationIdactiveGenerationSessionId = userNode.sessionId- activeTextPreparation = prompt.imageFiles.isEmptyisGenerating = trueisDownloading = falsehasRequestedModelDownload = true@@ -1152,7 +1139,6 @@ final class ChatViewModel: ObservableObject {self.sharedModelReadyTask?.cancel()self.clearSharedModelReadyTask()if self.activeGenerationId == generationId {- activeTextPreparation = falseisGenerating = falseisDownloading = falsestreamingParentId = nil@@ -1163,7 +1149,6 @@ final class ChatViewModel: ObservableObject {return}if self.activeGenerationId == generationId {- activeTextPreparation = falseisGenerating = falseisDownloading = falsestreamingParentId = nil@@ -1343,7 +1328,6 @@ final class ChatViewModel: ObservableObject {return}preparation = prepared- self.activeTextPreparation = falseself.conversationStatus = nil},onToken: onToken@@ -1562,7 +1546,6 @@ final class ChatViewModel: ObservableObject {}if isActiveGeneration {- activeTextPreparation = falseconversationStatus = nilisGenerating = falseisDownloading = false@@ -1583,7 +1566,6 @@ final class ChatViewModel: ObservableObject {private func settleGenerationIfActive(generationId: UUID, sessionId: UUID) {guard activeGenerationId == generationId, isGenerating else { return }- activeTextPreparation = falseconversationStatus = nilisGenerating = falseisDownloading = false