X Tutup
Skip to content

Commit 7444da4

Browse files
committed
Fix hasChatId to not depend on feature flag state
The hasChatId function in DuckChatContextualViewModel was delegating to duckChat.extractChatId(), which internally calls isDuckChatUrl(). That method returns false when isDuckChatFeatureEnabled is false. This created an unintended feature-flag dependency for UI state logic (showFullscreen) and chat context storage decisions. When the feature flag is off, hasChatId would incorrectly return false for valid URLs with a chatID parameter. Changed hasChatId to perform a direct URL parse without feature flag dependency, restoring the original behavior.
1 parent 78df013 commit 7444da4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/contextual/DuckChatContextualViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.duckduckgo.duckchat.impl.contextual
1818

19+
import androidx.core.net.toUri
1920
import androidx.lifecycle.ViewModel
2021
import androidx.lifecycle.viewModelScope
2122
import com.duckduckgo.anvil.annotations.ContributesViewModel
@@ -30,6 +31,7 @@ import com.duckduckgo.duckchat.impl.pixel.DuckChatPixels
3031
import com.duckduckgo.duckchat.impl.store.DuckChatContextualDataStore
3132
import com.duckduckgo.js.messaging.api.SubscriptionEventData
3233
import com.google.android.material.bottomsheet.BottomSheetBehavior
34+
import javax.inject.Inject
3335
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST
3436
import kotlinx.coroutines.channels.Channel
3537
import kotlinx.coroutines.flow.MutableStateFlow
@@ -41,7 +43,6 @@ import kotlinx.coroutines.launch
4143
import kotlinx.coroutines.withContext
4244
import logcat.logcat
4345
import org.json.JSONObject
44-
import javax.inject.Inject
4546

4647
@ContributesViewModel(FragmentScope::class)
4748
class DuckChatContextualViewModel @Inject constructor(
@@ -529,7 +530,11 @@ class DuckChatContextualViewModel @Inject constructor(
529530
}
530531

531532
private fun hasChatId(url: String?): Boolean {
532-
return url != null && duckChat.extractChatId(url) != null
533+
return url?.toUri()?.getQueryParameter(CHAT_ID_PARAM)?.isNotBlank() == true
534+
}
535+
536+
companion object {
537+
private const val CHAT_ID_PARAM = "chatID"
533538
}
534539

535540
private suspend fun shouldReuseStoredChatUrl(tabId: String): Boolean {

0 commit comments

Comments
 (0)
X Tutup