auth to server-V73

This commit is contained in:
Eric85710 2026-05-08 17:03:57 +08:00
parent bca3cc9588
commit b1d892f8f4
3 changed files with 29 additions and 13 deletions

View file

@ -55,12 +55,14 @@ interface TecnologiaApi {
suspend fun getFriendsPending(): PendingFriendsResponse
//accept and reject
@POST("api/friends/{id}/accept")
// accept and reject
@POST("api/friends/{fromUserId}/accept")
suspend fun acceptFriendRequest(
@Path("id") friendshipId: String
@Path("fromUserId") fromUserId: String
): Response<Unit>
@POST("api/friends/{id}/reject")
@POST("api/friends/{fromUserId}/reject")
suspend fun rejectFriendRequest(
@Path("id") friendshipId: String
@Path("fromUserId") fromUserId: String
): Response<Unit>
}

View file

@ -84,8 +84,13 @@ fun Message_contact_list(
items(uiState.pendingRequests) { request ->
PendingFriendRow(
request,
onAccept = { id -> contactListViewModel.acceptFriend(id) },
onReject = { id -> /* 實作邏輯同 accept */ }
isLoading = uiState.isLoading,
onAccept = { _ ->
request.fromUserId?.let { id -> contactListViewModel.acceptFriend(id) }
},
onReject = { _ ->
request.fromUserId?.let { id -> contactListViewModel.rejectFriend(id) }
}
)
}
item { HorizontalDivider(modifier = Modifier.padding(vertical = 12.dp)) }
@ -158,6 +163,7 @@ fun FriendRow(friend: Friend) {
@Composable
fun PendingFriendRow(
request: PendingFriendApiModel,
isLoading: Boolean,
onAccept: (String) -> Unit, // 增加回呼
onReject: (String) -> Unit // 增加回呼
) {
@ -175,14 +181,16 @@ fun PendingFriendRow(
},
trailingContent = {
Row {
IconButton(onClick = {
request.friendshipId?.let { onReject(it) }
}) {
IconButton(
onClick = { request.friendshipId?.let { onReject(it) } },
enabled = !isLoading // 正在載入時禁用
) {
Icon(Icons.Default.Close, contentDescription = "拒絕", tint = Color.Red)
}
IconButton(onClick = {
request.friendshipId?.let { onAccept(it) }
}) {
IconButton(
onClick = { request.friendshipId?.let { onAccept(it) } },
enabled = !isLoading // 正在載入時禁用
) {
Icon(Icons.Default.Check, contentDescription = "接受", tint = Color.Green)
}
}

View file

@ -58,7 +58,10 @@ class ContactListViewModel @Inject constructor(
//accept and reject
fun acceptFriend(friendshipId: String) {
viewModelScope.launch {
// 這裡可以選擇性開啟 loading
//loading
_uiState.update { it.copy(isLoading = true) }
val result = repository.acceptFriendRequest(friendshipId)
result.onSuccess {
@ -72,6 +75,9 @@ class ContactListViewModel @Inject constructor(
}
fun rejectFriend(friendshipId: String) {
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true) }
val result = repository.rejectFriendRequest(friendshipId)
result.onSuccess {