-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert PushRuleService to suspend functions #2414
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,13 @@ | |
*/ | ||
package im.vector.app.features.settings | ||
|
||
import androidx.lifecycle.lifecycleScope | ||
import androidx.preference.Preference | ||
import im.vector.app.R | ||
import im.vector.app.core.preference.PushRulePreference | ||
import im.vector.app.core.preference.VectorPreference | ||
import im.vector.app.core.utils.toast | ||
import org.matrix.android.sdk.api.MatrixCallback | ||
import kotlinx.coroutines.launch | ||
import org.matrix.android.sdk.api.pushrules.RuleIds | ||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind | ||
import javax.inject.Inject | ||
|
@@ -50,29 +51,25 @@ class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor() | |
if (newRule != null) { | ||
displayLoadingView() | ||
|
||
session.updatePushRuleActions( | ||
ruleAndKind.kind, | ||
preference.ruleAndKind?.pushRule ?: ruleAndKind.pushRule, | ||
newRule, | ||
object : MatrixCallback<Unit> { | ||
override fun onSuccess(data: Unit) { | ||
if (!isAdded) { | ||
return | ||
} | ||
preference.setPushRule(ruleAndKind.copy(pushRule = newRule)) | ||
hideLoadingView() | ||
} | ||
|
||
override fun onFailure(failure: Throwable) { | ||
if (!isAdded) { | ||
return | ||
} | ||
hideLoadingView() | ||
// Restore the previous value | ||
refreshDisplay() | ||
activity?.toast(errorFormatter.toHumanReadable(failure)) | ||
} | ||
}) | ||
lifecycleScope.launch { | ||
val result = runCatching { | ||
session.updatePushRuleActions(ruleAndKind.kind, | ||
preference.ruleAndKind?.pushRule ?: ruleAndKind.pushRule, | ||
newRule) | ||
} | ||
if (!isAdded) { | ||
return@launch | ||
} | ||
result.onSuccess { | ||
preference.setPushRule(ruleAndKind.copy(pushRule = newRule)) | ||
} | ||
hideLoadingView() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a detail, but now, I would rather call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically the behaviour would be different (out of scope) but I'm not bothered if you're not bothered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I do not think it will introduce a bug if we reorder. Also we could use |
||
result.onFailure { failure -> | ||
// Restore the previous value | ||
refreshDisplay() | ||
activity?.toast(errorFormatter.toHumanReadable(failure)) | ||
} | ||
} | ||
} | ||
false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all those 4 methods, the
return
statement could be removed.