Documentation ¶
Overview ¶
Package filters contains helper functions to be used by the storage implementations for filtering out elements at load time.
Index ¶
- Constants
- Variables
- func CacheKey(f *Filters) vocab.IRI
- func FilterIt(it vocab.Item, f Filterable) (vocab.Item, error)
- func GetLimit(f ...Check) string
- func GetWhereClauses(f ...Check) ([]string, []any)
- func IRIf(f Filters, iri string) string
- func IsItemIRI(f vocab.LinkOrIRI) bool
- func LoadCollectionFilters(f *Filters, auth vocab.Actor) error
- func LoadItemFilters(f *Filters, auth vocab.Actor) error
- func PaginateCollection(it vocab.Item, filters ...Check) vocab.Item
- func PaginatorValues(q url.Values) pagValues
- func ValidActivityCollection(typ vocab.CollectionPath) bool
- func ValidCollection(typ vocab.CollectionPath) bool
- func ValidCollectionCount(col vocab.ItemCollection, f Filterable) bool
- func ValidObjectCollection(typ vocab.CollectionPath) bool
- func VocabularyTypesFilter(types ...string) vocab.ActivityVocabularyTypes
- type Check
- func Actor(fns ...Check) Check
- func After(fns ...Check) Check
- func All(fns ...Check) Check
- func Any(fns ...Check) Check
- func AttributedToLike(frag string) Check
- func Authorized(iri vocab.IRI) Check
- func Before(fn ...Check) Check
- func ContentIs(cont string) Check
- func ContentLike(cont string) Check
- func ContextLike(frag string) Check
- func HasType(ty ...vocab.ActivityVocabularyType) Check
- func IDLike(frag string) Check
- func IRILike(frag string) Check
- func InReplyToLike(frag string) Check
- func MaxCountChecks(fns ...Check) Check
- func NameIs(name string) Check
- func NameLike(name string) Check
- func Not(fn Check) Check
- func Object(fns ...Check) Check
- func SameAttributedTo(iri vocab.IRI) Check
- func SameContext(iri vocab.IRI) Check
- func SameID(i vocab.IRI) Check
- func SameIRI(iri vocab.IRI) Check
- func SameInReplyTo(iri vocab.IRI) Check
- func SameURL(iri vocab.IRI) Check
- func SummaryIs(sum string) Check
- func SummaryLike(sum string) Check
- func Tag(fns ...Check) Check
- func Target(fns ...Check) Check
- func URLLike(frag string) Check
- func WithMaxCount(max int) Check
- type Checks
- func ActivityChecks(fns ...Check) Checks
- func ActorChecks(fns ...Check) Checks
- func CursorChecks(fns ...Check) Checks
- func FilterChecks(fns ...Check) Checks
- func FromIRI(i vocab.IRI) (Checks, error)
- func FromURL(u url.URL) Checks
- func FromValues(q url.Values) Checks
- func IntransitiveActivityChecks(fns ...Check) Checks
- func ObjectChecks(fns ...Check) Checks
- func TargetChecks(fns ...Check) Checks
- func TypeChecks(fns ...Check) Checks
- type CollectionFilterer
- type CompStr
- type CompStrs
- type FilterFn
- type Filterable
- type FilterableActivity
- type FilterableCollection
- type FilterableItems
- type FilterableObject
- type Filtersdeprecated
- func (f Filters) Actors() vocab.IRIs
- func (f Filters) After() Hash
- func (f Filters) AttributedTo() CompStrs
- func (f Filters) Audience() CompStrs
- func (f Filters) Before() Hash
- func (f Filters) Content() CompStrs
- func (f Filters) Context() CompStrs
- func (f Filters) Count() int
- func (f Filters) FilterCollection(col vocab.ItemCollection) (vocab.ItemCollection, int)
- func (f Filters) Generator() CompStrs
- func (f *Filters) GetLink() vocab.IRI
- func (f Filters) IRIs() CompStrs
- func (f Filters) InReplyTo() CompStrs
- func (f *Filters) IsItemIRI() bool
- func (f *Filters) ItemsMatch(col ...vocab.Item) bool
- func (f Filters) MediaTypes() []vocab.MimeType
- func (f Filters) Names() CompStrs
- func (f Filters) Objects() vocab.IRIs
- func (f Filters) Page() int
- func (f Filters) Tags() *Filters
- func (f Filters) Targets() vocab.IRIs
- func (f Filters) Types() CompStrs
- func (f Filters) URLs() CompStrs
- type Hash
- type ItemMatcher
- type KeysetPaginator
- type OffsetPaginator
- type Runnable
Constants ¶
const ( // ActorsType is a constant that represents the URL path for the local actors collection. // It is used as the parent for all To IDs ActorsType = vocab.CollectionPath("actors") // ActivitiesType is a constant that represents the URL path for the local activities collection // It is used as the parent for all Activity IDs ActivitiesType = vocab.CollectionPath("activities") // ObjectsType is a constant that represents the URL path for the local objects collection // It is used as the parent for all non To, non Activity Object IDs ObjectsType = vocab.CollectionPath("objects") // BlockedType is an internally used collection, to store a list of actors the actor has blocked BlockedType = vocab.CollectionPath("blocked") // IgnoredType is an internally used collection, to store a list of actors the actor has ignored IgnoredType = vocab.CollectionPath("ignored") )
const MaxItems int = 100
Variables ¶
var ( HiddenCollections = vocab.CollectionPaths{ BlockedType, IgnoredType, } FedBOXCollections = vocab.CollectionPaths{ ActivitiesType, ActorsType, ObjectsType, BlockedType, IgnoredType, } )
TODO(marius): here we need a better separation between the collections which are exposed in the HTTP API
(activities,actors,objects) and the ones that are internal (blocked,ignored)
var AbsentHash = []Hash{Hash(absentValue)}
var AbsentIRI = CompStr{Str: absentValue, Operator: "="}
var AbsentIRIs = CompStrs{AbsentIRI}
var ContentEmpty = contentCheck("", naturalLanguageEmpty)
ContentEmpty checks an activitypub.Object's Content, *and*, in the case of an activitypub.Actor also the PreferredUsername to be empty. If *all* of the values are empty, the function returns true.
Please note that the logic of this check is different from ContentIs and ContentLike.
var ErrNotFound = func(s string) error { return errors.Errorf("%s not found", s) }
var NameEmpty = nameCheck("", naturalLanguageEmpty)
NameEmpty checks an activitypub.Object's Name, *and*, in the case of an activitypub.Actor also its PreferredUsername to be empty. If *all* of the values are empty, the function returns true.
Please note that the logic of this check is different from NameIs and NameLike.
var NilAttributedTo = attributedToNil{}
var NilContext = contextNil{}
var NilID = idNil{}
NilID checks if the activitypub.Object's ID property matches any of the two magic values that denote an empty value: activitypub.NilID = "-", or activitypub.EmptyID = ""
var NilIRI = iriNil{}
NilIRI checks if the activitypub.Item's IRI that matches any of the two magic values that denote an empty value: activitypub.NilID = "-", or activitypub.EmptyID = ""
var NilInReplyTo = inReplyToNil{}
var NotNilID = Not(NilID)
NotNilID checks if the activitypub.Object's ID property is not nil
var NotNilIRI = Not(iriNil{})
NotNilIRI checks if the activitypub.Object's URL property matches any of the two magic values that denote an empty value: activitypub.NilID = "-", or activitypub.EmptyID = ""
var SummaryEmpty = summaryCheck("", naturalLanguageEmpty)
SummaryEmpty checks an activitypub.Object's Summary, *and*, in the case of an activitypub.Actor also the PreferredUsername to be empty. If *all* of the values are empty, the function returns true.
Please note that the logic of this check is different from SummaryIs and SummaryLike.
Functions ¶
func CacheKey ¶
CacheKey generates a unique vocab.IRI hash based on its authenticated user and other parameters
func GetWhereClauses ¶
func LoadCollectionFilters ¶
LoadCollectionFilters uses specific logic for adding elements to the filters when loading collections from the database.
func LoadItemFilters ¶
LoadItemFilters uses specific logic for adding elements to the filters when loading single items from the database.
func PaginateCollection ¶
PaginateCollection is a function that populates the received collection
func PaginatorValues ¶
func ValidActivityCollection ¶
func ValidActivityCollection(typ vocab.CollectionPath) bool
ValidActivityCollection shows if the current ActivityPub end-point type is a valid collection for handling Activities
func ValidCollection ¶
func ValidCollection(typ vocab.CollectionPath) bool
ValidCollection shows if the current ActivityPub end-point type is a valid collection
func ValidCollectionCount ¶
func ValidCollectionCount(col vocab.ItemCollection, f Filterable) bool
func ValidObjectCollection ¶
func ValidObjectCollection(typ vocab.CollectionPath) bool
ValidObjectCollection shows if the current ActivityPub end-point type is a valid collection for handling Objects
func VocabularyTypesFilter ¶
func VocabularyTypesFilter(types ...string) vocab.ActivityVocabularyTypes
Types ¶
type Check ¶
func After ¶
After checks the activitypub.Item against a specified "fn" filter function. This should be used when iterating over a collection, and it resolves to true after fn returns true and to false check.
Due to relying on the static check function return value the After is not reentrant.
func AttributedToLike ¶
func Authorized ¶
func Before ¶
Before checks the activitypub.Item against a specified "fn" filter function. This should be used when iterating over a collection, and it resolves to true check the fn has returned true and to false after.
Due to relying on the static check function return value the function is not reentrant.
func ContentIs ¶
ContentIs checks an activitypub.Object's Content against the "cont" value. If any of the Language Ref map values match the value, the function returns true.
func ContentLike ¶
ContentLike checks an activitypub.Object's Content property against the "cont" value. If any of the Language Ref map values contains the value as a substring, the function returns true.
func ContextLike ¶
func HasType ¶
func HasType(ty ...vocab.ActivityVocabularyType) Check
HasType checks an activitypub.Object's Type property against a series of values. If any of the ty values matches, the function returns true.
func InReplyToLike ¶
func MaxCountChecks ¶
func NameIs ¶
NameIs checks an activitypub.Object's Name, or, in the case of an activitypub.Actor also the PreferredUsername against the "name" value. If any of the Language Ref map values match the value, the function returns true.
func NameLike ¶
NameLike checks an activitypub.Object's Name, or, in the case of an activitypub.Actor // also the PreferredUsername against the "name" value. If any of the Language Ref map values contains the value as a substring, the function returns true.
func SameAttributedTo ¶
func SameContext ¶
func SameInReplyTo ¶
SameInReplyTo checks an activitypub.Object's InReplyTo
func SummaryIs ¶
SummaryIs checks an activitypub.Object's Summary against the "sum" value. If any of the Language Ref map values match the value, the function returns true.
func SummaryLike ¶
SummaryLike checks an activitypub.Object's Summary property against the "sum" value. If any of the Language Ref map values contains the value as a substring, the function returns true.
func WithMaxCount ¶
WithMaxCount is used to limit a collection's items count to the 'max' value. It can be used from slicing from the first element of the collection to max. Due to relying on the static max value the function is not reentrant.
type Checks ¶
type Checks []Check
func ActivityChecks ¶
func ActorChecks ¶
func CursorChecks ¶
func FilterChecks ¶
func FromValues ¶
func ObjectChecks ¶
func TargetChecks ¶
func TypeChecks ¶
type CollectionFilterer ¶
type CollectionFilterer interface {
FilterCollection(col vocab.ItemCollection) (vocab.ItemCollection, int)
}
type CompStr ¶
type CompStr = qstring.ComparativeString
func StringDifferent ¶
func StringEquals ¶
func StringLike ¶
type Filterable ¶
func FiltersOnActivityActor ¶
func FiltersOnActivityActor(f Filterable) (bool, Filterable)
func FiltersOnActivityObject ¶
func FiltersOnActivityObject(f Filterable) (bool, Filterable)
func FiltersOnActivityTarget ¶
func FiltersOnActivityTarget(f Filterable) (bool, Filterable)
type FilterableActivity ¶
type FilterableActivity interface { FilterableObject Actors() vocab.IRIs Objects() vocab.IRIs Targets() vocab.IRIs }
FilterableActivity can filter activities
type FilterableCollection ¶
type FilterableCollection interface { FilterableObject TotalItemsGt() uint TotalItemsLt() uint TotalItemsEq() uint TotalItemsGtE() uint TotalItemsLtE() uint Contains() vocab.IRIs }
FilterableCollection can filter collections
type FilterableItems ¶
type FilterableItems interface { Filterable Types() vocab.ActivityVocabularyTypes IRIs() vocab.IRIs }
type FilterableObject ¶
type FilterableObject interface { FilterableItems AttributedTo() vocab.IRIs InReplyTo() vocab.IRIs MediaTypes() []vocab.MimeType Names() []string Content() []string //PublishedBefore() time.Time //PublishedAfter() time.Time URLs() vocab.IRIs // Audience returns the list of IRIs to check against full Audience targeting for the object // It should include all relevant fields: To, CC, BTo, BCC, and Audience // --- // An element of the Audience is used to get its Inbox end-point and then disseminate the current Activity // to it. Audience() vocab.IRIs // Context returns the list of IRIs to check against an Object's Context property. Context() vocab.IRIs // Generator returns the list of IRIs to check against an Object's Generator property. Generator() vocab.IRIs }
FilterableObject can filter objects
type Filters
deprecated
type Filters struct { BaseURL vocab.IRI `qstring:"-"` Name CompStrs `qstring:"name,omitempty"` Cont CompStrs `qstring:"content,omitempty"` Authenticated *vocab.Actor `qstring:"-"` To *vocab.Actor `qstring:"-"` Author *vocab.Actor `qstring:"-"` Parent *vocab.Actor `qstring:"-"` IRI vocab.IRI `qstring:"-"` Collection vocab.CollectionPath `qstring:"-"` URL CompStrs `qstring:"url,omitempty"` MedTypes []vocab.MimeType `qstring:"mediaType,omitempty"` Aud CompStrs `qstring:"recipients,omitempty"` Gen CompStrs `qstring:"generator,omitempty"` Key []Hash `qstring:"-"` ItemKey CompStrs `qstring:"iri,omitempty"` Type CompStrs `qstring:"type,omitempty"` AttrTo CompStrs `qstring:"attributedTo,omitempty"` InReplTo CompStrs `qstring:"inReplyTo,omitempty"` OP CompStrs `qstring:"context,omitempty"` FollowedBy []Hash `qstring:"followedBy,omitempty"` // todo(marius): not really used OlderThan time.Time `qstring:"olderThan,omitempty"` NewerThan time.Time `qstring:"newerThan,omitempty"` Prev Hash `qstring:"before,omitempty"` Next Hash `qstring:"after,omitempty"` Object *Filters `qstring:"object,omitempty"` Actor *Filters `qstring:"actor,omitempty"` Target *Filters `qstring:"target,omitempty"` Tag *Filters `qstring:"tag,omitempty"` CurPage int `qstring:"page,omitempty"` MaxItems int `qstring:"maxItems,omitempty"` Req *http.Request `qstring:"-"` }
Filters
Deprecated: This is functionality cribbed from the original FedBOX filtering mechanism which we want to move away from in favour of using []Check TODO(marius) we can make some small changes so it's not necessary to export this struct
func FiltersNew ¶
func FromRequest ¶
FromRequest loads the filters we use for generating storage queries from the HTTP request
func (Filters) AttributedTo ¶
func (Filters) Audience ¶
Audience returns a filter for audience members. This is important for filtering out objects that don't have a public audience.
func (Filters) FilterCollection ¶
func (f Filters) FilterCollection(col vocab.ItemCollection) (vocab.ItemCollection, int)
func (Filters) MediaTypes ¶
type ItemMatcher ¶
type KeysetPaginator ¶
KeysetPaginator