anderssorby / elm-mastodon / Mastodon.Entity

The Mastodon API entities.

These are JSON-encoded over the wire. Mastodon.EncodeDecode knows how to do that.

Documented at https://docs.joinmastodon.org/api/entities/

Most of the Entity have a v field, which is the raw JS value from which it was decoded. This is useful if you want to display what you got over the wire. Code that creates these can set it to Json.Encode.null.

Entity


type Entity
    = NoEntity
    | AccountEntity Account
    | AccountListEntity (List Account)
    | SourceEntity Source
    | TokenEntity Token
    | ApplicationEntity Application
    | AppEntity App
    | CardEntity Card
    | ContextEntity Context
    | EmojiEntity Emoji
    | EmojiListEntity (List Emoji)
    | ErrorEntity Error
    | FilterEntity Filter
    | FilterListEntity (List Filter)
    | InstanceEntity Instance
    | ActivityEntity Activity
    | ActivityListEntity (List Activity)
    | PeersEntity (List String)
    | ListEntityEntity ListEntity
    | ListEntityListEntity (List ListEntity)
    | AttachmentEntity Attachment
    | AttachmentListEntity (List Attachment)
    | NotificationEntity Notification
    | NotificationListEntity (List Notification)
    | PushSubscriptionEntity PushSubscription
    | RelationshipEntity Relationship
    | RelationshipListEntity (List Relationship)
    | ResultsEntity Results
    | StatusEntity Status
    | PollEntity Poll
    | StatusListEntity (List Status)
    | ScheduledStatusEntity ScheduledStatus
    | ScheduledStatusListEntity (List ScheduledStatus)
    | ConversationEntity Conversation
    | ConversationListEntity (List Conversation)
    | GroupEntity Group
    | GroupRelationshipEntity GroupRelationship
    | GroupRelationshipListEntity (List GroupRelationship)
    | GroupListEntity (List Group)
    | StringListEntity (List String)
    | TagListEntity (List Tag)
    | ValueEntity Json.Encode.Value

One type to rule them all.

This is mostly to make tests easier to define. Most code will use individual entities explicitly.

String aliases


type alias Datetime =
String

Alias of String


type alias UrlString =
String

Alias of String


type alias HtmlString =
String

Alias of String


type alias ISO6391 =
String

Alias of String


type alias ISO6392 =
String

Alias of String


type alias UnixTimestamp =
String

Alias of String

Entities


type alias Account =
{ id : String
, username : String
, acct : String
, display_name : String
, locked : Basics.Bool
, created_at : Datetime
, followers_count : Basics.Int
, following_count : Basics.Int
, statuses_count : Basics.Int
, note : String
, url : UrlString
, avatar : UrlString
, avatar_static : UrlString
, header : UrlString
, header_static : UrlString
, emojis : List Emoji
, moved : Maybe WrappedAccount
, fields : List Field
, bot : Basics.Bool
, source : Maybe Source
, v : Json.Encode.Value 
}

Account entity

Pleroma servers have an additional field here, not yet supported:

"pleroma":{"tags":[],
           "skip_thread_containment":false,
           "settings_store":{},
           "relationship":{"subscribing":false,
                           "showing_reblogs":true,
                           "requested":false,
                           "muting_notifications":false,
                           "muting":false,
                           "id":"9kL2555DTtECY9TEQK",
                           "following":true,
                           "followed_by":true,
                           "endorsed":false,
                           "domain_blocking":false,
                           "blocking":false
                          }


type alias Source =
{ privacy : Privacy
, sensitive : Basics.Bool
, language : Maybe ISO6391
, note : String
, fields : List Field
, v : Json.Encode.Value 
}

Source entity.

Pleroma servers have an additional field here, not yet supported:

"pleroma":{"show_role":true,"no_rich_text":false}


type alias Token =
{ access_token : String
, token_type : String
, scope : String
, created_at : Basics.Int
, v : Json.Encode.Value 
}

Token entity.


type alias Application =
{ name : String
, website : Maybe UrlString
, v : Json.Encode.Value 
}

Application entity.


type alias App =
{ id : String
, name : String
, website : Maybe String
, redirect_uri : String
, client_id : String
, client_secret : String
, vapid_key : Maybe String
, v : Json.Encode.Value 
}

App entity.

This is not documented, so I requested one and reverse engineered it.


type alias Card =
{ url : UrlString
, title : String
, description : String
, image : Maybe UrlString
, type_ : CardType
, author_name : Maybe String
, author_url : Maybe UrlString
, provider_name : Maybe String
, provider_url : Maybe UrlString
, html : Maybe HtmlString
, width : Maybe Basics.Int
, height : Maybe Basics.Int
, v : Json.Encode.Value 
}

Card entity.


type alias Context =
{ ancestors : List Status
, descendants : List Status 
}

Context entity.


type alias Error =
{ httpStatus : String
, error : String 
}

Error entity.


type alias Filter =
{ id : String
, phrase : String
, context : List FilterContext
, expires_at : Maybe Datetime
, irreversible : Basics.Bool
, whole_word : Basics.Bool
, v : Json.Encode.Value 
}

Filter entity.


type alias Instance =
{ uri : String
, title : String
, description : String
, email : String
, version : String
, thumbnail : Maybe UrlString
, urls : Maybe URLs
, stats : Stats
, max_toot_chars : Maybe Basics.Int
, languages : List ISO6391
, contact_account : Maybe Account
, v : Json.Encode.Value 
}

Instance entity.


type alias Activity =
{ week : Basics.Int
, statuses : Basics.Int
, logins : Maybe Basics.Int
, registrations : Basics.Int
, v : Json.Encode.Value 
}

Activity entity.

Not documented. A list of these is returned by "GET instance/activity"


type alias ListEntity =
{ id : String
, title : String 
}

List entity.


type alias Notification =
{ id : String
, type_ : NotificationType
, created_at : Datetime
, account : Account
, status : Maybe Status
, v : Json.Encode.Value 
}

Notification entity.


type alias PushSubscription =
{ id : String
, endpoint : UrlString
, server_key : String
, alerts : Json.Encode.Value
, v : Json.Encode.Value 
}

Push subscription entity.


type alias Relationship =
{ id : String
, following : Basics.Bool
, followed_by : Basics.Bool
, blocking : Basics.Bool
, muting : Basics.Bool
, muting_notifications : Basics.Bool
, requested : Basics.Bool
, domain_blocking : Basics.Bool
, showing_reblogs : Basics.Bool
, endorsed : Basics.Bool
, v : Json.Encode.Value 
}

Relationship entity.


type alias Results =
{ accounts : List Account
, statuses : List Status
, hashtags : List String
, groups : List Group
, v : Json.Encode.Value 
}

Results entity.


type alias Status =
{ id : String
, uri : String
, url : Maybe UrlString
, account : Account
, in_reply_to_id : Maybe String
, in_reply_to_account_id : Maybe String
, reblog : Maybe WrappedStatus
, content : HtmlString
, plain_markdown : Maybe String
, plain_text : Maybe String
, created_at : Datetime
, emojis : List Emoji
, replies_count : Basics.Int
, reblogs_count : Basics.Int
, favourites_count : Basics.Int
, reblogged : Basics.Bool
, favourited : Basics.Bool
, muted : Basics.Bool
, sensitive : Basics.Bool
, spoiler_text : String
, visibility : Visibility
, media_attachments : List Attachment
, mentions : List Mention
, tags : List Tag
, card : Maybe Card
, poll : Maybe Poll
, application : Maybe Application
, language : Maybe String
, pinned : Basics.Bool
, group : Maybe Group
, quote_of_id : Maybe String
, quote : Maybe WrappedStatus
, v : Json.Encode.Value 
}

Status entity.

The plain_markdown and plain_text fields are elm-mastodon additions.

content is the HTML to display. plain_markdown is the markdown the user entered, if it is available. plain_text is the unformatted text, if it is available.


type alias RawStatus =
{ plain_markdown : Maybe String
, rich_content : Maybe String
, pleroma : Maybe PleromaStatusContent
, v : Json.Encode.Value 
}

RawStatus entity.

Extra Status fields that are not returned by all servers.


type alias ScheduledStatus =
{ id : String
, scheduled_at : Datetime
, params : StatusParams
, media_attachments : List Attachment
, v : Json.Encode.Value 
}

ScheduledStatus entity.


type alias Conversation =
{ id : String
, accounts : List Account
, last_status : Maybe Status
, unread : Basics.Bool
, v : Json.Encode.Value 
}

Conversation entity.


type alias Group =
{ id : String
, title : String
, description : String
, cover_image_url : String
, is_archived : Basics.Bool
, member_count : Basics.Int
, v : Json.Encode.Value 
}

Group entity.


type alias GroupRelationship =
{ id : String
, member : Basics.Bool
, admin : Basics.Bool
, unread_count : Basics.Int
, v : Json.Encode.Value 
}

Group relationship entity.

Entity field types


type alias Emoji =
{ shortcode : String
, static_url : UrlString
, url : UrlString
, visible_in_picker : Basics.Bool 
}

Values for the Account.emojis list. Also returned by /api/v1/custom_emojis.


type alias Field =
{ name : String
, value : HtmlString
, verified_at : Maybe Datetime 
}

Values for the Account.fields and Source.fields lists.


type Privacy
    = PublicPrivacy
    | UnlistedPrivacy
    | PrivatePrivacy

Values for Source.privacy


type alias Attachment =
{ id : String
, type_ : AttachmentType
, url : UrlString
, remote_url : Maybe UrlString
, preview_url : Maybe UrlString
, text_url : Maybe UrlString
, meta : Maybe Meta
, description : Maybe String
, v : Json.Encode.Value 
}

Element of Status.media_attachments and ScheduledStatus.media_attachments.

Note that it's possible to create an Attachment whose type_ disagrees with its meta. Maybe I should have represented it to prevent that, but I chose to mostly match the JSON.


type AttachmentType
    = UnknownAttachment
    | ImageAttachment
    | GifvAttachment
    | VideoAttachment
    | AudioAttachment
    | UnrecognizedAttachment String

Types for the Attachment.type_ field.


type Meta
    = ImageMeta ImageMetaFields
    | VideoMeta VideoMetaFields

Value for Attachment.meta


type alias ImageMetaFields =
{ small : Maybe ImageMetaInfo
, original : Maybe ImageMetaInfo
, focus : Maybe Focus 
}

Fields for an ImageMeta.


type alias VideoMetaFields =
{ small : Maybe VideoMetaInfo
, original : Maybe VideoMetaInfo
, focus : Maybe Focus 
}

Fields for a VideoMeta.


type alias ImageMetaInfo =
{ width : Maybe Basics.Int
, height : Maybe Basics.Int
, size : Maybe String
, aspect : Maybe Basics.Float 
}

Values for ImageMetaFields.small and ImageMetaFields.original


type alias VideoMetaInfo =
{ width : Maybe Basics.Int
, height : Maybe Basics.Int
, frame_rate : Maybe String
, duration : Maybe Basics.Float
, bitrate : Maybe Basics.Int 
}

Values for VideoMetaFields.small and VideoMetaFields.original


type alias Focus =
{ x : Basics.Float, y : Basics.Float }

The optional focus of an image attachment.


type CardType
    = LinkCard
    | PhotoCard
    | VideoCard
    | RichCard

Choices for the Card.type_ field.


type FilterContext
    = HomeContext
    | NotificationsContext
    | PublicContext
    | ThreadContext

Choices for the Filter.context list.


type alias URLs =
{ streaming_api : UrlString }

Value of Instance.urls.


type alias Stats =
{ user_count : Basics.Int
, status_count : Basics.Int
, domain_count : Basics.Int 
}

Value of Instance.stats.


type NotificationType
    = FollowNotification
    | MentionNotification
    | ReblogNotification
    | FavouriteNotification
    | PollNotification
    | FollowRequestNotification
    | UnknownNotification String

Choices for Notification.type_.


type Visibility
    = PublicVisibility
    | UnlistedVisibility
    | PrivateVisibility
    | DirectVisibility
    | PrivateGroupVisibility

Values for Status.visibility.


type alias Mention =
{ url : UrlString
, username : String
, acct : String
, id : String 
}

Values in Status.mentions.


type alias Tag =
{ name : String
, url : UrlString
, history : List History 
}

Elements of Results.hashtags and Status.tags.


type alias History =
{ day : UnixTimestamp
, uses : Basics.Int
, accounts : Basics.Int 
}

Value for Tag.history.


type alias Poll =
{ id : String
, expires_at : Maybe Datetime
, expired : Basics.Bool
, multiple : Basics.Bool
, votes_count : Basics.Int
, options : List PollOption
, voted : Basics.Bool
, v : Json.Encode.Value 
}

Value for Status.poll, and an Entity in its own right.


type alias PollOption =
{ title : String
, votes_count : Basics.Int 
}

Elements of the Poll.options list.


type alias StatusParams =
{ text : String
, in_reply_to_id : Maybe String
, media_ids : List String
, sensitive : Basics.Bool
, spoiler_text : Maybe String
, visibility : Maybe Visibility
, scheduled_at : Maybe Datetime
, application_id : String 
}

Elements of ScheduledStatus.params.


type alias PleromaStatusContent =
{ content : { plain_text : String } }

The pleroma field of a RawStatus entity (Pleroma only).

Authorization parameters


type alias Authorization =
{ clientId : String
, clientSecret : String
, token : String 
}

Authorization Parameters.

Applications will usually save this in localStorage, use the saved token until it expires, then use the client ID and secret to mint a new authorization.

The authorization is usually of the type "Bearer ".

Wrappers to prevent type recursion


type WrappedAccount
    = WrappedAccount Account

Wrapped Account, to prevent type recursion.


type WrappedStatus
    = WrappedStatus Status

Wrapped Status, to prevent type recursion.