feat: Ignore suggested accounts that haven't posted in 28 days (#1031)
The "Suggested accounts" API returns dormant accounts. See this bug report: https://github.com/mastodon/mastodon/issues/30674. That's bad UX, so filter out any account that hasn't posted in the last 28 days. Fixes #1029
This commit is contained in:
parent
ffb585b349
commit
e68ab54f95
|
@ -27,6 +27,8 @@ import com.github.michaelbull.result.Result
|
||||||
import com.github.michaelbull.result.coroutines.binding.binding
|
import com.github.michaelbull.result.coroutines.binding.binding
|
||||||
import com.github.michaelbull.result.map
|
import com.github.michaelbull.result.map
|
||||||
import com.github.michaelbull.result.mapError
|
import com.github.michaelbull.result.mapError
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -38,8 +40,18 @@ class NetworkSuggestionsRepository @Inject constructor(
|
||||||
private val api: MastodonApi,
|
private val api: MastodonApi,
|
||||||
) : SuggestionsRepository {
|
) : SuggestionsRepository {
|
||||||
override suspend fun getSuggestions(): Result<List<Suggestion>, GetSuggestionsError> = binding {
|
override suspend fun getSuggestions(): Result<List<Suggestion>, GetSuggestionsError> = binding {
|
||||||
|
val now = Instant.now()
|
||||||
api.getSuggestions(limit = 80)
|
api.getSuggestions(limit = 80)
|
||||||
.map { response -> response.body.map { Suggestion.from(it) } }
|
.map { response ->
|
||||||
|
response.body
|
||||||
|
// Filter out accounts that haven't posted in the last LAST_STATUS_CUTOFF_DURATION.
|
||||||
|
.filter {
|
||||||
|
it.account.lastStatusAt?.let { lastStatusAt ->
|
||||||
|
Duration.between(lastStatusAt.toInstant(), now) < LAST_STATUS_CUTOFF_DURATION
|
||||||
|
} == true
|
||||||
|
}
|
||||||
|
.map { Suggestion.from(it) }
|
||||||
|
}
|
||||||
.mapError { GetSuggestionsError(it) }
|
.mapError { GetSuggestionsError(it) }
|
||||||
.bind()
|
.bind()
|
||||||
}
|
}
|
||||||
|
@ -55,4 +67,12 @@ class NetworkSuggestionsRepository @Inject constructor(
|
||||||
api.followSuggestedAccount(accountId).mapError { FollowAccountError(it) }.bind()
|
api.followSuggestedAccount(accountId).mapError { FollowAccountError(it) }.bind()
|
||||||
}.await()
|
}.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Duration that specifies the maximum time in the past the account must have
|
||||||
|
* posted a status for inclusion.
|
||||||
|
*/
|
||||||
|
private val LAST_STATUS_CUTOFF_DURATION = Duration.ofDays(28)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue