Skip to content

Commit

Permalink
refactor: Base folder's thread query on the thread snooze state inste…
Browse files Browse the repository at this point in the history
…ad of the one of messages
  • Loading branch information
LunarX committed Mar 6, 2025
1 parent 1066fdf commit 29d4da8
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,13 @@ class ThreadController @Inject constructor(
): RealmQuery<Thread> {
val snoozeState = SnoozeState.Snoozed.apiValue

val collectionOperator = if (withSnooze) "ANY" else "NONE"
val nullOperator = if (withSnooze) "!=" else "=="

val isSnoozedState = "$collectionOperator messages._snoozeState == $1"

// TODO: Use the thread snooze state values instead of ANY/NONE on the messages
// This mimics the behavior on the web and help avoid displaying threads that are in an incoherent state on the API
val hasCorrectMetadata = "messages.snoozeEndDate $nullOperator null AND messages.snoozeAction $nullOperator null"
// Checking for snoozeEndDate and snoozeAction on top of _snoozeState mimics the behavior on the web and helps avoid
// displaying threads that are in an incoherent state on the API
val isSnoozedState = "_snoozeState == $1 AND snoozeEndDate != null AND snoozeAction != null"
val snoozeQuery = if (withSnooze) isSnoozedState else "NOT($isSnoozedState)"

return realm.query<Thread>(
"${Thread::folderId.name} == $0 AND $isSnoozedState AND $hasCorrectMetadata",
"${Thread::folderId.name} == $0 AND $snoozeQuery",
folderId,
snoozeState,
)
Expand Down

0 comments on commit 29d4da8

Please sign in to comment.