Skip to content

Commit

Permalink
Add setting for recording consent in conversation info
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Oct 27, 2023
1 parent 9ea77f6 commit 7f4bda2
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ class CallActivity : CallBaseActivity() {
conversationUser,
intArrayOf(ApiUtils.APIv4, 1)
)
// use MVVM
ncApi!!.getRoom(credentials, ApiUtils.getUrlForRoom(getRoomApiVersion, baseUrl, roomToken))
.retry(API_RETRIES)
.subscribeOn(Schedulers.io())
Expand All @@ -553,6 +552,7 @@ class CallActivity : CallBaseActivity() {

override fun onError(e: Throwable) {
Log.e(TAG, "Failed to get room", e)
Snackbar.make(binding!!.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
}

override fun onComplete() {
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String autho

@FormUrlEncoded
@POST
Observable<GenericOverall> joinCall(@Nullable @Header("Authorization") String authorization, @Url String url,
Observable<GenericOverall> joinCall(@Nullable @Header("Authorization") String authorization,
@Url String url,
@Field("flags") Integer inCall,
@Field("silent") Boolean callWithoutNotification);
@Field("silent") Boolean callWithoutNotification,
@Nullable @Field("recordingConsent") Boolean recordingConsent);

/*
Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken
Expand Down Expand Up @@ -686,4 +688,10 @@ Observable<GenericOverall> deleteReminder(@Header("Authorization") String author
Observable<ReminderOverall> setReminder(@Header("Authorization") String authorization,
@Url String url,
@Field("timestamp") int timestamp);

@FormUrlEncoded
@PUT
Observable<GenericOverall> setRecordingConsent(@Header("Authorization") String authorization,
@Url String url,
@Field("recordingConsent") int recordingConsent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class ConversationInfoActivity :
binding.notificationSettingsView.callNotificationsSwitch,
binding.notificationSettingsView.importantConversationSwitch,
binding.guestAccessView.allowGuestsSwitch,
binding.guestAccessView.passwordProtectionSwitch
binding.guestAccessView.passwordProtectionSwitch,
binding.recordingConsentView.recordingConsentForConversationSwitch
).forEach(viewThemeUtils.talk::colorSwitch)
}
}
Expand All @@ -259,6 +260,7 @@ class ConversationInfoActivity :
binding.webinarInfoView.webinarSettingsCategory,
binding.guestAccessView.guestAccessSettingsCategory,
binding.sharedItemsTitle,
binding.recordingConsentView.recordingConsentSettingsCategory,
binding.conversationSettingsTitle,
binding.participantsListCategory
)
Expand Down Expand Up @@ -707,6 +709,7 @@ class ConversationInfoActivity :

loadConversationAvatar()
adjustNotificationLevelUI()
initRecordingConsentOption()
initExpiringMessageOption()

binding.let {
Expand Down Expand Up @@ -738,6 +741,86 @@ class ConversationInfoActivity :
})
}

private fun initRecordingConsentOption() {
fun hide() {
binding.recordingConsentView.recordingConsentSettingsCategory.visibility = GONE
binding.recordingConsentView.recordingConsentForConversation.visibility = GONE
binding.recordingConsentView.recordingConsentAll.visibility = GONE
}

fun showAlwaysRequiredInfo() {
binding.recordingConsentView.recordingConsentForConversation.visibility = GONE
binding.recordingConsentView.recordingConsentAll.visibility = VISIBLE
}

fun showSwitch() {
binding.recordingConsentView.recordingConsentForConversation.visibility = VISIBLE
binding.recordingConsentView.recordingConsentAll.visibility = GONE

if (conversation!!.hasCall) {
binding.recordingConsentView.recordingConsentForConversation.isEnabled = false
binding.recordingConsentView.recordingConsentForConversation.alpha = LOW_EMPHASIS_OPACITY
} else {
binding.recordingConsentView.recordingConsentForConversationSwitch.isChecked =
conversation!!.recordingConsentRequired == RECORDING_CONSENT_REQUIRED_FOR_CONVERSATION

binding.recordingConsentView.recordingConsentForConversation.setOnClickListener {
binding.recordingConsentView.recordingConsentForConversationSwitch.isChecked =
!binding.recordingConsentView.recordingConsentForConversationSwitch.isChecked
submitRecordingConsentChanges()
}
}
}

if (conversation!!.isParticipantOwnerOrModerator &&
!ConversationUtils.isNoteToSelfConversation(ConversationModel.mapToConversationModel(conversation!!))
) {
when (CapabilitiesUtilNew.getRecordingConsentType(conversationUser)) {
CapabilitiesUtilNew.RECORDING_CONSENT_NOT_REQUIRED -> hide()
CapabilitiesUtilNew.RECORDING_CONSENT_REQUIRED -> showAlwaysRequiredInfo()
CapabilitiesUtilNew.RECORDING_CONSENT_DEPEND_ON_CONVERSATION -> showSwitch()
}
} else {
hide()
}
}

private fun submitRecordingConsentChanges() {
val state = if (binding.recordingConsentView.recordingConsentForConversationSwitch.isChecked) {
RECORDING_CONSENT_REQUIRED_FOR_CONVERSATION
} else {
RECORDING_CONSENT_NOT_REQUIRED_FOR_CONVERSATION
}

val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))

ncApi.setRecordingConsent(
ApiUtils.getCredentials(conversationUser.username, conversationUser.token),
ApiUtils.getUrlForRecordingConsent(apiVersion, conversationUser.baseUrl, conversation!!.token),
state
)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onComplete() {
// unused atm
}

override fun onSubscribe(d: Disposable) {
// unused atm
}

override fun onNext(t: GenericOverall) {
// unused atm
}

override fun onError(e: Throwable) {
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
Log.e(TAG, "Error when setting recording consent option for conversation", e)
}
})
}

private fun initExpiringMessageOption() {
if (conversation!!.isParticipantOwnerOrModerator &&
!ConversationUtils.isNoteToSelfConversation(ConversationModel.mapToConversationModel(conversation!!)) &&
Expand Down Expand Up @@ -1227,11 +1310,13 @@ class ConversationInfoActivity :
}

companion object {
private const val TAG = "ConversationInfo"
private val TAG = ConversationInfoActivity::class.java.simpleName
private const val NOTIFICATION_LEVEL_ALWAYS: Int = 1
private const val NOTIFICATION_LEVEL_MENTION: Int = 2
private const val NOTIFICATION_LEVEL_NEVER: Int = 3
private const val LOW_EMPHASIS_OPACITY: Float = 0.38f
private const val RECORDING_CONSENT_NOT_REQUIRED_FOR_CONVERSATION: Int = 0
private const val RECORDING_CONSENT_REQUIRED_FOR_CONVERSATION: Int = 1
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,8 @@ public static String getUrlForReminder(User user, String roomToken, String messa
String url = ApiUtils.getUrlForChatMessage(version, user.getBaseUrl(), roomToken, messageId);
return url + "/reminder";
}

public static String getUrlForRecordingConsent(int version, String baseUrl, String token) {
return getUrlForRoom(version, baseUrl, token) + "/recording-consent";
}
}
7 changes: 6 additions & 1 deletion app/src/main/res/layout/activity_conversation_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@
</LinearLayout>
</LinearLayout>

<include
android:id="@+id/recording_consent_view"
layout="@layout/item_recording_consent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />

<LinearLayout
android:id="@+id/conversation_settings"
Expand Down Expand Up @@ -261,7 +267,6 @@
android:popupTheme="@style/ThemeOverlay.AppTheme.PopupMenu"
android:text="" />


</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textview.MaterialTextView
Expand Down
72 changes: 72 additions & 0 deletions app/src/main/res/layout/item_recording_consent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/recording_consent_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/recording_consent_settings_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginEnd="@dimen/standard_margin"
android:paddingTop="@dimen/standard_padding"
android:paddingBottom="@dimen/standard_half_padding"
android:text="@string/recording_settings_title"
android:textSize="@dimen/headline_text_size"
android:textStyle="bold" />

<LinearLayout
android:id="@+id/recording_consent_for_conversation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal"
android:paddingStart="@dimen/standard_margin"
android:paddingTop="@dimen/standard_margin"
android:paddingEnd="@dimen/standard_margin"
android:paddingBottom="@dimen/standard_half_margin">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/recording_consent_for_conversation_title"
android:textSize="@dimen/headline_text_size" />

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/recording_consent_for_conversation_description"
android:textSize="@dimen/supporting_text_text_size" />

</LinearLayout>

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/recording_consent_for_conversation_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/standard_margin"
android:clickable="false" />

</LinearLayout>

<TextView
android:id="@+id/recording_consent_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/standard_margin"
android:paddingTop="@dimen/standard_margin"
android:paddingEnd="@dimen/standard_margin"
android:paddingBottom="@dimen/standard_half_margin"
android:text="@string/recording_consent_all" />

</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,12 @@ How to translate with transifex:
<string name="record_failed_info">The recording failed. Please contact your administrator.</string>
<string name="recording_consent_title">The call might be recorded.</string>
<string name="recording_consent_description">The recording might include your voice, video from camera, and screen share. Your consent is required before joining the call. Do you consent?</string>
<string name="recording_settings_title">Recording</string>
<string name="recording_consent_for_conversation_title">Recording consent</string>
<string name="recording_consent_for_conversation_description">Require recording consent before joining call in this conversation</string>
<string name="recording_consent_all">Recording consent is required for all calls</string>



<!-- Shared items -->
<string name="nc_shared_items">Shared items</string>
Expand Down

0 comments on commit 7f4bda2

Please sign in to comment.