Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-03-21 16:52:43 +01:00
parent f40f311ed3
commit f3ec53c445
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
4 changed files with 55 additions and 29 deletions

View File

@ -39,7 +39,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
buildToolsVersion '29.0.3'
defaultConfig {
applicationId "com.nextcloud.talk2"
versionName version
@ -47,7 +47,7 @@ android {
targetSdkVersion 29
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionCode 130
versionCode 132
versionName "9.0.0alpha1"
flavorDimensions "default"

View File

@ -42,6 +42,7 @@ import com.nextcloud.talk.newarch.features.contactsflow.ContactsViewOperationSta
import com.nextcloud.talk.newarch.features.contactsflow.ContactsViewOperationStateWrapper
import com.nextcloud.talk.newarch.features.contactsflow.ParticipantElement
import com.nextcloud.talk.newarch.features.conversationslist.ConversationsListView
import com.nextcloud.talk.newarch.local.models.canUserCreateGroupConversations
import com.nextcloud.talk.newarch.services.GlobalService
import kotlinx.coroutines.runBlocking
import org.koin.core.parameter.parametersOf
@ -137,41 +138,44 @@ class ContactsViewModel constructor(
private fun loadContacts() {
val searchQuery: String = if (filterMutableLiveData.value.isNullOrBlank()) "" else filterMutableLiveData.value.toString()
getContactsUseCase.invoke(viewModelScope, parametersOf(globalService.currentUserLiveData.value, groupConversation, searchQuery, conversationToken), object :
UseCaseResponse<List<Participant>> {
override suspend fun onSuccess(result: List<Participant>) {
val sortPriority = mapOf("users" to 0, "groups" to 1, "emails" to 2, "circles" to 3)
val user = globalService.currentUserLiveData.value
user?.let { operationUser ->
getContactsUseCase.invoke(viewModelScope, parametersOf(operationUser, groupConversation, searchQuery, conversationToken), object :
UseCaseResponse<List<Participant>> {
override suspend fun onSuccess(result: List<Participant>) {
val sortPriority = mapOf("users" to 0, "groups" to 1, "emails" to 2, "circles" to 3)
val sortedList = result.sortedWith(compareBy({
sortPriority[it.source]
}, {
it.displayName!!.toLowerCase()
}))
val sortedList = result.sortedWith(compareBy({
sortPriority[it.source]
}, {
it.displayName!!.toLowerCase()
}))
val selectedUserIds = selectedParticipants.map { (it.data as Participant).userId }
val selectedUserIds = selectedParticipants.map { (it.data as Participant).userId }
val participantElementsList: MutableList<ParticipantElement> = sortedList.map {
if (it.userId in selectedUserIds) {
it.selected = true
val participantElementsList: MutableList<ParticipantElement> = sortedList.map {
if (it.userId in selectedUserIds) {
it.selected = true
}
ParticipantElement(it, ParticipantElementType.PARTICIPANT.ordinal)
} as MutableList<ParticipantElement>
if (operationUser.canUserCreateGroupConversations() && conversationToken.isNullOrEmpty() && filterLiveData.value.isNullOrEmpty()) {
val newGroupElement = ParticipantElement(Pair(context.getString(R.string.nc_new_group), R.drawable.ic_people_group_white_24px), ParticipantElementType.PARTICIPANT_NEW_GROUP.ordinal)
participantElementsList.add(0, newGroupElement)
}
ParticipantElement(it, ParticipantElementType.PARTICIPANT.ordinal)
} as MutableList<ParticipantElement>
if (conversationToken.isNullOrEmpty() && filterLiveData.value.isNullOrEmpty()) {
val newGroupElement = ParticipantElement(Pair(context.getString(R.string.nc_new_group), R.drawable.ic_people_group_white_24px), ParticipantElementType.PARTICIPANT_NEW_GROUP.ordinal)
participantElementsList.add(0, newGroupElement)
_contacts.postValue(participantElementsList)
}
_contacts.postValue(participantElementsList)
}
override suspend fun onError(errorModel: ErrorModel?) {
_operationState.postValue(ContactsViewOperationStateWrapper(ContactsViewOperationState.LOADING_FAILED, errorModel?.getErrorMessage(), conversationToken))
override suspend fun onError(errorModel: ErrorModel?) {
_operationState.postValue(ContactsViewOperationStateWrapper(ContactsViewOperationState.LOADING_FAILED, errorModel?.getErrorMessage(), conversationToken))
}
})
}
})
}
}
}

View File

@ -29,6 +29,20 @@ fun User.getMaxMessageLength(): Int {
return capabilities?.spreedCapability?.config?.get("chat")?.get("max-length")?.toInt() ?: 1000
}
fun User.getAttachmentsConfig(key: String): Any? {
return capabilities?.spreedCapability?.config?.get("attachments")?.get(key)
}
fun User.canUserCreateGroupConversations(): Boolean {
val canCreateValue = capabilities?.spreedCapability?.config?.get("conversations")?.get("can-create")
canCreateValue?.let {
return it.toBoolean()
}
return true
}
fun User.getCredentials(): String = ApiUtils.getCredentials(username, token)
fun User.hasSpreedFeatureCapability(capabilityName: String): Boolean {

View File

@ -86,6 +86,14 @@ data class UserNgEntity(
}
}
fun UserNgEntity.canUserCreateGroupConversations(): Boolean {
val canCreateValue = capabilities?.spreedCapability?.config?.get("conversations")?.get("can-create")
canCreateValue?.let {
return it.toBoolean()
}
return true
}
fun UserNgEntity.toUser(): User {
return User(this.id, this.userId, this.username, this.baseUrl, this.token, this.displayName, this.pushConfiguration, this.capabilities, this.clientCertificate, this.signalingSettings, this.status)
}