mastodon

package
v0.0.0-...-54d5358 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2024 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package mastodon implements a Mastodon API service.

Index

Constants

View Source
const (
	PREVIEW_MAX_WIDTH  = 560
	PREVIEW_MAX_HEIGHT = 415
)

Variables

This section is empty.

Functions

func AccountsFamiliarFollowersShow

func AccountsFamiliarFollowersShow(env *Env, w http.ResponseWriter, req *http.Request) error

func AccountsFeaturedTagsShow

func AccountsFeaturedTagsShow(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsFollowersShow

func AccountsFollowersShow(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsFollowingShow

func AccountsFollowingShow(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsShow

func AccountsShow(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsShowListMembership

func AccountsShowListMembership(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsStatusesShow

func AccountsStatusesShow(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsUpdateCredentials

func AccountsUpdateCredentials(env *Env, w http.ResponseWriter, r *http.Request) error

func AccountsVerifyCredentials

func AccountsVerifyCredentials(env *Env, w http.ResponseWriter, r *http.Request) error

func AppsCreate

func AppsCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func BlocksCreate

func BlocksCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func BlocksDestroy

func BlocksDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func BlocksIndex

func BlocksIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func BookmarksCreate

func BookmarksCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func BookmarksDestroy

func BookmarksDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func BookmarksIndex

func BookmarksIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func ConversationsIndex

func ConversationsIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func DirectoryIndex

func DirectoryIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func EmojisIndex

func EmojisIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func FavouritesCreate

func FavouritesCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func FavouritesDestroy

func FavouritesDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func FavouritesIndex

func FavouritesIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func FiltersIndex

func FiltersIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func InstancesActivityShow

func InstancesActivityShow(env *Env, w http.ResponseWriter, r *http.Request) error

func InstancesDomainBlocksShow

func InstancesDomainBlocksShow(env *Env, w http.ResponseWriter, r *http.Request) error

func InstancesIndexV1

func InstancesIndexV1(env *Env, w http.ResponseWriter, r *http.Request) error

func InstancesIndexV2

func InstancesIndexV2(env *Env, w http.ResponseWriter, r *http.Request) error

func InstancesPeersShow

func InstancesPeersShow(env *Env, w http.ResponseWriter, r *http.Request) error

func InstancesRulesShow

func InstancesRulesShow(env *Env, w http.ResponseWriter, r *http.Request) error

func ListsAddMembers

func ListsAddMembers(env *Env, w http.ResponseWriter, r *http.Request) error

func ListsCreate

func ListsCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func ListsIndex

func ListsIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func ListsRemoveMembers

func ListsRemoveMembers(env *Env, w http.ResponseWriter, r *http.Request) error

func ListsShow

func ListsShow(env *Env, w http.ResponseWriter, r *http.Request) error

func ListsViewMembers

func ListsViewMembers(env *Env, w http.ResponseWriter, r *http.Request) error

func MarkersCreate

func MarkersCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func MarkersIndex

func MarkersIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func MutesCreate

func MutesCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func MutesDestroy

func MutesDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func MutesIndex

func MutesIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func NotificationsIndex

func NotificationsIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func PreferencesShow

func PreferencesShow(env *Env, w http.ResponseWriter, r *http.Request) error

func PushSubscriptionCreate

func PushSubscriptionCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func PushSubscriptionDestroy

func PushSubscriptionDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func PushSubscriptionShow

func PushSubscriptionShow(env *Env, w http.ResponseWriter, r *http.Request) error

func PushSubscriptionUpdate

func PushSubscriptionUpdate(env *Env, w http.ResponseWriter, r *http.Request) error

func RelationshipsCreate

func RelationshipsCreate(env *Env, w http.ResponseWriter, req *http.Request) error

func RelationshipsDestroy

func RelationshipsDestroy(env *Env, w http.ResponseWriter, req *http.Request) error

func RelationshipsShow

func RelationshipsShow(env *Env, w http.ResponseWriter, req *http.Request) error

func SearchIndex

func SearchIndex(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesContextsShow

func StatusesContextsShow(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesCreate

func StatusesCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesDestroy

func StatusesDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesFavouritesShow

func StatusesFavouritesShow(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesHistoryShow

func StatusesHistoryShow(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesReblogCreate

func StatusesReblogCreate(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesReblogDestroy

func StatusesReblogDestroy(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesReblogsShow

func StatusesReblogsShow(env *Env, w http.ResponseWriter, r *http.Request) error

func StatusesShow

func StatusesShow(env *Env, w http.ResponseWriter, r *http.Request) error

func StreamingHealth

func StreamingHealth(env *Env, w http.ResponseWriter, r *http.Request) error

func StreamingPublic

func StreamingPublic(env *Env, w http.ResponseWriter, r *http.Request) error

func StreamingWebsocket

func StreamingWebsocket(env *Env, w http.ResponseWriter, r *http.Request) error

func TimelinesHome

func TimelinesHome(env *Env, w http.ResponseWriter, r *http.Request) error

func TimelinesListShow

func TimelinesListShow(env *Env, w http.ResponseWriter, r *http.Request) error

func TimelinesPublic

func TimelinesPublic(env *Env, w http.ResponseWriter, r *http.Request) error

func TimelinesTagShow

func TimelinesTagShow(env *Env, w http.ResponseWriter, r *http.Request) error

Types

type Account

type Account struct {
	ID             snowflake.ID `json:"id,string"`
	Username       string       `json:"username"`
	Acct           string       `json:"acct"`
	DisplayName    string       `json:"display_name"`
	Locked         bool         `json:"locked"`
	Bot            bool         `json:"bot"`
	Discoverable   bool         `json:"discoverable"`
	Group          bool         `json:"group"`
	CreatedAt      string       `json:"created_at"`
	Note           string       `json:"note"`
	URL            string       `json:"url"`
	Avatar         string       `json:"avatar"`        // these four fields _cannot_ be blank
	AvatarStatic   string       `json:"avatar_static"` // if they are, various clients will consider the
	Header         string       `json:"header"`        // account to be invalid and ignore it or just go weird :grr:
	HeaderStatic   string       `json:"header_static"` // so they must be set to a default image.
	FollowersCount int32        `json:"followers_count"`
	FollowingCount int32        `json:"following_count"`
	StatusesCount  int32        `json:"statuses_count"`
	LastStatusAt   *string      `json:"last_status_at"`
	// NoIndex        bool             `json:"noindex"` // default false
	Emojis []map[string]any `json:"emojis"`
	Fields []Field          `json:"fields"`
}

type Alerts

type Alerts struct {
	Mention       bool `json:"mention"`
	Status        bool `json:"status"`
	Reblog        bool `json:"reblog"`
	Follow        bool `json:"follow"`
	FollowRequest bool `json:"follow_request"`
	Favourite     bool `json:"favourite"`
	Poll          bool `json:"poll"`
	Update        bool `json:"update"`
}

type Application

type Application struct {
	ID           snowflake.ID `json:"id,string"`
	Name         string       `json:"name"`
	Website      any          `json:"website"` // string or null
	RedirectURI  string       `json:"redirect_uri,omitempty"`
	VapidKey     string       `json:"vapid_key"`
	ClientID     string       `json:"client_id,omitempty"`
	ClientSecret string       `json:"client_secret,omitempty"`
}

type BoolOrBit

type BoolOrBit bool

BoolOrBit is a type that can be unmarshalled from a JSON boolean or a JSON string iOS Ivory v13102+ sends "status": "1" or "status": "0" instead of "status": true or "status": false Credit to @diligiant for figuring this out and providing the code

func (*BoolOrBit) UnmarshalJSON

func (b *BoolOrBit) UnmarshalJSON(data []byte) error

type CredentialAccount

type CredentialAccount struct {
	*Account
	Source Source `json:"source"`
	Role   *Role  `json:"role,omitempty"`
}

type Env

type Env struct {
	*gorm.DB
	*streaming.Mux
	Logger *slog.Logger
	Client *activitypub.Client
}

func (*Env) Log

func (e *Env) Log() *slog.Logger

type FamiliarFollowers

type FamiliarFollowers struct {
	ID       snowflake.ID `json:"id"`
	Accounts []*Account   `json:"accounts"`
}

type Field

type Field struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type List

type List struct {
	ID            snowflake.ID `json:"id,string"`
	Title         string       `json:"title"`
	RepliesPolicy string       `json:"replies_policy"`
}

type Marker

type Marker struct {
	LastReadID snowflake.ID `json:"last_read_id,string"`
	Version    int32        `json:"version"`
	UpdatedAt  string
}

https://docs.joinmastodon.org/entities/Marker/

type MediaAttachment

type MediaAttachment struct {
	ID               snowflake.ID `json:"id,string"`
	Type             string       `json:"type"`
	URL              string       `json:"url"`
	PreviewURL       string       `json:"preview_url,omitempty"`
	RemoteURL        any          `json:"remote_url,omitempty"`
	PreviewRemoteURL any          `json:"preview_remote_url,omitempty"`
	TextURL          any          `json:"text_url,omitempty"`
	Meta             Meta         `json:"meta"`
	Description      string       `json:"description,omitempty"`
	Blurhash         string       `json:"blurhash,omitempty"`
}

type Mention

type Mention struct {
	ID       snowflake.ID `json:"id,string"`
	URL      string       `json:"url"`
	Acct     string       `json:"acct"`
	Username string       `json:"username"`
}

Mention represents a mention of a user in the context of a status. https://docs.joinmastodon.org/entities/Status/#Mention

type Meta

type Meta struct {
	Original      *MetaFormat `json:"original,omitempty"`
	Small         *MetaFormat `json:"small,omitempty"`
	Focus         *MetaFocus  `json:"focus,omitempty"`
	Length        string      `json:"length,omitempty"`
	Duration      float64     `json:"duration,omitzero"`
	FPS           int         `json:"fps,omitzero"`
	Size          string      `json:"size,omitempty"`
	Width         int         `json:"width,omitzero"`
	Height        int         `json:"height,omitzero"`
	Aspect        float64     `json:"aspect,omitzero"`
	AudioEncode   string      `json:"audio_encode,omitempty"`
	AudioBitrate  string      `json:"audio_bitrate,omitempty"`
	AudioChannels string      `json:"audio_channels,omitempty"`
}

type MetaFocus

type MetaFocus struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

type MetaFormat

type MetaFormat struct {
	Width     int     `json:"width,omitempty"`
	Height    int     `json:"height,omitempty"`
	Size      string  `json:"size,omitempty"`
	Aspect    float64 `json:"aspect,omitzero"`
	FrameRate string  `json:"frame_rate,omitempty"`
	Duration  float64 `json:"duration,omitzero"`
	Bitrate   string  `json:"bitrate,omitempty"`
}

type Poll

type Poll struct {
	ID          snowflake.ID `json:"id,string"`
	ExpiresAt   string       `json:"expires_at"`
	Expired     bool         `json:"expired"`
	Multiple    bool         `json:"multiple"`
	VotesCount  int          `json:"votes_count"`
	VotersCount *int         `json:"voters_count"`
	Voted       bool         `json:"voted"`
	OwnVotes    []int        `json:"own_votes"`
	Options     []PollOption `json:"options"`
	Emojis      []any        `json:"emojis"`
}

https://docs.joinmastodon.org/entities/Poll/

type PollOption

type PollOption struct {
	Title      string `json:"title"`
	VotesCount int    `json:"votes_count"`
}

type Preferences

type Preferences struct {
	PostingDefaultVisibility string `json:"posting:default:visibility"`
	PostingDefaultSensitive  bool   `json:"posting:default:sensitive"`
	PostingDefaultLanguage   any    `json:"posting:default:language"`
	ReadingExpandMedia       string `json:"reading:expand:media"`
	ReadingExpandSpoilers    bool   `json:"reading:expand:spoilers"`
}

type Relationship

type Relationship struct {
	ID                  snowflake.ID `json:"id,string"`
	Following           bool         `json:"following"`
	ShowingReblogs      bool         `json:"showing_reblogs"`
	Notifying           bool         `json:"notifying"`
	FollowedBy          bool         `json:"followed_by"`
	Blocking            bool         `json:"blocking"`
	BlockedBy           bool         `json:"blocked_by"`
	Muting              bool         `json:"muting"`
	MutingNotifications bool         `json:"muting_notifications"`
	Requested           bool         `json:"requested"`
	DomainBlocking      bool         `json:"domain_blocking"`
	Endorsed            bool         `json:"endorsed"`
	Note                string       `json:"note"`
}

type Role

type Role struct {
	ID          uint32 `json:"id"`
	Name        string `json:"name"`
	Color       string `json:"color"`
	Position    int32  `json:"position"`
	Permissions uint32 `json:"permissions"`
	Highlighted bool   `json:"highlighted"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

type Serialiser

type Serialiser struct {
	// contains filtered or unexported fields
}

Seraliser contains methods to seralise various Mastodon REST API responses.

func NewSerialiser

func NewSerialiser(req *http.Request) Serialiser

func (*Serialiser) Account

func (s *Serialiser) Account(a *models.Actor) *Account

func (*Serialiser) Application

func (s *Serialiser) Application(a *models.Application) *Application

func (*Serialiser) CredentialAccount

func (s *Serialiser) CredentialAccount(a *models.Account) *CredentialAccount

func (*Serialiser) List

func (s *Serialiser) List(l *models.AccountList) *List

func (*Serialiser) Marker

func (s *Serialiser) Marker(m *models.AccountMarker) *Marker

func (*Serialiser) MediaAttachments

func (s *Serialiser) MediaAttachments(attachments []*models.Attachment) []*MediaAttachment

func (*Serialiser) Mentions

func (s *Serialiser) Mentions(mentions []models.StatusMention) []*Mention

func (*Serialiser) Poll

func (s *Serialiser) Poll(p *models.StatusPoll) *Poll

func (*Serialiser) Preferences

func (s *Serialiser) Preferences(prefs *models.AccountPreferences) *Preferences

func (*Serialiser) Relationship

func (s *Serialiser) Relationship(rel *models.Relationship) *Relationship

func (*Serialiser) Role

func (s *Serialiser) Role(ar *models.AccountRole) *Role

func (*Serialiser) Status

func (s *Serialiser) Status(st *models.Status) *Status

func (*Serialiser) StatusEdit

func (s *Serialiser) StatusEdit(st *models.Status) *StatusEdit

func (*Serialiser) Tags

func (s *Serialiser) Tags(tags []models.StatusTag) []*Tag

func (*Serialiser) WebPushSubscription

func (s *Serialiser) WebPushSubscription(sub *models.PushSubscription) *WebPushSubscription

type Source

type Source struct {
	Privacy             string           `json:"privacy"`
	Sensitive           bool             `json:"sensitive"`
	Language            string           `json:"language"`
	Note                string           `json:"note"`
	FollowRequestsCount int32            `json:"follow_requests_count"`
	Fields              []map[string]any `json:"fields"`
}

type Status

type Status struct {
	ID                 snowflake.ID       `json:"id,string"`
	CreatedAt          string             `json:"created_at"`
	InReplyToID        *snowflake.ID      `json:"in_reply_to_id,string"`
	InReplyToAccountID *snowflake.ID      `json:"in_reply_to_account_id,string"`
	Sensitive          bool               `json:"sensitive"`
	SpoilerText        string             `json:"spoiler_text"`
	Visibility         models.Visibility  `json:"visibility"`
	Language           any                `json:"language"`
	URI                string             `json:"uri"`
	URL                any                `json:"url"`
	RepliesCount       int                `json:"replies_count"`
	ReblogsCount       int                `json:"reblogs_count"`
	FavouritesCount    int                `json:"favourites_count"`
	EditedAt           any                `json:"edited_at"`
	Favourited         bool               `json:"favourited"`
	Reblogged          bool               `json:"reblogged"`
	Muted              bool               `json:"muted"`
	Pinned             bool               `json:"pinned"`
	Bookmarked         bool               `json:"bookmarked"`
	Content            string             `json:"content"`
	Filtered           []any              `json:"filtered,omitempty"`
	Reblog             *Status            `json:"reblog"`
	Application        any                `json:"application,omitempty"`
	Account            *Account           `json:"account"`
	MediaAttachments   []*MediaAttachment `json:"media_attachments"`
	Mentions           []*Mention         `json:"mentions"`
	Tags               []*Tag             `json:"tags"`
	Emojis             []any              `json:"emojis"`
	Card               any                `json:"card"`
	Poll               *Poll              `json:"poll"`
}

Status is a representation of a Mastodon Status object. https://docs.joinmastodon.org/entities/Status/

type StatusEdit

type StatusEdit struct {
	Content          string             `json:"content"`
	SpoilerText      string             `json:"spoiler_text"`
	Sensitive        bool               `json:"sensitive"`
	CreatedAt        string             `json:"created_at"` // updated_at if edited, created_at if original
	Account          *Account           `json:"account"`
	Poll             *Poll              `json:"poll"`
	MediaAttachments []*MediaAttachment `json:"media_attachments"`
	Emojis           []any              `json:"emojis"`
}

https://docs.joinmastodon.org/entities/StatusEdit/

type Tag

type Tag struct {
	Name    string           `json:"name"`
	URL     string           `json:"url"`
	History []map[string]any `json:"history,omitempty"`
}

Tag represents a hashtag in the context of a status. https://docs.joinmastodon.org/entities/Tag

type WebPushSubscription

type WebPushSubscription struct {
	ID        uint32 `json:"id"`
	Endpoint  string `json:"endpoint"`
	Alerts    Alerts `json:"alerts"`
	ServerKey string `json:"server_key"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL