activitypub

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package activitypub provides ActivityPub protocol support for tens-city. It enables federation with Mastodon and other ActivityPub-compatible platforms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	Context   string      `json:"@context,omitempty"`
	ID        string      `json:"id"`
	Type      string      `json:"type"`
	Actor     string      `json:"actor"`
	Published string      `json:"published,omitempty"`
	To        []string    `json:"to,omitempty"`
	Cc        []string    `json:"cc,omitempty"`
	Object    interface{} `json:"object"`
}

Activity represents a generic ActivityPub activity

type Actor

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

Actor represents an ActivityPub actor

func NewActor

func NewActor(config *Config) (*Actor, error)

NewActor creates a new ActivityPub actor with the given configuration. It loads or generates an RSA keypair for HTTP signatures.

func (*Actor) ClearPublished

func (a *Actor) ClearPublished() error

ClearPublished clears the published tracking (for testing/reset)

func (*Actor) Config

func (a *Actor) Config() *Config

Config returns the actor's configuration

func (*Actor) FetchActorInbox

func (a *Actor) FetchActorInbox(actorURL string) (string, error)

FetchActorInbox fetches a remote actor and returns their inbox URL

func (*Actor) FollowersURL

func (a *Actor) FollowersURL() string

FollowersURL returns the actor's followers collection URL

func (*Actor) FollowingURL

func (a *Actor) FollowingURL() string

FollowingURL returns the actor's following collection URL

func (*Actor) GetFediHandle added in v0.8.2

func (a *Actor) GetFediHandle() string

GetFediHandle returns the actor's fediverse handle (e.g., @user@domain)

func (*Actor) GetFollowersCount

func (a *Actor) GetFollowersCount() int

GetFollowersCount returns the number of followers

func (*Actor) GetPublishedCount

func (a *Actor) GetPublishedCount() int

GetPublishedCount returns the number of published posts

func (*Actor) HandleActor

func (a *Actor) HandleActor(w http.ResponseWriter, r *http.Request, username string)

HandleActor serves the ActivityPub actor profile. GET /users/{username} Content negotiation: returns JSON-LD for ActivityPub clients, HTML redirect otherwise

func (*Actor) HandleActorLegacy

func (a *Actor) HandleActorLegacy(w http.ResponseWriter, r *http.Request, username string)

HandleActorLegacy handles requests to the legacy write.as/writefreely path. GET /api/collections/{username} Redirects to the canonical /users/{username} path

func (*Actor) HandleFollowers

func (a *Actor) HandleFollowers(w http.ResponseWriter, r *http.Request, username string)

HandleFollowers serves the actor's followers collection. GET /users/{username}/followers

func (*Actor) HandleFollowing

func (a *Actor) HandleFollowing(w http.ResponseWriter, r *http.Request, username string)

HandleFollowing serves the actor's following collection. GET /users/{username}/following

func (*Actor) HandleInbox

func (a *Actor) HandleInbox(w http.ResponseWriter, r *http.Request, username string)

HandleInbox handles incoming ActivityPub activities. POST /users/{username}/inbox

func (*Actor) HandleInboxLegacy

func (a *Actor) HandleInboxLegacy(w http.ResponseWriter, r *http.Request, username string)

HandleInboxLegacy handles requests to the legacy write.as/writefreely inbox path. POST /api/collections/{username}/inbox

func (*Actor) HandleNodeInfo

func (a *Actor) HandleNodeInfo(w http.ResponseWriter, r *http.Request, localPosts int)

HandleNodeInfo handles /nodeinfo/2.0 requests

func (*Actor) HandleNodeInfoWellKnown

func (a *Actor) HandleNodeInfoWellKnown(w http.ResponseWriter, r *http.Request)

HandleNodeInfoWellKnown handles /.well-known/nodeinfo requests

func (*Actor) HandleOutbox

func (a *Actor) HandleOutbox(w http.ResponseWriter, r *http.Request, username string, posts []BlogPost)

HandleOutbox serves the actor's outbox (published activities). GET /users/{username}/outbox

func (*Actor) HandleWebFinger

func (a *Actor) HandleWebFinger(w http.ResponseWriter, r *http.Request)

HandleWebFinger handles WebFinger requests for actor discovery. GET /.well-known/webfinger?resource=acct:username@domain

func (*Actor) ID

func (a *Actor) ID() string

ID returns the actor's ActivityPub ID (URI)

func (*Actor) InboxURL

func (a *Actor) InboxURL() string

InboxURL returns the actor's inbox URL

func (*Actor) KeyID

func (a *Actor) KeyID() string

KeyID returns the actor's public key ID

func (*Actor) OutboxURL

func (a *Actor) OutboxURL() string

OutboxURL returns the actor's outbox URL

func (*Actor) PublicKeyPEM

func (a *Actor) PublicKeyPEM() string

PublicKeyPEM returns the public key in PEM format

func (*Actor) PublishNewPosts

func (a *Actor) PublishNewPosts(posts []BlogPost) (int, error)

PublishNewPosts checks for posts that haven't been published yet and publishes them. Returns the number of posts published.

func (*Actor) PublishPost

func (a *Actor) PublishPost(post BlogPost) ([]PublishResult, error)

PublishPost sends a Create activity for a blog post to all followers. Returns the number of successful deliveries and any errors.

func (*Actor) SignedGet

func (a *Actor) SignedGet(targetURL string) (*http.Response, error)

SignedGet sends a GET request with HTTP signature authentication

func (*Actor) SignedPost

func (a *Actor) SignedPost(targetURL string, body []byte) (*http.Response, error)

SignedPost sends a POST request with HTTP signature authentication

type ActorEndpoints

type ActorEndpoints struct {
	SharedInbox string `json:"sharedInbox,omitempty"`
}

ActorEndpoints contains additional endpoints

type ActorImage

type ActorImage struct {
	Type      string `json:"type"`
	MediaType string `json:"mediaType,omitempty"`
	URL       string `json:"url"`
}

ActorImage represents an image attachment (icon, image)

type ActorPublicKey

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

ActorPublicKey represents the actor's public key for HTTP signatures

type ActorResponse

type ActorResponse struct {
	Context           interface{}     `json:"@context"`
	ID                string          `json:"id"`
	Type              string          `json:"type"`
	PreferredUsername string          `json:"preferredUsername"`
	Name              string          `json:"name"`
	Summary           string          `json:"summary,omitempty"`
	URL               string          `json:"url,omitempty"`
	Inbox             string          `json:"inbox"`
	Outbox            string          `json:"outbox"`
	Followers         string          `json:"followers"`
	Following         string          `json:"following"`
	PublicKey         ActorPublicKey  `json:"publicKey"`
	Icon              *ActorImage     `json:"icon,omitempty"`
	Endpoints         *ActorEndpoints `json:"endpoints,omitempty"`
}

ActorResponse represents an ActivityPub Actor object

type Article

type Article struct {
	ID           string        `json:"id"`
	Type         string        `json:"type"`
	AttributedTo string        `json:"attributedTo"`
	Name         string        `json:"name"`
	Content      string        `json:"content"`
	Summary      string        `json:"summary,omitempty"`
	Published    string        `json:"published"`
	Updated      string        `json:"updated,omitempty"`
	URL          string        `json:"url"`
	To           []string      `json:"to,omitempty"`
	Cc           []string      `json:"cc,omitempty"`
	Tag          []Tag         `json:"tag,omitempty"`
	Image        *ArticleImage `json:"image,omitempty"`
}

Article represents an ActivityPub Article object (for blog posts)

type ArticleImage

type ArticleImage struct {
	Type      string `json:"type"`
	MediaType string `json:"mediaType,omitempty"`
	URL       string `json:"url"`
	Name      string `json:"name,omitempty"`
}

ArticleImage represents an image attachment for an Article

type BlogPost

type BlogPost struct {
	ID          string    // Unique identifier (URL)
	Slug        string    // URL slug
	Title       string    // Post title
	Description string    // Short description/summary
	Content     string    // HTML content
	Published   time.Time // Publication date
	Updated     time.Time // Last modified date (optional)
	Tags        []string  // Post tags
	AuthorName  string    // Author display name
	Image       string    // Featured image URL (optional)
}

BlogPost represents a blog post for conversion to ActivityPub

type Config

type Config struct {
	// Actor identity
	Username    string // e.g., "myork"
	Domain      string // e.g., "blog.stackdump.com"
	DisplayName string // e.g., "stackdump"
	Summary     string // Actor bio/description

	// URLs
	ProfileURL string // HTML profile page URL
	IconURL    string // Avatar/icon URL

	// Key storage
	KeyPath string // Path to store/load RSA private key

	// Software info (for NodeInfo)
	SoftwareName    string
	SoftwareVersion string

	// NodeInfo metadata
	NodeName        string // e.g., "Stackdump Blog"
	NodeDescription string // e.g., "Technical blog about..."
	NodeHomePage    string // e.g., "https://github.com/stackdump/tens-city"
	NodeGitHub      string // e.g., "https://github.com/stackdump/tens-city"
}

Config holds ActivityPub configuration for an actor

type IncomingActivity

type IncomingActivity struct {
	Context interface{} `json:"@context,omitempty"`
	ID      string      `json:"id"`
	Type    string      `json:"type"`
	Actor   string      `json:"actor"`
	Object  interface{} `json:"object"` // Can be string (for Follow) or object (for Create, etc.)
}

IncomingActivity represents an incoming ActivityPub activity

type NodeInfo

type NodeInfo struct {
	Version           string           `json:"version"`
	Software          NodeInfoSoftware `json:"software"`
	Protocols         []string         `json:"protocols"`
	Services          NodeInfoServices `json:"services"`
	Usage             NodeInfoUsage    `json:"usage"`
	OpenRegistrations bool             `json:"openRegistrations"`
	Metadata          NodeInfoMetadata `json:"metadata"`
}

NodeInfo represents the NodeInfo 2.0 schema response

type NodeInfoLink struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
}

NodeInfoLink represents a link in the nodeinfo well-known response

type NodeInfoMetaSoftware added in v0.8.4

type NodeInfoMetaSoftware struct {
	HomePage string `json:"homepage"`
	GitHub   string `json:"github"`
}

NodeInfoMetaSoftware has links about the software project

type NodeInfoMetadata added in v0.8.4

type NodeInfoMetadata struct {
	NodeName        string               `json:"nodeName"`
	NodeDescription string               `json:"nodeDescription"`
	Software        NodeInfoMetaSoftware `json:"software"`
}

NodeInfoMetadata describes the node

type NodeInfoServices added in v0.8.4

type NodeInfoServices struct {
	Inbound  []string `json:"inbound"`
	Outbound []string `json:"outbound"`
}

NodeInfoServices describes inbound/outbound service integrations

type NodeInfoSoftware

type NodeInfoSoftware struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

NodeInfoSoftware describes the server software

type NodeInfoUsage

type NodeInfoUsage struct {
	Users      NodeInfoUsers `json:"users"`
	LocalPosts int           `json:"localPosts"`
}

NodeInfoUsage describes server usage statistics

type NodeInfoUsers

type NodeInfoUsers struct {
	Total          int `json:"total"`
	ActiveMonth    int `json:"activeMonth"`
	ActiveHalfyear int `json:"activeHalfyear"`
}

NodeInfoUsers describes user statistics

type NodeInfoWellKnown

type NodeInfoWellKnown struct {
	Links []NodeInfoLink `json:"links"`
}

NodeInfoWellKnown represents the /.well-known/nodeinfo response

type OrderedCollection

type OrderedCollection struct {
	Context      string        `json:"@context"`
	ID           string        `json:"id"`
	Type         string        `json:"type"`
	TotalItems   int           `json:"totalItems"`
	OrderedItems []interface{} `json:"orderedItems,omitempty"`
	First        string        `json:"first,omitempty"`
}

OrderedCollection represents an ActivityPub OrderedCollection

type PublishResult

type PublishResult struct {
	Follower string
	Success  bool
	Error    string
}

PublishResult tracks the result of publishing to a follower

type Tag

type Tag struct {
	Type string `json:"type"`
	Name string `json:"name"`
	Href string `json:"href,omitempty"`
}

Tag represents a hashtag or mention

type WebFingerLink struct {
	Rel  string `json:"rel"`
	Type string `json:"type,omitempty"`
	Href string `json:"href,omitempty"`
}

WebFingerLink represents a link in the WebFinger response

type WebFingerResponse

type WebFingerResponse struct {
	Subject string          `json:"subject"`
	Aliases []string        `json:"aliases,omitempty"`
	Links   []WebFingerLink `json:"links"`
}

WebFingerResponse represents a WebFinger JRD response

Jump to

Keyboard shortcuts

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