Skip to content

Commit

Permalink
Do not propagate failure if saving the filter server side fails. This…
Browse files Browse the repository at this point in the history
… will be retried later.
  • Loading branch information
bmarty committed Dec 6, 2022
1 parent 6f0a95b commit ae93c07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class DefaultGetCurrentFilterTask @Inject constructor(

return when (storedFilterBody) {
currentFilterBody -> storedFilterId ?: storedFilterBody
else -> saveFilter(currentFilter)
else -> saveFilter(currentFilter) ?: currentFilterBody
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.matrix.android.sdk.internal.session.filter

import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
Expand All @@ -24,8 +25,9 @@ import javax.inject.Inject

/**
* Save a filter, in db and if any changes, upload to the server.
* Return the filterId if uploading to the server is successful, else return null.
*/
internal interface SaveFilterTask : Task<SaveFilterTask.Params, String> {
internal interface SaveFilterTask : Task<SaveFilterTask.Params, String?> {

data class Params(
val filter: Filter
Expand All @@ -39,18 +41,20 @@ internal class DefaultSaveFilterTask @Inject constructor(
private val globalErrorReceiver: GlobalErrorReceiver,
) : SaveFilterTask {

override suspend fun execute(params: SaveFilterTask.Params): String {
override suspend fun execute(params: SaveFilterTask.Params): String? {
val filter = params.filter
val filterResponse = executeRequest(globalErrorReceiver) {
// TODO auto retry
filterAPI.uploadFilter(userId, filter)
val filterResponse = tryOrNull {
executeRequest(globalErrorReceiver) {
filterAPI.uploadFilter(userId, filter)
}
}

val filterId = filterResponse?.filterId
filterRepository.storeSyncFilter(
filter = filter,
filterId = filterResponse.filterId,
filterId = filterId.orEmpty(),
roomEventFilter = FilterFactory.createDefaultRoomFilter()
)
return filterResponse.filterId
return filterId
}
}

0 comments on commit ae93c07

Please sign in to comment.