From 9f3bbf6ebfaf77115ce7a2f491e203d586c3c106 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Tue, 12 Nov 2024 16:53:29 +0100 Subject: [PATCH] refactor code Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 4 +-- .../talk/settings/SettingsActivity.kt | 25 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index bb68691a0..5707ae397 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -121,14 +121,14 @@ interface NcApiCoroutines { @POST suspend fun setReadStatusPrivacy( - @Header("Authorization") authorization: String?, + @Header("Authorization") authorization: String, @Url url: String, @Body body: RequestBody ): GenericOverall @POST suspend fun setTypingStatusPrivacy( - @Header("Authorization") authorization: String?, + @Header("Authorization") authorization: String, @Url url: String, @Body body: RequestBody ): GenericOverall 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 152f2106e..adb4183bd 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -1285,11 +1285,13 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu val booleanValue = if (newBoolean) "0" else "1" val json = "{\"key\": \"read_status_privacy\", \"value\" : $booleanValue}" try { - ncApiCoroutines.setReadStatusPrivacy( - ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token), - ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!), - json.toRequestBody("application/json".toMediaTypeOrNull()) - ) + credentials?.let { credentials -> + ncApiCoroutines.setReadStatusPrivacy( + credentials, + ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!), + json.toRequestBody("application/json".toMediaTypeOrNull()) + ) + } Log.i(TAG, "reading status set") } catch (e: Exception) { appPreferences.setReadPrivacy(!newBoolean) @@ -1310,11 +1312,14 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu val json = "{\"key\": \"typing_privacy\", \"value\" : $booleanValue}" try { - ncApiCoroutines.setTypingStatusPrivacy( - ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token), - ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!), - json.toRequestBody("application/json".toMediaTypeOrNull()) - ) + credentials?.let { credentials -> + ncApiCoroutines.setTypingStatusPrivacy( + credentials, + ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!), + json.toRequestBody("application/json".toMediaTypeOrNull()) + ) + } + loadCapabilitiesAndUpdateSettings() Log.i(TAG, "typing status set") } catch (e: Exception) {