fix online friends & pagination

This commit is contained in:
2024-12-04 18:57:14 +03:00
parent 65ed990726
commit d7e8c0dd35
4 changed files with 14 additions and 10 deletions
@@ -36,7 +36,7 @@ class FriendsRepositoryImpl(
val onlineFriends = async { getOnlineFriends(count, offset) }.await() val onlineFriends = async { getOnlineFriends(count, offset) }.await()
.successOrElse { failure -> .successOrElse { failure ->
return@withContext failure return@withContext failure
}.mapNotNull { userId -> friends.find { it.id == userId } } }
ApiResult.success(FriendsInfo(friends, onlineFriends)) ApiResult.success(FriendsInfo(friends, onlineFriends))
} }
@@ -4,5 +4,5 @@ import dev.meloda.fast.model.api.domain.VkUser
data class FriendsInfo( data class FriendsInfo(
val friends: List<VkUser>, val friends: List<VkUser>,
val onlineFriends: List<VkUser> val onlineFriendsIds: List<Int>
) )
@@ -67,7 +67,7 @@ class FriendsViewModelImpl(
} }
private fun loadFriends(offset: Int = currentOffset.value) { private fun loadFriends(offset: Int = currentOffset.value) {
friendsUseCase.getAllFriends(count = LOAD_COUNT, offset = offset) friendsUseCase.getFriends(count = LOAD_COUNT, offset = offset)
.listenValue(viewModelScope) { state -> .listenValue(viewModelScope) { state ->
state.processState( state.processState(
error = { error -> error = { error ->
@@ -81,8 +81,7 @@ class FriendsViewModelImpl(
} }
} }
}, },
success = { info -> success = { response ->
val response = info.friends
val itemsCountSufficient = response.size == LOAD_COUNT val itemsCountSufficient = response.size == LOAD_COUNT
canPaginate.setValue { itemsCountSufficient } canPaginate.setValue { itemsCountSufficient }
@@ -98,8 +97,9 @@ class FriendsViewModelImpl(
val loadedFriends = response.map { val loadedFriends = response.map {
it.asPresentation(userSettings.useContactNames.value) it.asPresentation(userSettings.useContactNames.value)
} }
val loadedOnlineFriends = info.onlineFriends.map {
it.asPresentation(userSettings.useContactNames.value) val loadedOnlineFriends = loadedFriends.filter {
it.onlineStatus.isOnline()
} }
val newState = screenState.value.copy( val newState = screenState.value.copy(
@@ -156,6 +156,6 @@ class FriendsViewModelImpl(
} }
companion object { companion object {
const val LOAD_COUNT = 60 const val LOAD_COUNT = 15
} }
} }
@@ -135,7 +135,7 @@ fun FriendsScreen(
val listState = rememberLazyListState() val listState = rememberLazyListState()
val paginationConditionMet by remember { val paginationConditionMet by remember(canPaginate, listState) {
derivedStateOf { derivedStateOf {
canPaginate && canPaginate &&
(listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index (listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index
@@ -300,7 +300,11 @@ fun FriendsScreen(
) )
} }
) { ) {
val friendsToDisplay = screenState.friends val friendsToDisplay = if (index == 0) {
screenState.friends
} else {
screenState.onlineFriends
}
FriendsList( FriendsList(
modifier = if (currentTheme.enableBlur) { modifier = if (currentTheme.enableBlur) {