mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 12:35:30 +03:00
convert rxjava to coroutines - set conversation read only
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
ab313adfd5
commit
452a4c72f4
12 changed files with 110 additions and 124 deletions
|
@ -142,8 +142,13 @@ interface NcApiCoroutines {
|
||||||
): GenericOverall
|
): GenericOverall
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
suspend fun clearChatHistory(
|
suspend fun clearChatHistory(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@PUT
|
||||||
|
suspend fun setConversationReadOnly(
|
||||||
@Header("Authorization") authorization: String,
|
@Header("Authorization") authorization: String,
|
||||||
@Url url: String
|
@Url url: String,
|
||||||
|
@Field("state") state: Int
|
||||||
): GenericOverall
|
): GenericOverall
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,13 +171,12 @@ class RenameConversationDialogFragment : DialogFragment() {
|
||||||
private fun setupStateObserver() {
|
private fun setupStateObserver() {
|
||||||
viewModel.renameRoomUiState.observe(viewLifecycleOwner) { state ->
|
viewModel.renameRoomUiState.observe(viewLifecycleOwner) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is ConversationInfoEditViewModel.RenameRoomUiState.None ->{
|
is ConversationInfoEditViewModel.RenameRoomUiState.None -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
is ConversationInfoEditViewModel.RenameRoomUiState.Success ->{
|
is ConversationInfoEditViewModel.RenameRoomUiState.Success -> {
|
||||||
handleSuccess()
|
handleSuccess()
|
||||||
}
|
}
|
||||||
is ConversationInfoEditViewModel.RenameRoomUiState.Error ->{
|
is ConversationInfoEditViewModel.RenameRoomUiState.Error -> {
|
||||||
showError()
|
showError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider:
|
||||||
val currentUser: User = currentUserProvider.currentUser.blockingGet()
|
val currentUser: User = currentUserProvider.currentUser.blockingGet()
|
||||||
val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)!!
|
val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)!!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun createConversation(
|
override fun createConversation(
|
||||||
roomName: String,
|
roomName: String,
|
||||||
conversationType: ConversationEnums.ConversationType?
|
conversationType: ConversationEnums.ConversationType?
|
||||||
|
|
|
@ -260,37 +260,33 @@ class ConversationInfoActivity :
|
||||||
|
|
||||||
viewModel.getConversationReadOnlyState.observe(this) { state ->
|
viewModel.getConversationReadOnlyState.observe(this) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
is ConversationInfoViewModel.SetConversationReadOnlySuccessState -> {
|
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Success -> {
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.SetConversationReadOnlyErrorState -> {
|
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Error -> {
|
||||||
Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
else -> {
|
is ConversationInfoViewModel.SetConversationReadOnlyViewState.None -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.clearChatHistoryViewState.observe(this){uiState ->
|
viewModel.clearChatHistoryViewState.observe(this) { uiState ->
|
||||||
when(uiState){
|
when (uiState) {
|
||||||
is ConversationInfoViewModel.ClearChatHistoryViewState.None ->{
|
is ConversationInfoViewModel.ClearChatHistoryViewState.None -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.ClearChatHistoryViewState.Success ->{
|
is ConversationInfoViewModel.ClearChatHistoryViewState.Success -> {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
binding.root,
|
binding.root,
|
||||||
context.getString(R.string.nc_clear_history_success),
|
context.getString(R.string.nc_clear_history_success),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
is ConversationInfoViewModel.ClearChatHistoryViewState.Error ->{
|
is ConversationInfoViewModel.ClearChatHistoryViewState.Error -> {
|
||||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||||
Log.e(TAG, "failed to clear chat history", uiState.exception)
|
Log.e(TAG, "failed to clear chat history", uiState.exception)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,7 +743,7 @@ class ConversationInfoActivity :
|
||||||
|
|
||||||
private fun clearHistory() {
|
private fun clearHistory() {
|
||||||
val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
|
val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))
|
||||||
viewModel.clearChatHistory(apiVersion,conversationToken)
|
viewModel.clearChatHistory(apiVersion, conversationToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteConversation() {
|
private fun deleteConversation() {
|
||||||
|
@ -842,7 +838,7 @@ class ConversationInfoActivity :
|
||||||
binding.lockConversationSwitch.isChecked = !isLocked
|
binding.lockConversationSwitch.isChecked = !isLocked
|
||||||
databaseStorageModule!!.saveBoolean("lock_switch", !isLocked)
|
databaseStorageModule!!.saveBoolean("lock_switch", !isLocked)
|
||||||
val state = if (isLocked) 0 else 1
|
val state = if (isLocked) 0 else 1
|
||||||
makeConversationReadOnly(conversationUser, conversationToken, state)
|
makeConversationReadOnly(conversationToken, state)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.lockConversation.visibility = GONE
|
binding.lockConversation.visibility = GONE
|
||||||
|
@ -922,8 +918,8 @@ class ConversationInfoActivity :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makeConversationReadOnly(conversationUser: User, roomToken: String, state: Int) {
|
private fun makeConversationReadOnly(roomToken: String, state: Int) {
|
||||||
viewModel.setConversationReadOnly(conversationUser, roomToken, state)
|
viewModel.setConversationReadOnly( roomToken, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initRecordingConsentOption() {
|
private fun initRecordingConsentOption() {
|
||||||
|
|
|
@ -18,11 +18,9 @@ import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.domain.ConversationModel
|
import com.nextcloud.talk.models.domain.ConversationModel
|
||||||
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||||
import com.nextcloud.talk.models.json.generic.GenericMeta
|
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||||
import com.nextcloud.talk.models.json.participants.TalkBan
|
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||||
import com.nextcloud.talk.repositories.conversations.ConversationsRepository
|
import com.nextcloud.talk.repositories.conversations.ConversationsRepository
|
||||||
import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK
|
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import io.reactivex.Observer
|
import io.reactivex.Observer
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
@ -81,13 +79,6 @@ class ConversationInfoViewModel @Inject constructor(
|
||||||
val getUnBanActorState: LiveData<ViewState>
|
val getUnBanActorState: LiveData<ViewState>
|
||||||
get() = _getUnBanActorState
|
get() = _getUnBanActorState
|
||||||
|
|
||||||
object SetConversationReadOnlySuccessState : ViewState
|
|
||||||
object SetConversationReadOnlyErrorState : ViewState
|
|
||||||
|
|
||||||
private val _getConversationReadOnlyState: MutableLiveData<ViewState> = MutableLiveData()
|
|
||||||
val getConversationReadOnlyState: LiveData<ViewState>
|
|
||||||
get() = _getConversationReadOnlyState
|
|
||||||
|
|
||||||
object GetRoomStartState : ViewState
|
object GetRoomStartState : ViewState
|
||||||
object GetRoomErrorState : ViewState
|
object GetRoomErrorState : ViewState
|
||||||
open class GetRoomSuccessState(val conversationModel: ConversationModel) : ViewState
|
open class GetRoomSuccessState(val conversationModel: ConversationModel) : ViewState
|
||||||
|
@ -112,10 +103,16 @@ class ConversationInfoViewModel @Inject constructor(
|
||||||
val getCapabilitiesViewState: LiveData<ViewState>
|
val getCapabilitiesViewState: LiveData<ViewState>
|
||||||
get() = _getCapabilitiesViewState
|
get() = _getCapabilitiesViewState
|
||||||
|
|
||||||
private val _clearChatHistoryViewState:MutableLiveData<ClearChatHistoryViewState> = MutableLiveData(ClearChatHistoryViewState.None)
|
private val _clearChatHistoryViewState: MutableLiveData<ClearChatHistoryViewState> =
|
||||||
val clearChatHistoryViewState:LiveData<ClearChatHistoryViewState>
|
MutableLiveData(ClearChatHistoryViewState.None)
|
||||||
|
val clearChatHistoryViewState: LiveData<ClearChatHistoryViewState>
|
||||||
get() = _clearChatHistoryViewState
|
get() = _clearChatHistoryViewState
|
||||||
|
|
||||||
|
private val _getConversationReadOnlyState: MutableLiveData<SetConversationReadOnlyViewState> =
|
||||||
|
MutableLiveData(SetConversationReadOnlyViewState.None)
|
||||||
|
val getConversationReadOnlyState: LiveData<SetConversationReadOnlyViewState>
|
||||||
|
get() = _getConversationReadOnlyState
|
||||||
|
|
||||||
fun getRoom(user: User, token: String) {
|
fun getRoom(user: User, token: String) {
|
||||||
_viewState.value = GetRoomStartState
|
_viewState.value = GetRoomStartState
|
||||||
chatNetworkDataSource.getRoom(user, token)
|
chatNetworkDataSource.getRoom(user, token)
|
||||||
|
@ -202,28 +199,15 @@ class ConversationInfoViewModel @Inject constructor(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setConversationReadOnly(user: User, token: String, state: Int) {
|
fun setConversationReadOnly(roomToken: String, state: Int) {
|
||||||
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
viewModelScope.launch {
|
||||||
val url = ApiUtils.getUrlForConversationReadOnly(apiVersion, user.baseUrl!!, token)
|
try {
|
||||||
conversationsRepository.setConversationReadOnly(user.getCredentials(), url, state)
|
conversationsRepository.setConversationReadOnly(roomToken, state)
|
||||||
.subscribeOn(Schedulers.io())
|
_getConversationReadOnlyState.value = SetConversationReadOnlyViewState.Success
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
} catch (exception: Exception) {
|
||||||
?.subscribe(object : Observer<GenericOverall> {
|
_getConversationReadOnlyState.value = SetConversationReadOnlyViewState.Error(exception)
|
||||||
override fun onSubscribe(p0: Disposable) {
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(error: Throwable) {
|
|
||||||
_getConversationReadOnlyState.value = SetConversationReadOnlyErrorState
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onComplete() {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNext(p0: GenericOverall) {
|
|
||||||
_getConversationReadOnlyState.value = SetConversationReadOnlySuccessState
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbanActor(user: User, token: String, banId: Int) {
|
fun unbanActor(user: User, token: String, banId: Int) {
|
||||||
|
@ -285,16 +269,12 @@ class ConversationInfoViewModel @Inject constructor(
|
||||||
conversationsRepository.unarchiveConversation(user.getCredentials(), url)
|
conversationsRepository.unarchiveConversation(user.getCredentials(), url)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearChatHistory(apiVersion:Int,roomToken:String){
|
fun clearChatHistory(apiVersion: Int, roomToken: String) {
|
||||||
viewModelScope.launch{
|
viewModelScope.launch {
|
||||||
try{
|
try {
|
||||||
val clearChatResult = conversationsRepository.clearChatHistory(apiVersion,roomToken)
|
conversationsRepository.clearChatHistory(apiVersion, roomToken)
|
||||||
val statusCode: GenericMeta? = clearChatResult.ocs?.meta
|
_clearChatHistoryViewState.value = ClearChatHistoryViewState.Success
|
||||||
val result = statusCode?.statusCode == STATUS_CODE_OK
|
} catch (exception: Exception) {
|
||||||
if (result) {
|
|
||||||
_clearChatHistoryViewState.value = ClearChatHistoryViewState.Success
|
|
||||||
}
|
|
||||||
}catch(exception:Exception){
|
|
||||||
_clearChatHistoryViewState.value = ClearChatHistoryViewState.Error(exception)
|
_clearChatHistoryViewState.value = ClearChatHistoryViewState.Error(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,10 +303,16 @@ class ConversationInfoViewModel @Inject constructor(
|
||||||
private val TAG = ConversationInfoViewModel::class.simpleName
|
private val TAG = ConversationInfoViewModel::class.simpleName
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ClearChatHistoryViewState{
|
sealed class ClearChatHistoryViewState {
|
||||||
data object None: ClearChatHistoryViewState()
|
data object None : ClearChatHistoryViewState()
|
||||||
data object Success:ClearChatHistoryViewState()
|
data object Success : ClearChatHistoryViewState()
|
||||||
data class Error(val exception:Exception):ClearChatHistoryViewState()
|
data class Error(val exception: Exception) : ClearChatHistoryViewState()
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class SetConversationReadOnlyViewState {
|
||||||
|
data object None : SetConversationReadOnlyViewState()
|
||||||
|
data object Success : SetConversationReadOnlyViewState()
|
||||||
|
data class Error(val exception: Exception) : SetConversationReadOnlyViewState()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class AllowGuestsUIState {
|
sealed class AllowGuestsUIState {
|
||||||
|
|
|
@ -167,19 +167,18 @@ class ConversationInfoEditActivity : BaseActivity() {
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conversationInfoEditViewModel.renameRoomUiState.observe(this){uiState ->
|
conversationInfoEditViewModel.renameRoomUiState.observe(this) { uiState ->
|
||||||
when(uiState){
|
when (uiState) {
|
||||||
is ConversationInfoEditViewModel.RenameRoomUiState.None ->{
|
is ConversationInfoEditViewModel.RenameRoomUiState.None -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
is ConversationInfoEditViewModel.RenameRoomUiState.Success ->{
|
is ConversationInfoEditViewModel.RenameRoomUiState.Success -> {
|
||||||
if (CapabilitiesUtil.isConversationDescriptionEndpointAvailable(spreedCapabilities)) {
|
if (CapabilitiesUtil.isConversationDescriptionEndpointAvailable(spreedCapabilities)) {
|
||||||
saveConversationDescription()
|
saveConversationDescription()
|
||||||
} else {
|
} else {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ConversationInfoEditViewModel.RenameRoomUiState.Error ->{
|
is ConversationInfoEditViewModel.RenameRoomUiState.Error -> {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
binding.root,
|
binding.root,
|
||||||
context.getString(R.string.default_error_msg),
|
context.getString(R.string.default_error_msg),
|
||||||
|
@ -190,27 +189,23 @@ class ConversationInfoEditActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conversationInfoEditViewModel.setConversationDescriptionUiState.observe(this){ uiState ->
|
conversationInfoEditViewModel.setConversationDescriptionUiState.observe(this) { uiState ->
|
||||||
when(uiState){
|
when (uiState) {
|
||||||
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.None ->{
|
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.None -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Success ->{
|
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Success -> {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Error ->{
|
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Error -> {
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
binding.root,
|
binding.root,
|
||||||
context.getString(R.string.default_error_msg),
|
context.getString(R.string.default_error_msg),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
Log.e(TAG, "Error while saving conversation description", uiState.exception)
|
Log.e(TAG, "Error while saving conversation description", uiState.exception)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAvatarOptions() {
|
private fun setupAvatarOptions() {
|
||||||
|
@ -276,14 +271,14 @@ class ConversationInfoEditActivity : BaseActivity() {
|
||||||
|
|
||||||
private fun saveConversationNameAndDescription() {
|
private fun saveConversationNameAndDescription() {
|
||||||
val newRoomName = binding.conversationName.text.toString()
|
val newRoomName = binding.conversationName.text.toString()
|
||||||
conversationInfoEditViewModel.renameRoom(
|
conversationInfoEditViewModel.renameRoom(
|
||||||
conversation!!.token,
|
conversation!!.token,
|
||||||
newRoomName
|
newRoomName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveConversationDescription() {
|
fun saveConversationDescription() {
|
||||||
val conversationDescription = binding.conversationDescription.text.toString()
|
val conversationDescription = binding.conversationDescription.text.toString()
|
||||||
conversationInfoEditViewModel.setConversationDescription(conversation!!.token, conversationDescription)
|
conversationInfoEditViewModel.setConversationDescription(conversation!!.token, conversationDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,5 +20,5 @@ interface ConversationInfoEditRepository {
|
||||||
|
|
||||||
suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall
|
suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall
|
||||||
|
|
||||||
suspend fun setConversationDescription(roomToken:String, conversationDescription:String?): GenericOverall
|
suspend fun setConversationDescription(roomToken: String, conversationDescription: String?): GenericOverall
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,11 @@ import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody.Companion.asRequestBody
|
import okhttp3.RequestBody.Companion.asRequestBody
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi,
|
class ConversationInfoEditRepositoryImpl(
|
||||||
|
private val ncApi: NcApi,
|
||||||
private val ncApiCoroutines: NcApiCoroutines,
|
private val ncApiCoroutines: NcApiCoroutines,
|
||||||
currentUserProvider: CurrentUserProviderNew) :
|
currentUserProvider: CurrentUserProviderNew
|
||||||
|
) :
|
||||||
ConversationInfoEditRepository {
|
ConversationInfoEditRepository {
|
||||||
|
|
||||||
val currentUser: User = currentUserProvider.currentUser.blockingGet()
|
val currentUser: User = currentUserProvider.currentUser.blockingGet()
|
||||||
|
|
|
@ -47,11 +47,12 @@ class ConversationInfoEditViewModel @Inject constructor(
|
||||||
get() = _viewState
|
get() = _viewState
|
||||||
|
|
||||||
private val _renameRoomUiState = MutableLiveData<RenameRoomUiState>(RenameRoomUiState.None)
|
private val _renameRoomUiState = MutableLiveData<RenameRoomUiState>(RenameRoomUiState.None)
|
||||||
val renameRoomUiState:LiveData<RenameRoomUiState>
|
val renameRoomUiState: LiveData<RenameRoomUiState>
|
||||||
get() = _renameRoomUiState
|
get() = _renameRoomUiState
|
||||||
|
|
||||||
private val _setConversationDescriptionUiState = MutableLiveData<SetConversationDescriptionUiState>(SetConversationDescriptionUiState.None)
|
private val _setConversationDescriptionUiState =
|
||||||
val setConversationDescriptionUiState:LiveData<SetConversationDescriptionUiState>
|
MutableLiveData<SetConversationDescriptionUiState>(SetConversationDescriptionUiState.None)
|
||||||
|
val setConversationDescriptionUiState: LiveData<SetConversationDescriptionUiState>
|
||||||
get() = _setConversationDescriptionUiState
|
get() = _setConversationDescriptionUiState
|
||||||
|
|
||||||
fun getRoom(user: User, token: String) {
|
fun getRoom(user: User, token: String) {
|
||||||
|
@ -76,31 +77,34 @@ class ConversationInfoEditViewModel @Inject constructor(
|
||||||
?.subscribe(DeleteConversationAvatarObserver())
|
?.subscribe(DeleteConversationAvatarObserver())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun renameRoom(roomToken:String, newRoomName:String){
|
fun renameRoom(roomToken: String, newRoomName: String) {
|
||||||
viewModelScope.launch{
|
viewModelScope.launch {
|
||||||
try{
|
try {
|
||||||
val renameRoomResult = conversationInfoEditRepository.renameConversation(roomToken, newRoomName)
|
val renameRoomResult = conversationInfoEditRepository.renameConversation(roomToken, newRoomName)
|
||||||
val statusCode:GenericMeta? = renameRoomResult.ocs?.meta
|
val statusCode: GenericMeta? = renameRoomResult.ocs?.meta
|
||||||
val result = statusCode?.statusCode == STATUS_CODE_OK
|
val result = statusCode?.statusCode == STATUS_CODE_OK
|
||||||
if(result){
|
if (result) {
|
||||||
_renameRoomUiState.value = RenameRoomUiState.Success(result)
|
_renameRoomUiState.value = RenameRoomUiState.Success(result)
|
||||||
}
|
}
|
||||||
}catch(exception:Exception){
|
} catch (exception: Exception) {
|
||||||
_renameRoomUiState.value = RenameRoomUiState.Error(exception)
|
_renameRoomUiState.value = RenameRoomUiState.Error(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setConversationDescription(roomToken:String, conversationDescription:String?){
|
fun setConversationDescription(roomToken: String, conversationDescription: String?) {
|
||||||
viewModelScope.launch{
|
viewModelScope.launch {
|
||||||
try{
|
try {
|
||||||
val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription(roomToken, conversationDescription)
|
val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription(
|
||||||
|
roomToken,
|
||||||
|
conversationDescription
|
||||||
|
)
|
||||||
val statusCode: GenericMeta? = setConversationDescriptionResult.ocs?.meta
|
val statusCode: GenericMeta? = setConversationDescriptionResult.ocs?.meta
|
||||||
val result = statusCode?.statusCode == STATUS_CODE_OK
|
val result = statusCode?.statusCode == STATUS_CODE_OK
|
||||||
if(result){
|
if (result) {
|
||||||
_setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success(result)
|
_setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success(result)
|
||||||
}
|
}
|
||||||
}catch(exception:Exception){
|
} catch (exception: Exception) {
|
||||||
_setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Error(exception)
|
_setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Error(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,15 +171,15 @@ class ConversationInfoEditViewModel @Inject constructor(
|
||||||
private val TAG = ConversationInfoEditViewModel::class.simpleName
|
private val TAG = ConversationInfoEditViewModel::class.simpleName
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class RenameRoomUiState{
|
sealed class RenameRoomUiState {
|
||||||
data object None: RenameRoomUiState()
|
data object None : RenameRoomUiState()
|
||||||
data class Success(val result:Boolean): RenameRoomUiState()
|
data class Success(val result: Boolean) : RenameRoomUiState()
|
||||||
data class Error(val exception:Exception): RenameRoomUiState()
|
data class Error(val exception: Exception) : RenameRoomUiState()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class SetConversationDescriptionUiState{
|
sealed class SetConversationDescriptionUiState {
|
||||||
data object None: SetConversationDescriptionUiState()
|
data object None : SetConversationDescriptionUiState()
|
||||||
data class Success(val result:Boolean):SetConversationDescriptionUiState()
|
data class Success(val result: Boolean) : SetConversationDescriptionUiState()
|
||||||
data class Error(val exception:Exception):SetConversationDescriptionUiState()
|
data class Error(val exception: Exception) : SetConversationDescriptionUiState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ class RepositoryModule {
|
||||||
ncApiCoroutines: NcApiCoroutines,
|
ncApiCoroutines: NcApiCoroutines,
|
||||||
userProvider: CurrentUserProviderNew
|
userProvider: CurrentUserProviderNew
|
||||||
): ConversationInfoEditRepository {
|
): ConversationInfoEditRepository {
|
||||||
return ConversationInfoEditRepositoryImpl(ncApi, ncApiCoroutines,userProvider)
|
return ConversationInfoEditRepositoryImpl(ncApi, ncApiCoroutines, userProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -25,7 +25,7 @@ interface ConversationsRepository {
|
||||||
|
|
||||||
suspend fun setPassword(password: String, token: String): GenericOverall
|
suspend fun setPassword(password: String, token: String): GenericOverall
|
||||||
|
|
||||||
fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable<GenericOverall>
|
suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall
|
||||||
|
|
||||||
suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall
|
suspend fun clearChatHistory(apiVersion: Int, roomToken: String): GenericOverall
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,10 @@ class ConversationsRepositoryImpl(
|
||||||
return coroutineApi.unarchiveConversation(credentials, url)
|
return coroutineApi.unarchiveConversation(credentials, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable<GenericOverall> {
|
override suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall {
|
||||||
return api.setConversationReadOnly(credentials, url, state)
|
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
||||||
|
val url = ApiUtils.getUrlForConversationReadOnly(apiVersion, user.baseUrl!!, roomToken)
|
||||||
|
return coroutineApi.setConversationReadOnly(credentials, url, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setPassword(password: String, token: String): GenericOverall {
|
override suspend fun setPassword(password: String, token: String): GenericOverall {
|
||||||
|
@ -91,7 +93,6 @@ class ConversationsRepositoryImpl(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun clearChatHistory(roomToken:String): GenericOverall {
|
|
||||||
override suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall {
|
override suspend fun clearChatHistory(apiVersion:Int,roomToken:String): GenericOverall {
|
||||||
return coroutineApi.clearChatHistory(
|
return coroutineApi.clearChatHistory(
|
||||||
credentials,
|
credentials,
|
||||||
|
|
Loading…
Reference in a new issue