diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 6bf7f984c..498a73678 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/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 setTypingStatusPrivacy(@Header("Authorization") String authorization, + @Url String url, + @Body RequestBody body); + @POST Observable searchContactsByPhoneNumber(@Header("Authorization") String authorization, @Url String url, diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index ab29d7942..55a0f9385 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -124,6 +124,7 @@ class SettingsActivity : BaseActivity() { private var screenLockTimeoutChangeListener: OnPreferenceValueChangedListener? = null private var themeChangeListener: OnPreferenceValueChangedListener? = null private var readPrivacyChangeListener: OnPreferenceValueChangedListener? = null + private var typingStatusChangeListener: OnPreferenceValueChangedListener? = null private var phoneBookIntegrationChangeListener: OnPreferenceValueChangedListener? = 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(R.id.mp_checkable) as Checkable).isChecked = + !CapabilitiesUtilNew.isTypingStatusPrivate(currentUser!!) + } else { + binding.settingsTypingStatus.visibility = View.GONE + } + (binding.settingsPhoneBookIntegration.findViewById(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 { + 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 { + 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(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 diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt b/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt index d91a4178f..88a2676b9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/database/user/CapabilitiesUtilNew.kt +++ b/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? = 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 } diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java index 96b53631d..898819a97 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java +++ b/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 listener); + @KeyByResource(R.string.nc_settings_read_privacy_key) + @RegisterChangeListenerMethod + void registerTypingStatusChangeListener(OnPreferenceValueChangedListener listener); + + @KeyByResource(R.string.nc_settings_read_privacy_key) + @UnregisterChangeListenerMethod + void unregisterTypingStatusChangeListener(OnPreferenceValueChangedListener listener); + @KeyByResource(R.string.nc_file_browser_sort_by_key) void setSorting(String value); diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index c292f30e2..7c5c4890a 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/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" /> + + Locked Share my read-status and show the read-status of others Read status + Share my typing-status and show the typing-status of others + Typing status 30 seconds 1 minute