fedi

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Context = StringList{"https://www.w3.org/ns/activitystreams"}
View Source
var Proxy proxy

Functions

func CheckHeaders

func CheckHeaders(c *fiber.Ctx, id string) error

func CreatePem

func CreatePem(id string) ([]byte, error)

func MergeOutbox

func MergeOutbox(ctx context.Context, board string, ob Outbox) error

func NewProxy

func NewProxy(proxyUrl string) (proxy, error)

func PostDel

func PostDel(ctx context.Context, board database.Board, post database.Post) error

func PostOut

func PostOut(ctx context.Context, board database.Board, post database.Post) error

PostOut sends a post out to federated servers.

func PublicKey

func PublicKey(id string) (string, error)

func SendActivity

func SendActivity(ctx context.Context, act Activity) error

func Sign

func Sign(id string, data string) (string, error)

func Verify

func Verify(keyPem string, sign string, data string) error

Types

type Activity

type Activity struct {
	*Object

	ObjectProp *Object `json:"object,omitempty"`
}

func GenerateAccept

func GenerateAccept(ctx context.Context, board database.Board, to string, obj *Object) (Activity, error)

func GenerateFollow

func GenerateFollow(ctx context.Context, board database.Board, to string) (Activity, error)

func GenerateUnfollow

func GenerateUnfollow(ctx context.Context, board database.Board, to string) (Activity, error)

type Actor

type Actor struct {
	*Object

	PublicKey *publicKey `json:"publicKey,omitempty"`

	Inbox     string `json:"inbox,omitempty"`
	Outbox    string `json:"outbox,omitempty"`
	Following string `json:"following,omitempty"`
	Followers string `json:"followers,omitempty"`

	PreferredUsername string `json:"preferredUsername,omitempty"`
	Restricted        bool   `json:"restricted"`
}

func Finger

func Finger(ctx context.Context, actor string) (Actor, error)

func TransformBoard

func TransformBoard(board database.Board) Actor

type Collection

type Collection struct {
	*Object

	TotalItems int          `json:"totalItems"`
	Items      []LinkObject `json:"items,omitempty"`
}

Collection is a collection of links or objects.

func (Collection) MarshalJSON

func (c Collection) MarshalJSON() ([]byte, error)
type Link struct {
	Href string
	Rel  string
	Name string
}

Link represents a link to an Object. This may be just a raw string; in which case, Href will be the only thing set. There are other properties in here, but we don't care about them.

func (Link) MarshalJSON

func (l Link) MarshalJSON() ([]byte, error)

func (*Link) UnmarshalJSON

func (l *Link) UnmarshalJSON(data []byte) error

type LinkActor

type LinkActor Actor

LinkActor is for cases where there may either be a Link or an Actor. Links can be a full Link object, or just a string. Actors must be a full Object.

func (*LinkActor) MarshalJSON

func (l *LinkActor) MarshalJSON() ([]byte, error)

func (*LinkActor) UnmarshalJSON

func (l *LinkActor) UnmarshalJSON(data []byte) error

type LinkObject

type LinkObject Object

LinkObject is for cases where there may either be a Link or an Object. Links can be a full Link object, or just a string. Objects must be a full Object.

func (*LinkObject) MarshalJSON

func (l *LinkObject) MarshalJSON() ([]byte, error)

func (*LinkObject) UnmarshalJSON

func (l *LinkObject) UnmarshalJSON(data []byte) error

type Object

type Object struct {
	Context StringList `json:"@context,omitempty"`

	ID   string `json:"id,omitempty"`
	Type string `json:"type,omitempty"`

	AttributedTo *LinkObject        `json:"attributedTo,omitempty"`
	Content      string             `json:"content,omitempty"`
	InReplyTo    []LinkObject       `json:"inReplyTo,omitempty"`
	Name         string             `json:"name,omitempty"`
	Published    *time.Time         `json:"published,omitempty"`
	Replies      *OrderedCollection `json:"replies,omitempty"`
	Summary      string             `json:"summary,omitempty"`
	To           []LinkObject       `json:"to,omitempty"`
	Updated      *time.Time         `json:"updated,omitempty"`

	// Extended attributes for other types
	Tripcode string     `json:"tripcode,omitempty"`
	Subject  string     `json:"subject,omitempty"`
	Options  []string   `json:"option,omitempty"` // Should be plural but it's not
	Actor    *LinkActor `json:"actor,omitempty"`

	// Hack to prevent collapsing objects because FChannel can't read them
	NoCollapse bool `json:"-"`
}

Object is the base type for all things ActivityPub. A small subset is used since we don't care about 90% of it.

func TransformPost

func TransformPost(ctx context.Context, actor *Actor, p database.Post, irt Object, fetchReplies bool, fetchInReplyTo bool) (Object, error)

TransformPost converts our native post structure to ActivityPub's Note.

func (Object) AsPost

func (n Object) AsPost(ctx context.Context, board string) (database.Post, error)

func (Object) AsThread

func (n Object) AsThread(ctx context.Context, board string) ([]database.Post, error)

type OrderedCollection

type OrderedCollection struct {
	*Object

	TotalItems   int          `json:"totalItems"`
	OrderedItems []LinkObject `json:"orderedItems,omitempty"`
}

OrderedCollection is a strictly ordered collection of links or objects. It exists solely because encoding/json won't do two JSON keys for one value, and I don't want to start pulling keys out of map[string]any returned from Unmarshal.

func (OrderedCollection) MarshalJSON

func (c OrderedCollection) MarshalJSON() ([]byte, error)

type Outbox

type Outbox struct {
	Context StringList `json:"@context,omitempty"`
	Actor   *Actor     `json:"actor,omitempty"`

	TotalItems   int          `json:"totalItems"`
	OrderedItems []LinkObject `json:"orderedItems,omitempty"`
}

func FetchOutbox

func FetchOutbox(ctx context.Context, actorUrl string) (Outbox, error)

func GenerateOutbox

func GenerateOutbox(ctx context.Context, board database.Board) (Outbox, error)

type StringList

type StringList []string

StringList is a type that takes either a string, or a []string. In the case of string, index 0 will be said string.

func (StringList) MarshalJSON

func (s StringList) MarshalJSON() ([]byte, error)

func (*StringList) UnmarshalJSON

func (s *StringList) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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