ap

package
v0.0.0-...-ec5862a Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ap implements types that represent the ActivityPub vocabulary.

These types implement database/sql.Scanner and database/sql/driver.Valuer, allowing them to be stored in a SQL database as a JSON column.

Index

Constants

View Source
const Public = "https://www.w3.org/ns/activitystreams#Public"

Public is the special ActivityPub collection used for public addressing.

Variables

View Source
var ErrInvalidActivity = errors.New("invalid activity")

Functions

This section is empty.

Types

type Activity

type Activity struct {
	Context   any          `json:"@context,omitempty"`
	ID        string       `json:"id"`
	Type      ActivityType `json:"type"`
	Actor     string       `json:"actor"`
	Object    any          `json:"object"`
	Target    string       `json:"target,omitempty"`
	To        Audience     `json:"to,omitempty"`
	CC        Audience     `json:"cc,omitempty"`
	Published Time         `json:"published,omitempty"`
}

Activity represents an ActivityPub activity. Object can point to another Activity, an Object or a string.

func (*Activity) IsPublic

func (a *Activity) IsPublic() bool

func (*Activity) LogValue

func (a *Activity) LogValue() slog.Value

func (*Activity) Scan

func (a *Activity) Scan(src any) error

func (*Activity) UnmarshalJSON

func (a *Activity) UnmarshalJSON(b []byte) error

func (*Activity) Value

func (a *Activity) Value() (driver.Value, error)

type ActivityType

type ActivityType string
const (
	Create   ActivityType = "Create"
	Follow   ActivityType = "Follow"
	Accept   ActivityType = "Accept"
	Undo     ActivityType = "Undo"
	Delete   ActivityType = "Delete"
	Announce ActivityType = "Announce"
	Update   ActivityType = "Update"
	Like     ActivityType = "Like"
	Move     ActivityType = "Move"
)

type Actor

type Actor struct {
	Context                   any               `json:"@context"`
	ID                        string            `json:"id"`
	Type                      ActorType         `json:"type"`
	Inbox                     string            `json:"inbox"`
	Outbox                    string            `json:"outbox"`
	Endpoints                 map[string]string `json:"endpoints,omitempty"`
	PreferredUsername         string            `json:"preferredUsername"`
	Name                      string            `json:"name,omitempty"`
	Summary                   string            `json:"summary,omitempty"`
	Followers                 string            `json:"followers,omitempty"`
	PublicKey                 PublicKey         `json:"publicKey"`
	Icon                      Array[Attachment] `json:"icon,omitempty"`
	Image                     Attachment        `json:"image,omitempty"`
	ManuallyApprovesFollowers bool              `json:"manuallyApprovesFollowers"`
	AlsoKnownAs               Audience          `json:"alsoKnownAs,omitempty"`
	Published                 *Time             `json:"published"`
	Updated                   *Time             `json:"updated,omitempty"`
	MovedTo                   string            `json:"movedTo,omitempty"`
	Suspended                 bool              `json:"suspended,omitempty"`
	Attachment                []Attachment      `json:"attachment,omitempty"`
}

Actor represents an ActivityPub actor.

func (*Actor) Scan

func (a *Actor) Scan(src any) error

func (*Actor) Value

func (a *Actor) Value() (driver.Value, error)

type ActorType

type ActorType string
const (
	Person ActorType = "Person"
	Group  ActorType = "Group"
)

type Array

type Array[T any] []T

Array is an array or a single item.

func (Array[T]) MarshalJSON

func (a Array[T]) MarshalJSON() ([]byte, error)

func (*Array[T]) UnmarshalJSON

func (a *Array[T]) UnmarshalJSON(b []byte) error

type Attachment

type Attachment struct {
	Type      AttachmentType `json:"type,omitempty"`
	MediaType string         `json:"mediaType,omitempty"`
	URL       string         `json:"url,omitempty"`
	Href      string         `json:"href,omitempty"`
	Name      string         `json:"name,omitempty"`
	Value     string         `json:"value,omitempty"`
}

type AttachmentType

type AttachmentType string
const (
	Image         AttachmentType = "Image"
	PropertyValue AttachmentType = "PropertyValue"
)

type Audience

type Audience struct {
	data.OrderedMap[string, struct{}]
}

Audience is an ordered, unique list of actor IDs.

func (*Audience) Add

func (a *Audience) Add(s string)

func (Audience) MarshalJSON

func (a Audience) MarshalJSON() ([]byte, error)

func (*Audience) Scan

func (a *Audience) Scan(src any) error

func (*Audience) UnmarshalJSON

func (a *Audience) UnmarshalJSON(b []byte) error

func (*Audience) Value

func (a *Audience) Value() (driver.Value, error)

type Object

type Object struct {
	Context      any          `json:"@context,omitempty"`
	ID           string       `json:"id"`
	Type         ObjectType   `json:"type"`
	AttributedTo string       `json:"attributedTo,omitempty"`
	InReplyTo    string       `json:"inReplyTo,omitempty"`
	Content      string       `json:"content,omitempty"`
	Summary      string       `json:"summary,omitempty"`
	Sensitive    bool         `json:"sensitive,omitempty"`
	Name         string       `json:"name,omitempty"`
	Published    Time         `json:"published"`
	Updated      *Time        `json:"updated,omitempty"`
	To           Audience     `json:"to,omitempty"`
	CC           Audience     `json:"cc,omitempty"`
	Audience     string       `json:"audience,omitempty"`
	Tag          Array[Tag]   `json:"tag,omitempty"`
	Attachment   []Attachment `json:"attachment,omitempty"`
	URL          string       `json:"url,omitempty"`

	// polls
	VotersCount int64        `json:"votersCount,omitempty"`
	OneOf       []PollOption `json:"oneOf,omitempty"`
	AnyOf       []PollOption `json:"anyOf,omitempty"`
	EndTime     *Time        `json:"endTime,omitempty"`
	Closed      *Time        `json:"closed,omitempty"`
}

Object represents most ActivityPub objects. Actors are represented by Actor.

func (*Object) IsPublic

func (o *Object) IsPublic() bool

func (*Object) Scan

func (o *Object) Scan(src any) error

func (*Object) Value

func (o *Object) Value() (driver.Value, error)

type ObjectType

type ObjectType string
const (
	Note     ObjectType = "Note"
	Page     ObjectType = "Page"
	Article  ObjectType = "Article"
	Question ObjectType = "Question"
)

type PollOption

type PollOption struct {
	Name    string `json:"name"`
	Replies struct {
		TotalItems int64 `json:"totalItems"`
	} `json:"replies"`
}

type PublicKey

type PublicKey struct {
	ID           string `json:"id"`
	Owner        string `json:"owner"`
	PublicKeyPem string `json:"publicKeyPem"`
}

type Resolver

type Resolver interface {
	ResolveID(ctx context.Context, log *slog.Logger, db *sql.DB, key httpsig.Key, id string, flags ResolverFlag) (*Actor, error)
	Resolve(ctx context.Context, log *slog.Logger, db *sql.DB, key httpsig.Key, host, name string, flags ResolverFlag) (*Actor, error)
}

Resolver retrieves Actor objects given their ID.

type ResolverFlag

type ResolverFlag uint
const (
	// Offline disables fetching of remote actors and forces use of local or cached actors.
	Offline ResolverFlag = 1

	// InstanceActor enables discovery of the "instance actor" instead of the regular actor discovery flow.
	InstanceActor = 2
)

type Tag

type Tag struct {
	Type TagType     `json:"type,omitempty"`
	Name string      `json:"name,omitempty"`
	Href string      `json:"href,omitempty"`
	Icon *Attachment `json:"icon,omitempty"`
}

type TagType

type TagType string
const (
	Mention TagType = "Mention"
	Hashtag TagType = "Hashtag"
	Emoji   TagType = "Emoji"
)

type Time

type Time struct {
	time.Time
}

Time is a wrapper around time.Time with fallback if parsing of RFC3339 fails.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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