-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2214 from HedvigInsurance/feature/conversation-an…
…d-new-chat-disambiguation-button-in-help-center Feature, conversation and new chat disambiguation button in help center
- Loading branch information
Showing
24 changed files
with
274 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id("hedvig.android.ktlint") | ||
id("hedvig.android.library") | ||
alias(libs.plugins.apollo) | ||
alias(libs.plugins.squareSortDependencies) | ||
} | ||
|
||
dependencies { | ||
implementation(libs.apollo.normalizedCache) | ||
implementation(libs.arrow.core) | ||
implementation(libs.koin.core) | ||
implementation(projects.apolloCore) | ||
implementation(projects.apolloOctopusPublic) | ||
} | ||
|
||
apollo { | ||
service("octopus") { | ||
packageName = "octopus" | ||
dependsOn(projects.apolloOctopusPublic, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
.../src/main/kotlin/com/hedvig/android/data/conversations/HasAnyActiveConversationUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.hedvig.android.data.conversations | ||
|
||
import arrow.core.Either | ||
import arrow.core.raise.either | ||
import com.apollographql.apollo.ApolloClient | ||
import com.apollographql.apollo.cache.normalized.FetchPolicy | ||
import com.apollographql.apollo.cache.normalized.fetchPolicy | ||
import com.hedvig.android.apollo.ApolloOperationError | ||
import com.hedvig.android.apollo.safeFlow | ||
import com.hedvig.android.logger.LogPriority | ||
import com.hedvig.android.logger.logcat | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import octopus.CbmNumberOfChatMessagesQuery | ||
import octopus.type.ChatMessageSender | ||
|
||
class HasAnyActiveConversationUseCase( | ||
private val apolloClient: ApolloClient, | ||
) { | ||
fun invoke(alwaysHitTheNetwork: Boolean = false): Flow<Either<ApolloOperationError, Boolean>> { | ||
return apolloClient | ||
.query(CbmNumberOfChatMessagesQuery()) | ||
.fetchPolicy(if (alwaysHitTheNetwork) FetchPolicy.CacheAndNetwork else FetchPolicy.CacheFirst) | ||
.safeFlow() | ||
.map { result -> | ||
either { | ||
val data = result | ||
.onLeft { apolloOperationError -> | ||
logcat(LogPriority.ERROR, apolloOperationError.throwable) { | ||
"isEligibleToShowTheChatIcon cant determine if the chat icon should be shown. $apolloOperationError" | ||
} | ||
} | ||
.bind() | ||
val eligibleFromLegacyConversation = data | ||
.currentMember | ||
.legacyConversation | ||
?.messagePage | ||
?.messages | ||
?.isEligibleToShowTheChatIcon() == true | ||
if (eligibleFromLegacyConversation) { | ||
return@either true | ||
} | ||
val conversations = data.currentMember.conversations | ||
val showChatIcon = conversations.any { conversation -> | ||
val isOpenConversation = conversation.isOpen | ||
val hasAnyMessageSent = conversation.newestMessage != null | ||
isOpenConversation || hasAnyMessageSent | ||
} | ||
showChatIcon | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Suppress("ktlint:standard:max-line-length") | ||
private fun List<CbmNumberOfChatMessagesQuery.Data.CurrentMember.LegacyConversation.MessagePage.Message>.isEligibleToShowTheChatIcon(): Boolean { | ||
// If there are *any* messages from the member, then we should show the chat icon | ||
if (this.any { it.sender == ChatMessageSender.MEMBER }) return true | ||
// There is always an automatic message sent by Hedvig, therefore we need to check for > 1 | ||
return this.filter { it.sender == ChatMessageSender.HEDVIG }.size > 1 | ||
} |
9 changes: 9 additions & 0 deletions
9
...tions/src/main/kotlin/com/hedvig/android/data/conversations/di/DataConversationsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hedvig.android.data.conversations.di | ||
|
||
import com.apollographql.apollo.ApolloClient | ||
import com.hedvig.android.data.conversations.HasAnyActiveConversationUseCase | ||
import org.koin.dsl.module | ||
|
||
val dataConversationsModule = module { | ||
single<HasAnyActiveConversationUseCase> { HasAnyActiveConversationUseCase(get<ApolloClient>()) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...help-center/src/main/kotlin/com/hedvig/android/feature/help/center/HelpCenterViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
package com.hedvig.android.feature.help.center | ||
|
||
import com.hedvig.android.data.conversations.HasAnyActiveConversationUseCase | ||
import com.hedvig.android.feature.help.center.data.GetQuickLinksUseCase | ||
import com.hedvig.android.feature.help.center.model.commonQuestions | ||
import com.hedvig.android.feature.help.center.model.commonTopics | ||
import com.hedvig.android.molecule.android.MoleculeViewModel | ||
|
||
internal class HelpCenterViewModel( | ||
getQuickLinksUseCase: GetQuickLinksUseCase, | ||
hasAnyActiveConversationUseCase: HasAnyActiveConversationUseCase, | ||
) : MoleculeViewModel<HelpCenterEvent, HelpCenterUiState>( | ||
initialState = HelpCenterUiState( | ||
topics = commonTopics, | ||
questions = commonQuestions, | ||
selectedQuickAction = null, | ||
quickLinksUiState = HelpCenterUiState.QuickLinkUiState.Loading, | ||
search = null, | ||
showNavigateToInboxButton = false, | ||
), | ||
presenter = HelpCenterPresenter( | ||
getQuickLinksUseCase = getQuickLinksUseCase, | ||
hasAnyActiveConversationUseCase = hasAnyActiveConversationUseCase, | ||
), | ||
) |
30 changes: 30 additions & 0 deletions
30
...er/src/main/kotlin/com/hedvig/android/feature/help/center/ShowNavigateToInboxViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.hedvig.android.feature.help.center | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import arrow.core.merge | ||
import com.hedvig.android.data.conversations.HasAnyActiveConversationUseCase | ||
import com.hedvig.android.molecule.android.MoleculeViewModel | ||
import com.hedvig.android.molecule.public.MoleculePresenter | ||
import com.hedvig.android.molecule.public.MoleculePresenterScope | ||
import kotlinx.coroutines.flow.map | ||
|
||
internal class ShowNavigateToInboxViewModel( | ||
hasAnyActiveConversationUseCase: HasAnyActiveConversationUseCase, | ||
) : MoleculeViewModel<Unit, Boolean>( | ||
false, | ||
ShowNavigateToInboxPresenter(hasAnyActiveConversationUseCase), | ||
) | ||
|
||
internal class ShowNavigateToInboxPresenter( | ||
private val hasAnyActiveConversationUseCase: HasAnyActiveConversationUseCase, | ||
) : MoleculePresenter<Unit, Boolean> { | ||
@Composable | ||
override fun MoleculePresenterScope<Unit>.present(lastState: Boolean): Boolean { | ||
return remember(hasAnyActiveConversationUseCase) { | ||
hasAnyActiveConversationUseCase.invoke().map { it.mapLeft { false }.merge() } | ||
}.collectAsState(lastState).value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.