Skip to content

cattle_grid.extensions.examples.recipients

Simple transformer type extension that adds the recipients and whether the activity is public to the data. You can include this transformer into cattle_grid by adding

cattle_grid.toml
[[extensions]]
module = "cattle_grid.extensions.examples.recipients"

to your configuration file.

transformer async

transformer(data)

The transformer

>>> from asyncio import run
>>> run(transformer({"raw": {"type": "Activity", "to": ["http://alice.example"]}}))
{'recipients': {'recipients': ['http://alice.example'], 'public': False}}
Source code in cattle_grid/extensions/examples/recipients.py
@extension.transform(inputs=["raw"], outputs=["recipients"])
async def transformer(data):
    """The transformer

    ```pycon
    >>> from asyncio import run
    >>> run(transformer({"raw": {"type": "Activity", "to": ["http://alice.example"]}}))
    {'recipients': {'recipients': ['http://alice.example'], 'public': False}}

    ```
    """
    raw = data.get("raw")
    recipients = recipients_for_object(raw)
    public = is_public(raw)

    return {"recipients": {"recipients": list(recipients), "public": public}}