Skip to content

fediverse_pasture.types

fediverse_pasture.types

MessageModifier = Callable[[dict], dict] module-attribute

Used to add the variable content to an activity pub message. The intended usage can be seen in the ActivitySender.init_create_note method.

ApplicationAdapterForActor dataclass

Basic type that is used to describe how to interact with an external application. actor_uri represents the actor a message will be sent to.

Parameters:

Name Type Description Default
actor_uri str

The actor uri

required
application_name str

The name the application will be displayed as

required
Source code in fediverse_pasture/types.py
@dataclass
class ApplicationAdapterForActor:
    """Basic type that is used to describe how to interact with
    an external application. actor_uri represents the actor
    a message will be sent to.
    """

    actor_uri: str = field(metadata={"description": "The actor uri"})
    application_name: str = field(
        metadata={"description": "The name the application will be displayed as"}
    )

ApplicationAdapterForLastActivity dataclass

Basic type that is used to describe how to interact with an external application. actor_uri represents the actor a message will be sent to. fetch_activity is used to fetch this activity.

Parameters:

Name Type Description Default
actor_uri str

The actor uri

required
application_name str

The name the application will be displayed as

required
fetch_activity Callable[list, Awaitable[Optional[dict]]]

coroutine that retrieves the activity with a specified published date.

required
Source code in fediverse_pasture/types.py
@dataclass
class ApplicationAdapterForLastActivity:
    """Basic type that is used to describe how to interact with
    an external application. actor_uri represents the actor
    a message will be sent to. fetch_activity is used to
    fetch this activity.
    """

    actor_uri: str = field(metadata={"description": "The actor uri"})
    application_name: str = field(
        metadata={"description": "The name the application will be displayed as"}
    )
    fetch_activity: Callable[[datetime], Awaitable[dict | None]] = field(
        metadata={
            "description": "coroutine that retrieves the activity with a specified published date."
        }
    )

Message dataclass

Class to track messages

Parameters:

Name Type Description Default
steps List[str]

a log of strings

<dynamic>
Source code in fediverse_pasture/types.py
@dataclass
class Message:
    """Class to track messages"""

    steps: List[str] = field(
        default_factory=list, metadata={"description": "a log of strings"}
    )

    def add(self, msg):
        """Adds a message to steps and logs it to info"""
        logger.info(msg)
        self.steps.append(msg)

    def error(self, msg):
        """Logs an error and returns a message object"""
        logger.error(msg)
        return {"x error": msg, **self.response}

    @property
    def response(self):
        """Returns a dictionary with a single key "steps" containing the steps"""
        return {"steps": self.steps}

response property

Returns a dictionary with a single key “steps” containing the steps

add(msg)

Adds a message to steps and logs it to info

Source code in fediverse_pasture/types.py
def add(self, msg):
    """Adds a message to steps and logs it to info"""
    logger.info(msg)
    self.steps.append(msg)

error(msg)

Logs an error and returns a message object

Source code in fediverse_pasture/types.py
def error(self, msg):
    """Logs an error and returns a message object"""
    logger.error(msg)
    return {"x error": msg, **self.response}