mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-10 08:00:57 +00:00
convert rxjava to coroutines - set expiration and set notification levels for messages
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
1d9f475768
commit
5094cf5719
@ -163,4 +163,20 @@ interface NcApiCoroutines {
|
||||
@Url url: String,
|
||||
@Field("state") state: Int
|
||||
): GenericOverall
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
suspend fun setNotificationLevel(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Url url: String,
|
||||
@Field("level") level: Int
|
||||
): GenericOverall
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
suspend fun setMessageExpiration(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Url url: String,
|
||||
@Field("seconds") seconds: Int
|
||||
): GenericOverall
|
||||
}
|
||||
|
@ -1016,8 +1016,10 @@ class ConversationInfoActivity :
|
||||
.setSimpleItems(resources.getStringArray(R.array.message_expiring_descriptions))
|
||||
binding.conversationSettingsDropdown.setOnItemClickListener { _, _, position, _ ->
|
||||
val v: String = resources.getStringArray(R.array.message_expiring_values)[position]
|
||||
lifecycleScope.launch {
|
||||
databaseStorageModule!!.saveString("conversation_settings_dropdown", v)
|
||||
}
|
||||
}
|
||||
binding.messageExpirationSettings.visibility = VISIBLE
|
||||
} else {
|
||||
binding.messageExpirationSettings.visibility = GONE
|
||||
@ -1521,7 +1523,6 @@ class ConversationInfoActivity :
|
||||
lifecycleScope.launch {
|
||||
module.saveBoolean("important_conversation_switch", !isChecked)
|
||||
}
|
||||
|
||||
}
|
||||
binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener {
|
||||
val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked
|
||||
@ -1534,8 +1535,10 @@ class ConversationInfoActivity :
|
||||
.setOnItemClickListener { _, _, position, _ ->
|
||||
val value = resources.getStringArray(R.array.message_notification_levels_entry_values)[position]
|
||||
Log.i(TAG, "saved $value to module from $position")
|
||||
lifecycleScope.launch {
|
||||
module.saveString("conversation_info_message_notifications_dropdown", value)
|
||||
}
|
||||
}
|
||||
|
||||
binding.notificationSettingsView.importantConversationSwitch.isChecked = module
|
||||
.getBoolean("important_conversation_switch", false)
|
||||
|
@ -18,7 +18,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA
|
||||
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
|
||||
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils.getConversationApiVersion
|
||||
import com.nextcloud.talk.utils.ApiUtils.getCredentials
|
||||
@ -28,10 +27,6 @@ import com.nextcloud.talk.utils.ApiUtils.getUrlForRoomNotificationLevel
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability
|
||||
import com.nextcloud.talk.utils.SpreedFeatures
|
||||
import com.nextcloud.talk.utils.UserIdUtils.getIdForUser
|
||||
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
|
||||
@ -83,7 +78,6 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("lobby_switch" != key) {
|
||||
arbitraryStorageManager!!.storeStorageSetting(
|
||||
accountIdentifier,
|
||||
@ -96,18 +90,16 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveString(key: String, value: String) {
|
||||
if ("conversation_settings_dropdown" == key) {
|
||||
suspend fun saveString(key: String, value: String) {
|
||||
when (key) {
|
||||
"conversation_settings_dropdown" -> {
|
||||
try {
|
||||
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4))
|
||||
|
||||
val trimmedValue = value.replace("expire_", "")
|
||||
val valueInt = trimmedValue.toInt()
|
||||
|
||||
ncApi!!.setMessageExpiration(
|
||||
getCredentials(
|
||||
conversationUser.username,
|
||||
conversationUser.token
|
||||
),
|
||||
withContext(Dispatchers.IO) {
|
||||
ncApiCoroutines!!.setMessageExpiration(
|
||||
getCredentials(conversationUser.username, conversationUser.token)!!,
|
||||
getUrlForMessageExpiration(
|
||||
apiVersion,
|
||||
conversationUser.baseUrl,
|
||||
@ -115,26 +107,14 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
),
|
||||
valueInt
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(genericOverall: GenericOverall) {
|
||||
messageExpiration = valueInt
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error when trying to set message expiration", e)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Error when trying to set message expiration", exception)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
} else if ("conversation_info_message_notifications_dropdown" == key) {
|
||||
"conversation_info_message_notifications_dropdown" -> {
|
||||
try {
|
||||
if (hasSpreedFeatureCapability(
|
||||
conversationUser.capabilities!!.spreedCapability!!,
|
||||
SpreedFeatures.NOTIFICATION_LEVELS
|
||||
@ -147,14 +127,13 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
"always" -> 1
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1))
|
||||
|
||||
ncApi!!.setNotificationLevel(
|
||||
withContext(Dispatchers.IO) {
|
||||
ncApiCoroutines!!.setNotificationLevel(
|
||||
getCredentials(
|
||||
conversationUser.username,
|
||||
conversationUser.token
|
||||
),
|
||||
)!!,
|
||||
getUrlForRoomNotificationLevel(
|
||||
apiVersion,
|
||||
conversationUser.baseUrl,
|
||||
@ -162,32 +141,21 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
),
|
||||
intValue
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(object : Observer<GenericOverall?> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(p0: GenericOverall) {
|
||||
messageNotificationLevel = value
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
} else {
|
||||
messageNotificationLevel = value
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Error trying to set notification level", exception)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
arbitraryStorageManager!!.storeStorageSetting(accountIdentifier, key, value, conversationToken)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBoolean(key: String, defaultVal: Boolean): Boolean {
|
||||
return if ("lobby_switch" == key) {
|
||||
|
Loading…
Reference in New Issue
Block a user