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 ff464b48f..ba0bc911f 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -131,6 +131,14 @@ interface NcApiCoroutines { @Url url: String ): GenericOverall + @FormUrlEncoded + @POST + suspend fun notificationCalls( + @Header("Authorization") authorization: String, + @Url url: String, + @Field("level") level: Int + ): GenericOverall + @POST suspend fun setReadStatusPrivacy( @Header("Authorization") authorization: String, diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index da36a2d09..eeb8a5ae0 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -835,7 +835,9 @@ class ConversationInfoActivity : binding.lockConversation.setOnClickListener { val isLocked = binding.lockConversationSwitch.isChecked binding.lockConversationSwitch.isChecked = !isLocked - databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) + lifecycleScope.launch{ + databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) + } val state = if (isLocked) 0 else 1 makeConversationReadOnly(conversationToken, state) } @@ -1516,12 +1518,17 @@ class ConversationInfoActivity : binding.notificationSettingsView.notificationSettingsImportantConversation.setOnClickListener { val isChecked = binding.notificationSettingsView.importantConversationSwitch.isChecked binding.notificationSettingsView.importantConversationSwitch.isChecked = !isChecked - module.saveBoolean("important_conversation_switch", !isChecked) + lifecycleScope.launch{ + module.saveBoolean("important_conversation_switch", !isChecked) + } + } binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener { val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked binding.notificationSettingsView.callNotificationsSwitch.isChecked = !isChecked - module.saveBoolean("call_notifications_switch", !isChecked) + lifecycleScope.launch{ + module.saveBoolean("call_notifications_switch", !isChecked) + } } binding.notificationSettingsView.conversationInfoMessageNotificationsDropdown .setOnItemClickListener { _, _, position, _ -> diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt index 76efd36cb..69d9f0562 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.kt @@ -12,6 +12,7 @@ import android.text.TextUtils import android.util.Log import autodagger.AutoInjector import com.nextcloud.talk.api.NcApi +import com.nextcloud.talk.api.NcApiCoroutines import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager @@ -31,10 +32,13 @@ import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) class DatabaseStorageModule(conversationUser: User, conversationToken: String) { + @JvmField @Inject var arbitraryStorageManager: ArbitraryStorageManager? = null @@ -43,6 +47,10 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { @Inject var ncApi: NcApi? = null + @JvmField + @Inject + var ncApiCoroutines: NcApiCoroutines?= null + private var messageExpiration = 0 private val conversationUser: User private val conversationToken: String @@ -60,42 +68,20 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) { this.conversationToken = conversationToken } - fun saveBoolean(key: String, value: Boolean) { + suspend fun saveBoolean(key: String, value: Boolean) { if ("call_notifications_switch" == key) { val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) - ncApi!!.notificationCalls( - getCredentials( - conversationUser.username, - conversationUser.token - ), - getUrlForRoomNotificationCalls( - apiVersion, - conversationUser.baseUrl, - conversationToken - ), - if (value) 1 else 0 - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - object : Observer { - override fun onSubscribe(d: Disposable) { - // unused atm - } - - override fun onNext(genericOverall: GenericOverall) { - Log.d(TAG, "Toggled notification calls") - } - - override fun onError(e: Throwable) { - Log.e(TAG, "Error when trying to toggle notification calls", e) - } - - override fun onComplete() { - // unused atm - } - } - ) + val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl,conversationToken) + val credentials = getCredentials(conversationUser.username,conversationUser.token) + val notificationLevel = if(value) 1 else 0 + withContext(Dispatchers.IO) { + try { + ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel) + Log.d(TAG, "Toggled notification calls") + } catch (e: Throwable) { + Log.e(TAG, "Error when trying to toggle notification calls", e) + } + } } if ("lobby_switch" != key) {