retain conversation successfully

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2025-05-19 19:59:38 +02:00 committed by Marcel Hibbe
parent 1ed89b2a53
commit 01b80a0753
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 62 additions and 9 deletions

View File

@ -258,4 +258,7 @@ interface NcApiCoroutines {
@GET @GET
suspend fun getProfile(@Header("Authorization") authorization: String, @Url url: String): ProfileOverall suspend fun getProfile(@Header("Authorization") authorization: String, @Url url: String): ProfileOverall
@DELETE
suspend fun unbindRoom(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
} }

View File

@ -1073,6 +1073,27 @@ class ChatActivity :
binding.voiceRecordingLock.y -= y binding.voiceRecordingLock.y -= y
} }
chatViewModel.unbindRoomResult.observe(this) { uiState ->
when (uiState) {
is ChatViewModel.UnbindRoomUiState.Success -> {
binding.conversationDeleteNotice.visibility = View.GONE
Snackbar.make(
binding.root,
context.getString(R.string.nc_room_retention),
Snackbar.LENGTH_LONG
).show()
}
is ChatViewModel.UnbindRoomUiState.Error -> {
Snackbar.make(
binding.root,
context.getString(R.string.nc_common_error_sorry),
Snackbar.LENGTH_LONG
).show()
}
else -> { }
}
}
chatViewModel.outOfOfficeViewState.observe(this) { uiState -> chatViewModel.outOfOfficeViewState.observe(this) { uiState ->
when (uiState) { when (uiState) {
is ChatViewModel.OutOfOfficeUIState.Error -> { is ChatViewModel.OutOfOfficeUIState.Error -> {
@ -1207,13 +1228,11 @@ class ChatActivity :
} }
binding.conversationDeleteNotice.findViewById<MaterialButton>(R.id.keep_button).setOnClickListener { binding.conversationDeleteNotice.findViewById<MaterialButton>(R.id.keep_button).setOnClickListener {
chatViewModel.unbindRoom(credentials!!, conversationUser?.baseUrl!!, currentConversation?.token!!)
} }
} }
fun deleteConversationDialog(context: Context) { fun deleteConversationDialog(context: Context) {
val dialogBuilder = MaterialAlertDialogBuilder(context) val dialogBuilder = MaterialAlertDialogBuilder(context)
.setIcon( .setIcon(
viewThemeUtils.dialog viewThemeUtils.dialog
@ -1236,7 +1255,6 @@ class ChatActivity :
dialog.getButton(AlertDialog.BUTTON_POSITIVE), dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE) dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
) )
} }
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught")

View File

@ -76,4 +76,5 @@ interface ChatNetworkDataSource {
limit: Int limit: Int
): List<ChatMessageJson> ): List<ChatMessageJson>
suspend fun getOpenGraph(credentials: String, baseUrl: String, extractedLinkToPreview: String): Reference? suspend fun getOpenGraph(credentials: String, baseUrl: String, extractedLinkToPreview: String): Reference?
suspend fun unbindRoom(credentials: String, baseUrl: String, roomToken: String): GenericOverall
} }

View File

@ -217,4 +217,9 @@ class RetrofitChatNetwork(
extractedLinkToPreview extractedLinkToPreview
).blockingFirst().ocs?.data?.references?.entries?.iterator()?.next()?.value ).blockingFirst().ocs?.data?.references?.entries?.iterator()?.next()?.value
} }
override suspend fun unbindRoom(credentials: String, baseUrl: String, roomToken: String): GenericOverall {
val url = ApiUtils.getUrlForUnbindingRoom(baseUrl, roomToken)
return ncApiCoroutines.unbindRoom(credentials, url)
}
} }

View File

@ -146,6 +146,10 @@ class ChatViewModel @Inject constructor(
val outOfOfficeViewState: LiveData<OutOfOfficeUIState> val outOfOfficeViewState: LiveData<OutOfOfficeUIState>
get() = _outOfOfficeViewState get() = _outOfOfficeViewState
private val _unbindRoomResult = MutableLiveData<UnbindRoomUiState>(UnbindRoomUiState.None)
val unbindRoomResult: LiveData<UnbindRoomUiState>
get() = _unbindRoomResult
private val _voiceMessagePlaybackSpeedPreferences: MutableLiveData<Map<String, PlaybackSpeed>> = MutableLiveData() private val _voiceMessagePlaybackSpeedPreferences: MutableLiveData<Map<String, PlaybackSpeed>> = MutableLiveData()
val voiceMessagePlaybackSpeedPreferences: LiveData<Map<String, PlaybackSpeed>> val voiceMessagePlaybackSpeedPreferences: LiveData<Map<String, PlaybackSpeed>>
get() = _voiceMessagePlaybackSpeedPreferences get() = _voiceMessagePlaybackSpeedPreferences
@ -804,6 +808,17 @@ class ChatViewModel @Inject constructor(
} }
} }
fun unbindRoom(credentials: String, baseUrl: String, roomToken: String) {
viewModelScope.launch {
try {
val response = chatNetworkDataSource.unbindRoom(credentials, baseUrl, roomToken)
_unbindRoomResult.value = UnbindRoomUiState.Success(response.ocs?.meta?.statusCode!!)
} catch (exception: Exception) {
_unbindRoomResult.value = UnbindRoomUiState.Error(exception.message.toString())
}
}
}
fun resendMessage(credentials: String, urlForChat: String, message: ChatMessage) { fun resendMessage(credentials: String, urlForChat: String, message: ChatMessage) {
viewModelScope.launch { viewModelScope.launch {
chatRepository.resendChatMessage( chatRepository.resendChatMessage(
@ -855,4 +870,10 @@ class ChatViewModel @Inject constructor(
data class Success(val userAbsence: UserAbsenceData) : OutOfOfficeUIState() data class Success(val userAbsence: UserAbsenceData) : OutOfOfficeUIState()
data class Error(val exception: Exception) : OutOfOfficeUIState() data class Error(val exception: Exception) : OutOfOfficeUIState()
} }
sealed class UnbindRoomUiState {
data object None : UnbindRoomUiState()
data class Success(val statusCode: Int) : UnbindRoomUiState()
data class Error(val message: String) : UnbindRoomUiState()
}
} }

View File

@ -449,6 +449,10 @@ object ApiUtils {
return "$baseUrl$OCS_API_VERSION/cloud/users/search/by-phone" return "$baseUrl$OCS_API_VERSION/cloud/users/search/by-phone"
} }
fun getUrlForUnbindingRoom(baseUrl: String, roomToken: String): String {
return "$baseUrl/ocs/v2.php/apps/spreed/api/v4/room/$roomToken/object"
}
fun getUrlForFileUpload(baseUrl: String, user: String, remotePath: String): String { fun getUrlForFileUpload(baseUrl: String, user: String, remotePath: String): String {
return "$baseUrl/remote.php/dav/files/$user$remotePath" return "$baseUrl/remote.php/dav/files/$user$remotePath"
} }

View File

@ -521,6 +521,7 @@ How to translate with transifex:
leaked to other services</string> leaked to other services</string>
<string name="startCallForbidden">You are not allowed to start a call</string> <string name="startCallForbidden">You are not allowed to start a call</string>
<string name="nc_last_moderator_leaving_room_warning">You need to promote a new moderator before you can leave the conversation</string> <string name="nc_last_moderator_leaving_room_warning">You need to promote a new moderator before you can leave the conversation</string>
<string name="nc_room_retention">Room was retained successfully</string>
<string name="share">Share</string> <string name="share">Share</string>
<string name="send_to">Send to</string> <string name="send_to">Send to</string>