Răsfoiți Sursa

add setting to toggle typing status privacy

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 ani în urmă
părinte
comite
d3d8e2abef

+ 5 - 0
app/src/main/java/com/nextcloud/talk/api/NcApi.java

@@ -453,6 +453,11 @@ public interface NcApi {
                                                     @Url String url,
                                                     @Body RequestBody body);
 
+    @POST
+    Observable<GenericOverall> setTypingStatusPrivacy(@Header("Authorization") String authorization,
+                                                    @Url String url,
+                                                    @Body RequestBody body);
+
     @POST
     Observable<ContactsByNumberOverall> searchContactsByPhoneNumber(@Header("Authorization") String authorization,
                                                                     @Url String url,

+ 49 - 1
app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt

@@ -124,6 +124,7 @@ class SettingsActivity : BaseActivity() {
     private var screenLockTimeoutChangeListener: OnPreferenceValueChangedListener<String?>? = null
     private var themeChangeListener: OnPreferenceValueChangedListener<String?>? = null
     private var readPrivacyChangeListener: OnPreferenceValueChangedListener<Boolean>? = null
+    private var typingStatusChangeListener: OnPreferenceValueChangedListener<Boolean>? = null
     private var phoneBookIntegrationChangeListener: OnPreferenceValueChangedListener<Boolean>? = null
     private var profileQueryDisposable: Disposable? = null
     private var dbQueryDisposable: Disposable? = null
@@ -419,6 +420,11 @@ class SettingsActivity : BaseActivity() {
                 readPrivacyChangeListener = it
             }
         )
+        appPreferences.registerTypingStatusChangeListener(
+            TypingStatusChangeListener().also {
+                typingStatusChangeListener = it
+            }
+        )
     }
 
     fun sendLogs() {
@@ -487,6 +493,7 @@ class SettingsActivity : BaseActivity() {
                 settingsIncognitoKeyboard,
                 settingsPhoneBookIntegration,
                 settingsReadPrivacy,
+                settingsTypingStatus,
                 settingsProxyUseCredentials
             ).forEach(viewThemeUtils.talk::colorSwitchPreference)
         }
@@ -660,6 +667,13 @@ class SettingsActivity : BaseActivity() {
             binding.settingsReadPrivacy.visibility = View.GONE
         }
 
+        if (CapabilitiesUtilNew.isTypingStatusAvailable(currentUser!!)) {
+            (binding.settingsTypingStatus.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
+                !CapabilitiesUtilNew.isTypingStatusPrivate(currentUser!!)
+        } else {
+            binding.settingsTypingStatus.visibility = View.GONE
+        }
+
         (binding.settingsPhoneBookIntegration.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
             appPreferences.isPhoneBookIntegrationEnabled
     }
@@ -697,6 +711,7 @@ class SettingsActivity : BaseActivity() {
         appPreferences.unregisterScreenLockTimeoutListener(screenLockTimeoutChangeListener)
         appPreferences.unregisterThemeChangeListener(themeChangeListener)
         appPreferences.unregisterReadPrivacyChangeListener(readPrivacyChangeListener)
+        appPreferences.unregisterTypingStatusChangeListener(typingStatusChangeListener)
         appPreferences.unregisterPhoneBookIntegrationChangeListener(phoneBookIntegrationChangeListener)
 
         super.onDestroy()
@@ -1010,7 +1025,7 @@ class SettingsActivity : BaseActivity() {
                     }
 
                     override fun onNext(genericOverall: GenericOverall) {
-                        Log.d(TAG, "onNext")
+                        // unused atm
                     }
 
                     override fun onError(e: Throwable) {
@@ -1026,6 +1041,39 @@ class SettingsActivity : BaseActivity() {
         }
     }
 
+    private inner class TypingStatusChangeListener : OnPreferenceValueChangedListener<Boolean> {
+        override fun onChanged(newValue: Boolean) {
+            val booleanValue = if (newValue) "0" else "1"
+            val json = "{\"key\": \"typing_privacy\", \"value\" : $booleanValue}"
+            ncApi.setTypingStatusPrivacy(
+                ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
+                ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl),
+                RequestBody.create("application/json".toMediaTypeOrNull(), json)
+            )
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(object : Observer<GenericOverall> {
+                    override fun onSubscribe(d: Disposable) {
+                        // unused atm
+                    }
+
+                    override fun onNext(genericOverall: GenericOverall) {
+                        // unused atm
+                    }
+
+                    override fun onError(e: Throwable) {
+                        appPreferences.setTypingStatus(!newValue)
+                        (binding.settingsTypingStatus.findViewById<View>(R.id.mp_checkable) as Checkable).isChecked =
+                            !newValue
+                    }
+
+                    override fun onComplete() {
+                        // unused atm
+                    }
+                })
+        }
+    }
+
     companion object {
         private const val TAG = "SettingsController"
         private const val DURATION: Long = 2500

+ 17 - 0
app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt

@@ -98,7 +98,24 @@ object CapabilitiesUtilNew {
                 return (map["read-privacy"]!!.toString()).toInt() == 1
             }
         }
+        return false
+    }
+
+    fun isTypingStatusAvailable(user: User): Boolean {
+        if (user.capabilities?.spreedCapability?.config?.containsKey("chat") == true) {
+            val map: Map<String, Any>? = user.capabilities!!.spreedCapability!!.config!!["chat"]
+            return map != null && map.containsKey("typing-privacy")
+        }
+        return false
+    }
 
+    fun isTypingStatusPrivate(user: User): Boolean {
+        if (user.capabilities?.spreedCapability?.config?.containsKey("chat") == true) {
+            val map = user.capabilities!!.spreedCapability!!.config!!["chat"]
+            if (map?.containsKey("typing-privacy") == true) {
+                return (map["typing-privacy"]!!.toString()).toInt() == 1
+            }
+        }
         return false
     }
 

+ 11 - 0
app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java

@@ -312,6 +312,9 @@ public interface AppPreferences {
 
     @KeyByResource(R.string.nc_settings_read_privacy_key)
     void setReadPrivacy(boolean value);
+
+    @KeyByResource(R.string.nc_settings_read_privacy_key)
+    void setTypingStatus(boolean value);
     
     @KeyByResource(R.string.nc_settings_read_privacy_key)
     @RegisterChangeListenerMethod
@@ -321,6 +324,14 @@ public interface AppPreferences {
     @UnregisterChangeListenerMethod
     void unregisterReadPrivacyChangeListener(OnPreferenceValueChangedListener<Boolean> listener);
 
+    @KeyByResource(R.string.nc_settings_read_privacy_key)
+    @RegisterChangeListenerMethod
+    void registerTypingStatusChangeListener(OnPreferenceValueChangedListener<Boolean> listener);
+
+    @KeyByResource(R.string.nc_settings_read_privacy_key)
+    @UnregisterChangeListenerMethod
+    void unregisterTypingStatusChangeListener(OnPreferenceValueChangedListener<Boolean> listener);
+
     @KeyByResource(R.string.nc_file_browser_sort_by_key)
     void setSorting(String value);
 

+ 8 - 0
app/src/main/res/layout/activity_settings.xml

@@ -264,6 +264,14 @@
             apc:mp_key="@string/nc_settings_read_privacy_key"
             apc:mp_summary="@string/nc_settings_read_privacy_desc"
             apc:mp_title="@string/nc_settings_read_privacy_title" />
+
+        <com.yarolegovich.mp.MaterialSwitchPreference
+            android:id="@+id/settings_typing_status"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            apc:mp_key="@string/nc_settings_read_privacy_key"
+            apc:mp_summary="@string/nc_settings_typing_status_desc"
+            apc:mp_title="@string/nc_settings_typing_status_title" />
     </com.yarolegovich.mp.MaterialPreferenceCategory>
 
     <com.yarolegovich.mp.MaterialPreferenceCategory

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -151,6 +151,8 @@ How to translate with transifex:
     <string name="nc_locked">Locked</string>
     <string name="nc_settings_read_privacy_desc">Share my read-status and show the read-status of others</string>
     <string name="nc_settings_read_privacy_title">Read status</string>
+    <string name="nc_settings_typing_status_desc">Share my typing-status and show the typing-status of others</string>
+    <string name="nc_settings_typing_status_title">Typing status</string>
 
     <string name="nc_screen_lock_timeout_30">30 seconds</string>
     <string name="nc_screen_lock_timeout_60">1 minute</string>