Skip to content
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

include filtered notifications in the notification tab #4712

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class NotificationsRemoteMediator(
// so already existing placeholders don't get accidentally overwritten
sinceId = topPlaceholderId,
limit = state.config.pageSize,
excludes = excludes
excludes = excludes,
includeFiltered = true
)

val notifications = notificationResponse.body()
Expand All @@ -89,14 +90,24 @@ class NotificationsRemoteMediator(

val notificationResponse = when (loadType) {
LoadType.REFRESH -> {
api.notifications(sinceId = topPlaceholderId, limit = state.config.pageSize, excludes = excludes)
api.notifications(
sinceId = topPlaceholderId,
limit = state.config.pageSize,
excludes = excludes,
includeFiltered = true
)
}
LoadType.PREPEND -> {
return MediatorResult.Success(endOfPaginationReached = true)
}
LoadType.APPEND -> {
val maxId = state.pages.findLast { it.data.isNotEmpty() }?.data?.lastOrNull()?.id
api.notifications(maxId = maxId, limit = state.config.pageSize, excludes = excludes)
api.notifications(
maxId = maxId,
limit = state.config.pageSize,
excludes = excludes,
includeFiltered = true
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,17 @@ class NotificationsViewModel @Inject constructor(
maxId = idAbovePlaceholder,
minId = idBelowPlaceholder,
limit = TimelineViewModel.LOAD_AT_ONCE,
excludes = excludes.value
excludes = excludes.value,
includeFiltered = true
)
// Using sinceId, loads up to LOAD_AT_ONCE statuses immediately before
// maxId, and no smaller than minId.
ReadingOrder.NEWEST_FIRST -> api.notifications(
maxId = idAbovePlaceholder,
sinceId = idBelowPlaceholder,
limit = TimelineViewModel.LOAD_AT_ONCE,
excludes = excludes.value
excludes = excludes.value,
includeFiltered = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ interface MastodonApi {
/** Maximum number of results to return. Defaults to 15, max is 30 */
@Query("limit") limit: Int? = null,
/** Types to excludes from the results */
@Query("exclude_types[]") excludes: Set<Notification.Type>? = null
@Query("exclude_types[]") excludes: Set<Notification.Type>? = null,
@Query("include_filtered") includeFiltered: Boolean = true
): Response<List<Notification>>

/** Fetch a single notification */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class NotificationsRemoteMediatorTest {
val remoteMediator = NotificationsRemoteMediator(
accountManager = accountManager,
api = mock {
onBlocking { notifications(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) } doReturn Response.error(500, "".toResponseBody())
onBlocking { notifications(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) } doReturn Response.error(500, "".toResponseBody())
},
db = db,
excludes = emptySet()
Expand All @@ -99,7 +99,7 @@ class NotificationsRemoteMediatorTest {
val remoteMediator = NotificationsRemoteMediator(
accountManager = accountManager,
api = mock {
onBlocking { notifications(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) } doThrow IOException()
onBlocking { notifications(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) } doThrow IOException()
},
db = db,
excludes = emptySet()
Expand Down
Loading