Module activitypubdantic.models.activity

ACTIVITY PYDANTIC MODELS FOR VALIDATION

Documentation: https://www.w3.org/TR/activitystreams-vocabulary/#activity-types

Expand source code
# -*- coding: utf-8 -*-
"""
ACTIVITY PYDANTIC MODELS FOR VALIDATION \n
Documentation: https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
"""
# Import Pydantic models and types
from datetime import datetime
from pydantic import field_validator, model_validator
from typing import List, Literal, Union

# Import core models that are required for the actor definition
# Not all will be directly called
from activitypubdantic.models.core import (
    ActivityModel,
    CollectionModel,
    CollectionPageModel,
    ImageModel,
    IntransitiveActivityModel,
    LinkModel,
    PlaceModel,
    ObjectModel,
    validate_list_links_or_objects,
)


"""
ACTIVITY TYPES
"""


class AcceptModel(ActivityModel):
    """
    Indicates that the actor accepts the object.
    """

    # Type
    type: Literal["Accept"] = "Accept"


class TentativeAcceptModel(ActivityModel):
    """
    A specialization of Accept indicating that the acceptance is tentative.
    """

    # Type
    type: Literal["TentativeAccept"] = "TentativeAccept"


class AddModel(ActivityModel):
    """
    Indicates that the actor has added the object to the target.
    """

    # Type
    type: Literal["Add"] = "Add"


class ArriveModel(IntransitiveActivityModel):
    """
    An IntransitiveActivity that indicates that the actor has arrived at the location.
    """

    # Type
    type: Literal["Arrive"] = "Arrive"


class CreateModel(ActivityModel):
    """
    Indicates that the actor has created the object.
    """

    # Type
    type: Literal["Create"] = "Create"


class DeleteModel(ActivityModel):
    """
    Indicates that the actor has deleted the object.
    """

    # Type
    type: Literal["Delete"] = "Delete"


class FollowModel(ActivityModel):
    """
    Indicates that the actor is "following" the object.
    """

    # Type
    type: Literal["Follow"] = "Follow"


class IgnoreModel(ActivityModel):
    """
    Indicates that the actor is ignoring the object.
    """

    # Type
    type: Literal["Ignore"] = "Ignore"


class JoinModel(ActivityModel):
    """
    Indicates that the actor is joining the object.
    """

    # Type
    type: Literal["Join"] = "Join"


class LeaveModel(ActivityModel):
    """
    Indicates that the actor is leaving the object.
    """

    # Type
    type: Literal["Leave"] = "Leave"


class LikeModel(ActivityModel):
    """
    Indicates that the actor is likes the object.
    """

    # Type
    type: Literal["Like"] = "Like"


class OfferModel(ActivityModel):
    """
    Indicates that the actor is offering the object.
    """

    # Type
    type: Literal["Offer"] = "Offer"


class InviteModel(OfferModel):
    """
    A specialization of Offer in which the actor is extending
    an invitation for the object to the target.
    """

    # Type
    type: Literal["Invite"] = "Invite"


class RejectModel(ActivityModel):
    """
    Indicates that the actor is rejecting the object.
    """

    # Type
    type: Literal["Reject"] = "Reject"


class TentativeRejectModel(RejectModel):
    """
    A specialization of Reject in which the rejection is considered tentative.
    """

    # Type
    type: Literal["TentativeReject"] = "TentativeReject"


class RemoveModel(ActivityModel):
    """
    Indicates that the actor is removing the object.
    """

    # Type
    type: Literal["Remove"] = "Remove"


class UndoModel(ActivityModel):
    """
    Indicates that the actor is undoing the object.
    """

    # Type
    type: Literal["Undo"] = "Undo"


class UpdateModel(ActivityModel):
    """
    Indicates that the actor is updating the object.
    """

    # Type
    type: Literal["Update"] = "Update"


class ViewModel(ActivityModel):
    """
    Indicates that the actor is viewing the object.
    """

    # Type
    type: Literal["View"] = "View"


class ListenModel(ActivityModel):
    """
    Indicates that the actor is listening to the object.
    """

    # Type
    type: Literal["Listen"] = "Listen"


class ReadModel(ActivityModel):
    """
    Indicates that the actor is reading the object.
    """

    # Type
    type: Literal["Read"] = "Read"


class MoveModel(ActivityModel):
    """
    Indicates that the actor is moving the object from origin to target.
    """

    # Type
    type: Literal["Move"] = "Move"


class TravelModel(IntransitiveActivityModel):
    """
    Indicates that the actor is traveling from origin to target.
    """

    # Type
    type: Literal["Travel"] = "Travel"


class AnnounceModel(ActivityModel):
    """
    Indicates that the actor is calling the target's attention to the object.
    """

    # Type
    type: Literal["Announce"] = "Announce"


class BlockModel(IgnoreModel):
    """
    Indicates that the actor is blocking the object. Blocking is a stronger form of Ignore.
    """

    # Type
    type: Literal["Block"] = "Block"


class FlagModel(ActivityModel):
    """
    Flagging is defined in the sense common to many social platforms
    as reporting content as being inappropriate for any number of reasons.
    """

    # Type
    type: Literal["Flag"] = "Flag"


class DislikeModel(ActivityModel):
    """
    Indicates that the actor dislikes the object.
    """

    # Type
    type: Literal["Dislike"] = "Dislike"


class QuestionModel(IntransitiveActivityModel):
    """
    Represents a question being asked.
    Note, in Mastodon, this is an Object, not an Activity, with a "votersCount" property.
    """

    # Type
    type: Literal["Question"] = "Question"

    # Properties
    one_of: Union[None, List[Union[None, LinkModel, ObjectModel]]] = None
    any_of: Union[None, List[Union[None, LinkModel, ObjectModel]]] = None
    closed: Union[None, bool, datetime, LinkModel, ObjectModel] = None
    votersCount: Union[None, int] = None  # In Mastodon

    # Validation
    _question_list_of_links_or_objects = field_validator(
        "one_of", "any_of", mode="before"
    )(validate_list_links_or_objects)

    # Only one of one_of or any_of may be set
    @model_validator(mode="after")
    def _question_validate_one_of_or_any_of(cls, m: "QuestionModel"):
        any_of = m.any_of
        one_of = m.one_of
        if any_of and one_of:
            raise ValueError("Only one of the answer types may be set.")
        return m

Classes

class AcceptModel (id: HttpUrl = None, **kwargs)

Indicates that the actor accepts the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class AcceptModel(ActivityModel):
    """
    Indicates that the actor accepts the object.
    """

    # Type
    type: Literal["Accept"] = "Accept"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Accept']
class AddModel (id: HttpUrl = None, **kwargs)

Indicates that the actor has added the object to the target.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class AddModel(ActivityModel):
    """
    Indicates that the actor has added the object to the target.
    """

    # Type
    type: Literal["Add"] = "Add"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Add']
class AnnounceModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is calling the target's attention to the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class AnnounceModel(ActivityModel):
    """
    Indicates that the actor is calling the target's attention to the object.
    """

    # Type
    type: Literal["Announce"] = "Announce"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Announce']
class ArriveModel (id: HttpUrl = None, **kwargs)

An IntransitiveActivity that indicates that the actor has arrived at the location.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class ArriveModel(IntransitiveActivityModel):
    """
    An IntransitiveActivity that indicates that the actor has arrived at the location.
    """

    # Type
    type: Literal["Arrive"] = "Arrive"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Arrive']
class BlockModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is blocking the object. Blocking is a stronger form of Ignore.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class BlockModel(IgnoreModel):
    """
    Indicates that the actor is blocking the object. Blocking is a stronger form of Ignore.
    """

    # Type
    type: Literal["Block"] = "Block"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Block']
class CreateModel (id: HttpUrl = None, **kwargs)

Indicates that the actor has created the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class CreateModel(ActivityModel):
    """
    Indicates that the actor has created the object.
    """

    # Type
    type: Literal["Create"] = "Create"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Create']
class DeleteModel (id: HttpUrl = None, **kwargs)

Indicates that the actor has deleted the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class DeleteModel(ActivityModel):
    """
    Indicates that the actor has deleted the object.
    """

    # Type
    type: Literal["Delete"] = "Delete"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Delete']
class DislikeModel (id: HttpUrl = None, **kwargs)

Indicates that the actor dislikes the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class DislikeModel(ActivityModel):
    """
    Indicates that the actor dislikes the object.
    """

    # Type
    type: Literal["Dislike"] = "Dislike"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Dislike']
class FlagModel (id: HttpUrl = None, **kwargs)

Flagging is defined in the sense common to many social platforms as reporting content as being inappropriate for any number of reasons.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class FlagModel(ActivityModel):
    """
    Flagging is defined in the sense common to many social platforms
    as reporting content as being inappropriate for any number of reasons.
    """

    # Type
    type: Literal["Flag"] = "Flag"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Flag']
class FollowModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is "following" the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class FollowModel(ActivityModel):
    """
    Indicates that the actor is "following" the object.
    """

    # Type
    type: Literal["Follow"] = "Follow"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Follow']
class IgnoreModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is ignoring the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class IgnoreModel(ActivityModel):
    """
    Indicates that the actor is ignoring the object.
    """

    # Type
    type: Literal["Ignore"] = "Ignore"

Ancestors

Subclasses

Class variables

var model_config
var model_fields
var type : Literal['Ignore']
class InviteModel (id: HttpUrl = None, **kwargs)

A specialization of Offer in which the actor is extending an invitation for the object to the target.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class InviteModel(OfferModel):
    """
    A specialization of Offer in which the actor is extending
    an invitation for the object to the target.
    """

    # Type
    type: Literal["Invite"] = "Invite"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Invite']
class JoinModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is joining the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class JoinModel(ActivityModel):
    """
    Indicates that the actor is joining the object.
    """

    # Type
    type: Literal["Join"] = "Join"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Join']
class LeaveModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is leaving the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class LeaveModel(ActivityModel):
    """
    Indicates that the actor is leaving the object.
    """

    # Type
    type: Literal["Leave"] = "Leave"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Leave']
class LikeModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is likes the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class LikeModel(ActivityModel):
    """
    Indicates that the actor is likes the object.
    """

    # Type
    type: Literal["Like"] = "Like"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Like']
class ListenModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is listening to the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class ListenModel(ActivityModel):
    """
    Indicates that the actor is listening to the object.
    """

    # Type
    type: Literal["Listen"] = "Listen"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Listen']
class MoveModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is moving the object from origin to target.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class MoveModel(ActivityModel):
    """
    Indicates that the actor is moving the object from origin to target.
    """

    # Type
    type: Literal["Move"] = "Move"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Move']
class OfferModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is offering the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class OfferModel(ActivityModel):
    """
    Indicates that the actor is offering the object.
    """

    # Type
    type: Literal["Offer"] = "Offer"

Ancestors

Subclasses

Class variables

var model_config
var model_fields
var type : Literal['Offer']
class QuestionModel (id: HttpUrl = None, **kwargs)

Represents a question being asked. Note, in Mastodon, this is an Object, not an Activity, with a "votersCount" property.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class QuestionModel(IntransitiveActivityModel):
    """
    Represents a question being asked.
    Note, in Mastodon, this is an Object, not an Activity, with a "votersCount" property.
    """

    # Type
    type: Literal["Question"] = "Question"

    # Properties
    one_of: Union[None, List[Union[None, LinkModel, ObjectModel]]] = None
    any_of: Union[None, List[Union[None, LinkModel, ObjectModel]]] = None
    closed: Union[None, bool, datetime, LinkModel, ObjectModel] = None
    votersCount: Union[None, int] = None  # In Mastodon

    # Validation
    _question_list_of_links_or_objects = field_validator(
        "one_of", "any_of", mode="before"
    )(validate_list_links_or_objects)

    # Only one of one_of or any_of may be set
    @model_validator(mode="after")
    def _question_validate_one_of_or_any_of(cls, m: "QuestionModel"):
        any_of = m.any_of
        one_of = m.one_of
        if any_of and one_of:
            raise ValueError("Only one of the answer types may be set.")
        return m

Ancestors

Class variables

var any_of : Optional[None]
var closed : Union[None, bool, datetime.datetime, LinkModelObjectModel]
var model_config
var model_fields
var one_of : Optional[None]
var type : Literal['Question']
var votersCount : Optional[None]
class ReadModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is reading the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class ReadModel(ActivityModel):
    """
    Indicates that the actor is reading the object.
    """

    # Type
    type: Literal["Read"] = "Read"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Read']
class RejectModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is rejecting the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class RejectModel(ActivityModel):
    """
    Indicates that the actor is rejecting the object.
    """

    # Type
    type: Literal["Reject"] = "Reject"

Ancestors

Subclasses

Class variables

var model_config
var model_fields
var type : Literal['Reject']
class RemoveModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is removing the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class RemoveModel(ActivityModel):
    """
    Indicates that the actor is removing the object.
    """

    # Type
    type: Literal["Remove"] = "Remove"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Remove']
class TentativeAcceptModel (id: HttpUrl = None, **kwargs)

A specialization of Accept indicating that the acceptance is tentative.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class TentativeAcceptModel(ActivityModel):
    """
    A specialization of Accept indicating that the acceptance is tentative.
    """

    # Type
    type: Literal["TentativeAccept"] = "TentativeAccept"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['TentativeAccept']
class TentativeRejectModel (id: HttpUrl = None, **kwargs)

A specialization of Reject in which the rejection is considered tentative.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class TentativeRejectModel(RejectModel):
    """
    A specialization of Reject in which the rejection is considered tentative.
    """

    # Type
    type: Literal["TentativeReject"] = "TentativeReject"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['TentativeReject']
class TravelModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is traveling from origin to target.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class TravelModel(IntransitiveActivityModel):
    """
    Indicates that the actor is traveling from origin to target.
    """

    # Type
    type: Literal["Travel"] = "Travel"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Travel']
class UndoModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is undoing the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class UndoModel(ActivityModel):
    """
    Indicates that the actor is undoing the object.
    """

    # Type
    type: Literal["Undo"] = "Undo"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Undo']
class UpdateModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is updating the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class UpdateModel(ActivityModel):
    """
    Indicates that the actor is updating the object.
    """

    # Type
    type: Literal["Update"] = "Update"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['Update']
class ViewModel (id: HttpUrl = None, **kwargs)

Indicates that the actor is viewing the object.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Expand source code
class ViewModel(ActivityModel):
    """
    Indicates that the actor is viewing the object.
    """

    # Type
    type: Literal["View"] = "View"

Ancestors

Class variables

var model_config
var model_fields
var type : Literal['View']