Skip to content

armgit / ente

Public Imported from GitHub
0

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

[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.kt
index 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.kt
index 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.kt
index 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? = null
private var sessionSummaryJob: Job? = null
@Volatile private var stopRequested = false
- private var isForeground = true
- private var preparingGenerationToken: Long? = null
@Volatile private var activePreparation: ConversationPreparationControl? = null
private var streamingParentId: String? = null
private 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 ?: return
scope.launch(Dispatchers.IO) {
@@ -490,7 +480,6 @@ internal class ChatStoreActions(
val scope = scope ?: return
if (!state.value.chat.deviceCapability.isChatSupported()) return
val prompt = buildPrompt(userMessage.text, userMessage.attachments)
- if (!isForeground && prompt.imageFiles.isEmpty()) return
val priorGeneration = generationJob
val priorSummary = sessionSummaryJob
activePreparation?.cancel()
@@ -504,7 +493,6 @@ internal class ChatStoreActions(
clearTransientAssistantError()
val generationToken = nextGenerationToken()
- preparingGenerationToken = generationToken.takeIf { prompt.imageFiles.isEmpty() }
streamingParentId = userMessage.id
state.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 = null
state.update { it.copy(chat = it.chat.copy(preparationStatus = null)) }
}
val generated = runCatching {
@@ -1664,7 +1651,6 @@ internal class ChatStoreActions(
private fun cancelGeneration() {
clearTransientAssistantError()
- preparingGenerationToken = null
activePreparation?.cancel()
generationJob?.cancel()
llmProvider.stopGeneration()
@@ -1674,7 +1660,6 @@ internal class ChatStoreActions(
}
private fun settleGenerationIfActive(token: Long, sessionId: String) {
- if (preparingGenerationToken == token) preparingGenerationToken = null
if (!isGenerationActive(token, sessionId) || !state.value.chat.isGenerating) return
streamingParentId = null
state.update { appState ->
diff --git a/apple/apps/ensu/Ensu/Chat/ChatView.swift b/apple/apps/ensu/Ensu/Chat/ChatView.swift
index 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.swift
index 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 = false
private var activeGenerationId: UUID?
private var activeGenerationSessionId: UUID?
- private var activeTextPreparation = false
- private var isForeground = true
private var modelDownloadLoggedStart = false
private let downloadProgressTracker = DownloadProgressTracker()
private var pendingOverflow: PendingOverflow?
@@ -300,7 +298,6 @@ final class ChatViewModel: ObservableObject {
self.stopRequested = stopRequested
activeGenerationId = nil
activeGenerationSessionId = nil
- activeTextPreparation = false
isGenerating = false
isDownloading = false
streamingResponse = ""
@@ -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 = generationTask
let priorSummary = sessionSummaryTask
priorGeneration?.cancel()
@@ -1086,7 +1074,6 @@ final class ChatViewModel: ObservableObject {
let generationId = UUID()
activeGenerationId = generationId
activeGenerationSessionId = userNode.sessionId
- activeTextPreparation = prompt.imageFiles.isEmpty
isGenerating = true
isDownloading = false
hasRequestedModelDownload = true
@@ -1152,7 +1139,6 @@ final class ChatViewModel: ObservableObject {
self.sharedModelReadyTask?.cancel()
self.clearSharedModelReadyTask()
if self.activeGenerationId == generationId {
- activeTextPreparation = false
isGenerating = false
isDownloading = false
streamingParentId = nil
@@ -1163,7 +1149,6 @@ final class ChatViewModel: ObservableObject {
return
}
if self.activeGenerationId == generationId {
- activeTextPreparation = false
isGenerating = false
isDownloading = false
streamingParentId = nil
@@ -1343,7 +1328,6 @@ final class ChatViewModel: ObservableObject {
return
}
preparation = prepared
- self.activeTextPreparation = false
self.conversationStatus = nil
},
onToken: onToken
@@ -1562,7 +1546,6 @@ final class ChatViewModel: ObservableObject {
}
if isActiveGeneration {
- activeTextPreparation = false
conversationStatus = nil
isGenerating = false
isDownloading = false
@@ -1583,7 +1566,6 @@ final class ChatViewModel: ObservableObject {
private func settleGenerationIfActive(generationId: UUID, sessionId: UUID) {
guard activeGenerationId == generationId, isGenerating else { return }
- activeTextPreparation = false
conversationStatus = nil
isGenerating = false
isDownloading = false