ActivityPub.Utils (Bonfire v1.0.2-social-alpha.31)
View SourceMisc functions used for federation
Summary
Functions
Checks if any of the given labels exist in any of the given collections. Supports both single values and lists for labels and collections.
Generates a consistent cache key for ActivityPub cache buckets.
Calculates a TTL (in seconds) for caching based on the published date of an object. If the published date is in the future, returns the number of seconds until then (plus a small buffer). Otherwise, returns the default TTL (nil).
Format according to RFC 1123, which is the standard for HTTP dates. Example: Mon, 15 Apr 2025 14:30:15 GMT
Takes a string and returns true if it is a valid UUID (Universally Unique Identifier)
conditionally update a map
Handles multiple cases where the input value is of a different type (atom, list, tuple, etc.) and returns a string representation of it.
Determines if an object or an activity is public.
Takes a map or keyword list, and returns a map with any atom keys converted to string keys. It can optionally do so recursively.
Functions
Checks if any of the given labels exist in any of the given collections. Supports both single values and lists for labels and collections.
Generates a consistent cache key for ActivityPub cache buckets.
Examples
iex> ActivityPub.Utils.ap_cache_key(:pointer, "01K62V27CP9Z5B0AP231QSY199")
"abc123:pointer:01K62V27CP9Z5B0AP231QSY199"
Calculates a TTL (in seconds) for caching based on the published date of an object. If the published date is in the future, returns the number of seconds until then (plus a small buffer). Otherwise, returns the default TTL (nil).
Examples
iex> ActivityPub.Utils.cache_ttl_from_published(%{"published" => DateTime.to_iso8601(DateTime.add(DateTime.utc_now(), 10))})
10..15
iex> ActivityPub.Utils.cache_ttl_from_published(%{"published" => DateTime.to_iso8601(DateTime.add(DateTime.utc_now(), -10))})
nil
Format according to RFC 1123, which is the standard for HTTP dates. Example: Mon, 15 Apr 2025 14:30:15 GMT
Takes a string and returns true if it is a valid UUID (Universally Unique Identifier)
conditionally update a map
Handles multiple cases where the input value is of a different type (atom, list, tuple, etc.) and returns a string representation of it.
Determines if an object or an activity is public.
Takes a map or keyword list, and returns a map with any atom keys converted to string keys. It can optionally do so recursively.