Skip to content

Commit

Permalink
add participants endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <[email protected]>
  • Loading branch information
sowjanyakch committed Aug 13, 2024
1 parent a4038e8 commit abf6d85
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 114 deletions.
8 changes: 8 additions & 0 deletions app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.nextcloud.talk.api
import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
Expand Down Expand Up @@ -65,4 +66,11 @@ interface NcApiCoroutines {
@Url url: String,
@Field("description") description: String?
): GenericOverall

@POST
fun addParticipant(
@Header("Authorization") authorization: String?,
@Url url: String?,
@QueryMap options: Map<String, String>?
): AddParticipantOverall
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class ContactsActivityCompose : BaseActivity() {
listOf(
ShareType.Group.shareType,
ShareType.Email.shareType,
ShareType
.Circle.shareType
ShareType.Circle.shareType
)
)
contactsViewModel.getContactsFromSearchParams()
Expand Down Expand Up @@ -123,9 +122,9 @@ fun ContactItemRow(
contact: AutocompleteUser,
contactsViewModel: ContactsViewModel,
context: Context,
selectedContacts: MutableList<String>
selectedContacts: MutableList<AutocompleteUser>
) {
val isSelected = contact.id?.let { it in selectedContacts } ?: false
val isSelected = contact in selectedContacts
val roomUiState by contactsViewModel.roomViewState.collectAsState()
val isAddParticipants = contactsViewModel.isAddParticipantsView.value
Row(
Expand All @@ -141,10 +140,11 @@ fun ContactItemRow(
)
} else {
if (isSelected) {
selectedContacts.remove(contact.id!!)
selectedContacts.remove(contact)
} else {
selectedContacts.add(contact.id!!)
selectedContacts.add(contact)
}
contactsViewModel.updateSelectedParticipants(selectedContacts)
}
},
verticalAlignment = Alignment.CenterVertically
Expand Down Expand Up @@ -200,7 +200,6 @@ fun AppBar(title: String, context: Context, contactsViewModel: ContactsViewModel

TopAppBar(
title = { Text(text = title) },

navigationIcon = {
IconButton(onClick = {
(context as? Activity)?.finish()
Expand Down Expand Up @@ -304,8 +303,6 @@ fun ConversationCreationOptions(context: Context, contactsViewModel: ContactsVie
}
}



class CompanionClass {
companion object {
internal val TAG = ContactsActivityCompose::class.simpleName
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ package com.nextcloud.talk.contacts

import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall

interface ContactsRepository {
suspend fun getContacts(searchQuery: String?, shareTypes: List<String>): AutocompleteOverall
suspend fun createRoom(roomType: String, sourceType: String, userId: String, conversationName: String?): RoomOverall
fun getImageUri(avatarId: String, requestBigSize: Boolean): String
suspend fun addParticipants(conversationToken: String, userId: String, sourceType: String): AddParticipantOverall
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.RetrofitBucket
import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.ApiUtils.getRetrofitBucketForAddParticipant
import com.nextcloud.talk.utils.ApiUtils.getRetrofitBucketForAddParticipantWithSource
import com.nextcloud.talk.utils.ContactUtils

class ContactsRepositoryImpl(
Expand Down Expand Up @@ -72,4 +75,28 @@ class ContactsRepositoryImpl(
requestBigSize
)
}

override suspend fun addParticipants(
conversationToken: String,
userId: String,
sourceType: String
): AddParticipantOverall {
val retrofitBucket: RetrofitBucket = if (sourceType == "users") {
getRetrofitBucketForAddParticipant(
apiVersion,
_currentUser.baseUrl,
conversationToken,
userId
)
} else {
getRetrofitBucketForAddParticipantWithSource(
apiVersion,
_currentUser.baseUrl,
conversationToken,
sourceType,
userId
)
}
return ncApiCoroutines.addParticipant(credentials, retrofitBucket.url, retrofitBucket.queryMap)
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/nextcloud/talk/contacts/ContactsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ContactsViewModel @Inject constructor(
val contactsViewState: StateFlow<ContactsUiState> = _contactsViewState
private val _roomViewState = MutableStateFlow<RoomUiState>(RoomUiState.None)
val roomViewState: StateFlow<RoomUiState> = _roomViewState
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
private val _searchQuery = MutableStateFlow("")
val searchQuery: StateFlow<String> = _searchQuery
private val shareTypes: MutableList<String> = mutableListOf(ShareType.User.shareType)
Expand All @@ -32,6 +34,8 @@ class ContactsViewModel @Inject constructor(
val searchState: StateFlow<Boolean> = _searchState
private val _isAddParticipantsView = MutableStateFlow(false)
val isAddParticipantsView: StateFlow<Boolean> = _isAddParticipantsView
private val selectedParticipants = mutableListOf<AutocompleteUser>()
val selectedParticipantsList: List<AutocompleteUser> = selectedParticipants

init {
getContactsFromSearchParams()
Expand All @@ -41,6 +45,9 @@ class ContactsViewModel @Inject constructor(
_searchQuery.value = query
}

fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
selectedParticipants.addAll(participants)
}
fun updateSearchState(searchState: Boolean) {
_searchState.value = searchState
}
Expand Down Expand Up @@ -89,6 +96,17 @@ class ContactsViewModel @Inject constructor(
fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
return repository.getImageUri(avatarId, requestBigSize)
}
fun addParticipants(conversationToken: String, userId: String, sourceType: String) {
viewModelScope.launch {
try {
val participantsOverall = repository.addParticipants(conversationToken, userId, sourceType)
val participants = participantsOverall.ocs?.data
addParticipantsViewState.value = AddParticipantsUiState.Success(participants)
} catch (exception: Exception) {
addParticipantsViewState.value = AddParticipantsUiState.Error(exception.message ?: "")
}
}
}
}

sealed class ContactsUiState {
Expand All @@ -103,3 +121,9 @@ sealed class RoomUiState {
data class Success(val conversation: Conversation?) : RoomUiState()
data class Error(val message: String) : RoomUiState()
}

sealed class AddParticipantsUiState() {
data object None : AddParticipantsUiState()
data class Success(val participants: List<Conversation>?) : AddParticipantsUiState()
data class Error(val message: String) : AddParticipantsUiState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fun ContactsItem(contacts: List<AutocompleteUser>, contactsViewModel: ContactsVi
}
).toString()
}
val selectedContacts = remember { mutableStateListOf<String>() }
val selectedContacts = remember { mutableStateListOf<AutocompleteUser>() }
LazyColumn(
modifier = Modifier
.padding(8.dp)
Expand Down

0 comments on commit abf6d85

Please sign in to comment.