matrix-org / matrix-spec

The Matrix protocol specification
Apache License 2.0
188 stars 94 forks source link

Unclear what filtering with empty arrays does #1312

Open clokep opened 1 year ago

clokep commented 1 year ago

Link to problem area: https://spec.matrix.org/v1.4/client-server-api/#_matrixclientv3useruseridfilter_eventfilter

Issue

It is unclear what providing an empty array for e.g. types or not_types would do. Is that treated as not providing the field (empirically this is what happens)?

According to tulir the proper way to filter out all event types is: {"not_types": ["*"]}

See https://matrix.to/#/!NasysSDfxKxZBzJJoE:matrix.org/$q-MFBajP8Lvnxs7r1u_AyfGtUf7spu86BUVFuhqTHXM?via=matrix.org&via=libera.chat&via=element.io.

Benjamin-L commented 3 months ago

My opinion is that types: [] should filter out all events, same as not_types: [ "*" ]. not_types: [] should be a no-op. This is consistent with ruma's type definitions, where not_types: [] will be (de)serialized as a missing not_types key, while types: [] is preserved as different from a missing types key.

This behavior (types: [] rejects all events, not_types: [] is no-op) is what I'm using for my filtering implementation in grapevine here.

clokep commented 3 months ago

I believe that matches Synapse behavior: https://github.com/element-hq/synapse/blob/805e6c9a8f703a0a774321bd0755be63dcdcc807/synapse/api/filtering.py#L467

Unsure if this was always the same or changed recently: https://github.com/element-hq/synapse/commit/7e582a25f8f350df29d7d83ca902bdb522d1bbaf

Edit: Looks like that commit didn't change the filtering logic.