-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unread archived conversations indicator [WPB-4437] (#2288)
- Loading branch information
Showing
9 changed files
with
229 additions
and
22 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
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
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/com/wire/android/ui/home/drawer/HomeDrawerState.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,23 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
* | ||
*/ | ||
|
||
package com.wire.android.ui.home.drawer | ||
|
||
data class HomeDrawerState(val unreadArchiveConversationsCount: Int) |
58 changes: 58 additions & 0 deletions
58
app/src/main/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModel.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,58 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
* | ||
*/ | ||
|
||
package com.wire.android.ui.home.drawer | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.viewModelScope | ||
import com.wire.android.navigation.SavedStateViewModel | ||
import com.wire.kalium.logic.feature.conversation.ObserveArchivedUnreadConversationsCountUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@Suppress("LongParameterList") | ||
@HiltViewModel | ||
class HomeDrawerViewModel @Inject constructor( | ||
override val savedStateHandle: SavedStateHandle, | ||
private val observeArchivedUnreadConversationsCountUseCase: ObserveArchivedUnreadConversationsCountUseCase, | ||
) : SavedStateViewModel(savedStateHandle) { | ||
|
||
var drawerState by mutableStateOf( | ||
HomeDrawerState( | ||
unreadArchiveConversationsCount = 0 | ||
) | ||
) | ||
private set | ||
|
||
init { | ||
observeUnreadArchiveConversationsCount() | ||
} | ||
|
||
private fun observeUnreadArchiveConversationsCount() { | ||
viewModelScope.launch { | ||
observeArchivedUnreadConversationsCountUseCase() | ||
.collect { drawerState = drawerState.copy(unreadArchiveConversationsCount = it.toInt()) } | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
app/src/test/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModelTest.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,77 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.home.drawer | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.wire.android.config.CoroutineTestExtension | ||
import com.wire.android.config.NavigationTestExtension | ||
import com.wire.kalium.logic.feature.conversation.ObserveArchivedUnreadConversationsCountUseCase | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.flow.consumeAsFlow | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.runTest | ||
import org.amshove.kluent.internal.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(CoroutineTestExtension::class) | ||
@ExtendWith(NavigationTestExtension::class) | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@ExtendWith(NavigationTestExtension::class) | ||
class HomeDrawerViewModelTest { | ||
|
||
@Test | ||
fun `given archivedUnreadConversationsCount, when starts observing, then returns correct integer value`() = runTest { | ||
// Given | ||
val unreadCount = 10L | ||
val (arrangement, viewModel) = Arrangement() | ||
.arrange() | ||
|
||
// When | ||
arrangement.unreadArchivedConversationsCountChannel.send(unreadCount) | ||
advanceUntilIdle() | ||
|
||
// Then | ||
assertEquals(unreadCount.toInt(), viewModel.drawerState.unreadArchiveConversationsCount) | ||
} | ||
|
||
private class Arrangement { | ||
|
||
@MockK | ||
lateinit var savedStateHandle: SavedStateHandle | ||
|
||
@MockK | ||
lateinit var observeArchivedUnreadConversationsCount: ObserveArchivedUnreadConversationsCountUseCase | ||
|
||
val unreadArchivedConversationsCountChannel = Channel<Long>(capacity = Channel.UNLIMITED) | ||
|
||
init { | ||
MockKAnnotations.init(this, relaxUnitFun = true) | ||
coEvery { observeArchivedUnreadConversationsCount() } returns unreadArchivedConversationsCountChannel.consumeAsFlow() | ||
} | ||
|
||
fun arrange() = this to HomeDrawerViewModel( | ||
savedStateHandle, | ||
observeArchivedUnreadConversationsCount | ||
) | ||
} | ||
} |
Submodule kalium
updated
9 files