Skip to content

Commit

Permalink
DROID-3167 Date as an Object | Exclude all object which were not crea…
Browse files Browse the repository at this point in the history
…ted by space members (#1911)
  • Loading branch information
konstantiniiv authored Dec 12, 2024
1 parent 85d64f7 commit 1511bab
Showing 1 changed file with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.RelationFormat
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.Relations.LAST_MODIFIED_DATE
import com.anytypeio.anytype.core_models.Relations.RELATION_KEY
import com.anytypeio.anytype.core_models.Relations.TYPE
import com.anytypeio.anytype.core_models.TimeInSeconds

fun filtersAndSortsForSearch(
Expand All @@ -21,8 +24,8 @@ fun filtersAndSortsForSearch(
addAll(buildDeletedFilter())
add(buildSpaceIdFilter(spaces))
add(buildTemplateFilter())
add(
buildFieldFilter(
addAll(
buildFieldFilters(
dateObjectId = dateId,
field = field,
timestamp = timestamp
Expand All @@ -45,31 +48,51 @@ private fun buildSorts(
)
}

private fun buildFieldFilter(
private fun buildFieldFilters(
dateObjectId: Id,
field: ActiveField,
timestamp: TimeInSeconds
): DVFilter {
): List<DVFilter> {
val fieldKey = field.key.key
return when (field.format) {
Relation.Format.DATE -> {
DVFilter(
relation = fieldKey,
condition = DVFilterCondition.EQUAL,
value = timestamp.toDouble(),
relationFormat = RelationFormat.DATE
)
buildList {
add(
DVFilter(
relation = fieldKey,
condition = DVFilterCondition.EQUAL,
value = timestamp.toDouble(),
relationFormat = RelationFormat.DATE
)
)
if (fieldKey == LAST_MODIFIED_DATE) {
add(
DVFilter(
relation = Relations.CREATED_DATE,
condition = DVFilterCondition.NOT_EQUAL,
value = mapOf(
RELATION_KEY to fieldKey,
TYPE to VALUE_FROM_RELATION
)
)
)
}
}
}
else -> {
DVFilter(
relation = fieldKey,
condition = DVFilterCondition.IN,
value = dateObjectId
listOf(
DVFilter(
relation = fieldKey,
condition = DVFilterCondition.IN,
value = dateObjectId
)
)
}
}
}

const val VALUE_FROM_RELATION = "valueFromRelation"

private fun buildTemplateFilter(): DVFilter = DVFilter(
relation = Relations.TYPE_UNIQUE_KEY,
condition = DVFilterCondition.NOT_EQUAL,
Expand Down

0 comments on commit 1511bab

Please sign in to comment.