mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-24 05:55:39 +03:00
set conversation read only
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
956f2c435b
commit
50569a09af
8 changed files with 79 additions and 4 deletions
|
@ -256,6 +256,18 @@ class ConversationInfoActivity :
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.getConversationReadOnlyState.observe(this) { state ->
|
||||||
|
when (state) {
|
||||||
|
is ConversationInfoViewModel.SetConversationReadOnlySuccessState -> {
|
||||||
|
}
|
||||||
|
is ConversationInfoViewModel.SetConversationReadOnlyErrorState -> {
|
||||||
|
Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupActionBar() {
|
private fun setupActionBar() {
|
||||||
|
@ -658,6 +670,7 @@ class ConversationInfoActivity :
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkInfo.State.FAILED -> {
|
WorkInfo.State.FAILED -> {
|
||||||
val errorType = workInfo.outputData.getString("error_type")
|
val errorType = workInfo.outputData.getString("error_type")
|
||||||
if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) {
|
if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) {
|
||||||
|
@ -674,6 +687,7 @@ class ConversationInfoActivity :
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -826,6 +840,18 @@ class ConversationInfoActivity :
|
||||||
binding.archiveConversationTextHint.text = resources.getString(R.string.archive_hint)
|
binding.archiveConversationTextHint.text = resources.getString(R.string.archive_hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ConversationUtils.isConversationReadOnlyAvailable(conversationCopy, spreedCapabilities)) {
|
||||||
|
binding.lockConversation.visibility = VISIBLE
|
||||||
|
binding.lockConversation.setOnClickListener {
|
||||||
|
val isChecked = binding.lockConversationSwitch.isChecked
|
||||||
|
binding.lockConversationSwitch.isChecked = !isChecked
|
||||||
|
val state = if (isChecked) 0 else 1
|
||||||
|
makeConversationReadOnly(conversationUser, conversationToken, state)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding.lockConversation.visibility = GONE
|
||||||
|
}
|
||||||
|
|
||||||
if (!isDestroyed) {
|
if (!isDestroyed) {
|
||||||
binding.dangerZoneOptions.visibility = VISIBLE
|
binding.dangerZoneOptions.visibility = VISIBLE
|
||||||
|
|
||||||
|
@ -898,6 +924,10 @@ class ConversationInfoActivity :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun makeConversationReadOnly(conversationUser: User, roomToken: String, state: Int) {
|
||||||
|
viewModel.setConversationReadOnly(conversationUser, roomToken, state)
|
||||||
|
}
|
||||||
|
|
||||||
private fun initRecordingConsentOption() {
|
private fun initRecordingConsentOption() {
|
||||||
fun hide() {
|
fun hide() {
|
||||||
binding.recordingConsentView.recordingConsentSettingsCategory.visibility = GONE
|
binding.recordingConsentView.recordingConsentSettingsCategory.visibility = GONE
|
||||||
|
|
|
@ -76,6 +76,13 @@ 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
|
||||||
|
@ -178,6 +185,30 @@ class ConversationInfoViewModel @Inject constructor(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setConversationReadOnly(user: User, token: String, state: Int) {
|
||||||
|
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
||||||
|
val url = ApiUtils.getUrlForConversationReadOnly(apiVersion, user.baseUrl!!, token)
|
||||||
|
conversationsRepository.setConversationReadOnly(user.getCredentials(), url, state)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
?.subscribe(object : Observer<GenericOverall> {
|
||||||
|
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) {
|
||||||
val url = ApiUtils.getUrlForUnban(user.baseUrl!!, token, banId)
|
val url = ApiUtils.getUrlForUnban(user.baseUrl!!, token, banId)
|
||||||
chatNetworkDataSource.unbanActor(user.getCredentials(), url)
|
chatNetworkDataSource.unbanActor(user.getCredentials(), url)
|
||||||
|
|
|
@ -34,4 +34,6 @@ interface ConversationsRepository {
|
||||||
suspend fun archiveConversation(credentials: String, url: String): GenericOverall
|
suspend fun archiveConversation(credentials: String, url: String): GenericOverall
|
||||||
|
|
||||||
suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall
|
suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall
|
||||||
|
|
||||||
|
fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable<GenericOverall>
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,10 @@ class ConversationsRepositoryImpl(
|
||||||
return coroutineApi.unarchiveConversation(credentials, url)
|
return coroutineApi.unarchiveConversation(credentials, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable<GenericOverall> {
|
||||||
|
return api.setConversationReadOnly(credentials, url, state)
|
||||||
|
}
|
||||||
|
|
||||||
private fun apiVersion(): Int {
|
private fun apiVersion(): Int {
|
||||||
return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
|
return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ object ApiUtils {
|
||||||
return getUrlForRoom(version, baseUrl, token) + "/password"
|
return getUrlForRoom(version, baseUrl, token) + "/password"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUrlForRoomReadOnlyState(version: Int, baseUrl: String?, token: String?): String {
|
fun getUrlForConversationReadOnly(version: Int, baseUrl: String?, token: String?): String {
|
||||||
return getUrlForRoom(version, baseUrl, token) + "/read-only"
|
return getUrlForRoom(version, baseUrl, token) + "/read-only"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,14 @@ object ConversationUtils {
|
||||||
!isNoteToSelfConversation(conversation)
|
!isNoteToSelfConversation(conversation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isConversationReadOnlyAvailable(
|
||||||
|
conversation: ConversationModel,
|
||||||
|
spreedCapabilities: SpreedCapability
|
||||||
|
): Boolean {
|
||||||
|
return CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.READ_ONLY_ROOMS) &&
|
||||||
|
canModerate(conversation, spreedCapabilities)
|
||||||
|
}
|
||||||
|
|
||||||
fun isLobbyViewApplicable(conversation: ConversationModel, spreedCapabilities: SpreedCapability): Boolean {
|
fun isLobbyViewApplicable(conversation: ConversationModel, spreedCapabilities: SpreedCapability): Boolean {
|
||||||
return !canModerate(conversation, spreedCapabilities) &&
|
return !canModerate(conversation, spreedCapabilities) &&
|
||||||
(
|
(
|
||||||
|
|
|
@ -335,14 +335,13 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.materialswitch.MaterialSwitch
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
android:id="@+id/lobby_switch"
|
android:id="@+id/lock_conversation_switch"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginStart="@dimen/standard_margin"
|
android:layout_marginStart="@dimen/standard_margin"
|
||||||
android:layout_marginEnd="1dp"
|
android:layout_marginEnd="1dp"
|
||||||
android:checked="false"
|
android:clickable="false"
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true" />
|
android:focusable="true" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -824,4 +824,5 @@ How to translate with transifex:
|
||||||
<string name="archived">Archived</string>
|
<string name="archived">Archived</string>
|
||||||
<string name="archive_hint">Once a conversation is archived, it will be hidden by default. Select the filter \'Archived\' to view archived conversations. Direct mentions will still be received.</string>
|
<string name="archive_hint">Once a conversation is archived, it will be hidden by default. Select the filter \'Archived\' to view archived conversations. Direct mentions will still be received.</string>
|
||||||
<string name="unarchive_hint">Once a conversation is unarchived, it will be shown by default again.</string>
|
<string name="unarchive_hint">Once a conversation is unarchived, it will be shown by default again.</string>
|
||||||
|
<string name="conversation_read_only_failed">Failed to set conversation Read-only</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue