Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.dscvit.vitty.network.api.community.responses.user

data class ActiveFriendResponse(
val data: List<String>?,
val data: List<ActiveFriendItem>?,
)

data class ActiveFriendItem(
val friend_username: String?,
val hide: Boolean?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fun ConnectScreenContent(
val username = sharedPreferences.getString(Constants.COMMUNITY_USERNAME, "") ?: ""

if (token.isNotEmpty()) {
connectViewModel.fetchActiveFriends(token, prefs = sharedPreferences)
connectViewModel.refreshFriendList(token, username)
connectViewModel.getFriendRequest(token)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.dscvit.vitty.network.api.community.responses.circle.CircleRequestsRes
import com.dscvit.vitty.network.api.community.responses.circle.CreateCircleResponse
import com.dscvit.vitty.network.api.community.responses.circle.JoinCircleResponse
import com.dscvit.vitty.network.api.community.responses.requests.RequestsResponse
import com.dscvit.vitty.network.api.community.responses.user.ActiveFriendItem
import com.dscvit.vitty.network.api.community.responses.user.ActiveFriendResponse
import com.dscvit.vitty.network.api.community.responses.user.CircleResponse
import com.dscvit.vitty.network.api.community.responses.user.FriendResponse
Expand Down Expand Up @@ -48,7 +49,7 @@ class ConnectViewModel : ViewModel() {
private val _sentCircleRequests = MutableLiveData<CircleRequestsResponse?>()
private val _isCircleRequestsLoading = MutableLiveData<Boolean>()
private val _circleActionResponse = MutableLiveData<PostResponse?>()
private val _activeFriends = MutableLiveData<List<String>??>()
private val _activeFriends = MutableLiveData<List<ActiveFriendItem>??>()
private val _ghostModeResponse = MutableLiveData<GhostModeResponse?>()

val ghostModeResponse: MutableLiveData<GhostModeResponse?> = _ghostModeResponse
Expand All @@ -71,7 +72,7 @@ class ConnectViewModel : ViewModel() {
val sentCircleRequests: MutableLiveData<CircleRequestsResponse?> = _sentCircleRequests
val isCircleRequestsLoading: MutableLiveData<Boolean> = _isCircleRequestsLoading
val circleActionResponse: MutableLiveData<PostResponse?> = _circleActionResponse
val activeFriends: MutableLiveData<List<String>??> = _activeFriends
val activeFriends: MutableLiveData<List<ActiveFriendItem>??> = _activeFriends

fun getFriendList(
token: String,
Expand Down Expand Up @@ -774,7 +775,7 @@ class ConnectViewModel : ViewModel() {
_ghostModeResponse.postValue(null)
}

fun updateActiveFriendsList(data: List<String>?) {
fun updateActiveFriendsList(data: List<ActiveFriendItem>?) {
_activeFriends.postValue(data)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import coil.compose.AsyncImage
import com.dscvit.vitty.R
import com.dscvit.vitty.model.PeriodDetails
import com.dscvit.vitty.network.api.community.responses.timetable.TimetableResponse
import com.dscvit.vitty.network.api.community.responses.user.ActiveFriendItem
import com.dscvit.vitty.network.api.community.responses.user.UserResponse
import com.dscvit.vitty.theme.Accent
import com.dscvit.vitty.theme.Background
Expand Down Expand Up @@ -119,7 +120,10 @@ fun FriendDetailScreenContent(

LaunchedEffect(activeFriends) {
Timber.d("Active friends: $activeFriends")
activeFriends?.let { activeList -> isFriendGhosted = !activeList.contains(friend.username) }
activeFriends?.let { activeList ->
val friendItem = activeList.find { it.friend_username == friend.username }
isFriendGhosted = friendItem?.hide ?: false
}
}

LaunchedEffect(ghostModeResponse) {
Expand All @@ -130,15 +134,16 @@ fun FriendDetailScreenContent(
context.getSharedPreferences(Constants.USER_INFO, Context.MODE_PRIVATE)

if (ghostModeResponse!!.success) {
val currentActiveFriends = activeFriends?.toMutableList() ?: mutableListOf()
val currentActiveFriends = activeFriends?.toMutableList() ?: mutableListOf<ActiveFriendItem>()
val gson = Gson()

if (isFriendGhosted) {
currentActiveFriends.removeAll { it == friend.username }
val existingFriendIndex = currentActiveFriends.indexOfFirst { it.friend_username == friend.username }

if (existingFriendIndex != -1) {
currentActiveFriends[existingFriendIndex] =
currentActiveFriends[existingFriendIndex].copy(hide = isFriendGhosted)
} else {
if (!currentActiveFriends.contains(friend.username)) {
currentActiveFriends.add(friend.username)
}
currentActiveFriends.add(ActiveFriendItem(friend_username = friend.username, hide = isFriendGhosted))
}

val activeFriendsJson = gson.toJson(currentActiveFriends)
Expand Down
Loading
Loading