types

package module
v0.0.0-...-5264aa3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: AGPL-3.0 Imports: 10 Imported by: 10

README

go.yarn.social/types

Build Status Go Report Card Go Reference

go.yarn.social/types is the Go library used by Yarn's main software component yarnd and several other components as a dependency.

Quick Start

TBD

License

go.yarn.social/types is licensed under the terms of the AGPLv3

Documentation

Index

Constants

View Source
const PreambleBufferSize = 2048
View Source
const (
	// TwtHashLength is the encoded length (no. of characters) of a Twt's Hash (base32 encoded blake2b)
	TwtHashLength = 7
)

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrInvalidFeed    = errors.New("erroneous feed detected")
)
View Source
var NilTwt = &nilTwt{}
View Source
var PreambleMarker = []byte("#")

Functions

func IsValidFeedType

func IsValidFeedType(t FeedType) bool

func NormalizeUsername

func NormalizeUsername(username string) string

func SetTwtManager

func SetTwtManager(m TwtManager)

func SplitTwts

func SplitTwts(twts Twts, ttl time.Duration, N int) (Twts, Twts, Twts)

SplitTwts into three groupings. The first with created > now (future?! misbehaving clients or misconfigured timezone) The second with created > ttl or at most N. The third all remaining twts.

Types

type ArchivedFeed

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

func NewArchivedFeed

func NewArchivedFeed(twter *Twter, hash, path string) *ArchivedFeed

func (*ArchivedFeed) Hash

func (af *ArchivedFeed) Hash() string

func (*ArchivedFeed) Path

func (af *ArchivedFeed) Path() string

func (*ArchivedFeed) String

func (af *ArchivedFeed) String() string

func (*ArchivedFeed) Twter

func (af *ArchivedFeed) Twter() *Twter

func (*ArchivedFeed) URL

func (af *ArchivedFeed) URL() string

type AuthRequest

type AuthRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

AuthRequest ...

func NewAuthRequest

func NewAuthRequest(r io.Reader) (req AuthRequest, err error)

NewAuthRequest ...

type AuthResponse

type AuthResponse struct {
	Token string `json:"token"`
}

AuthResponse ...

func (AuthResponse) Bytes

func (res AuthResponse) Bytes() ([]byte, error)

Bytes ...

type ConversationRequest

type ConversationRequest struct {
	Hash string `json:"hash"`
	Page int    `json:"page"`
}

ConversationRequest ...

func NewConversationRequest

func NewConversationRequest(r io.Reader) (req ConversationRequest, err error)

NewConversationRequest ...

type ErrDeadFeed

type ErrDeadFeed struct {
	Reason string
}

func (ErrDeadFeed) Error

func (e ErrDeadFeed) Error() string

type ExternalProfileRequest

type ExternalProfileRequest struct {
	URL  string `json:"url"`
	Nick string `json:"nick"`
}

ExternalProfileRequest ...

func NewExternalProfileRequest

func NewExternalProfileRequest(r io.Reader) (req ExternalProfileRequest, err error)

NewExternalProfileRequest ...

type FeedLookup

type FeedLookup interface {
	FeedLookup(string) *Twter
}

type FeedLookupFn

type FeedLookupFn func(string) *Twter

func (FeedLookupFn) FeedLookup

func (fn FeedLookupFn) FeedLookup(s string) *Twter

type FeedType

type FeedType string
const (
	// FeedTypeRSS is the RSS/Atom Feed Type
	FeedTypeRSS FeedType = "rss"

	// FeedTypeBot is the Automation/Bot Feed Type
	FeedTypeBot FeedType = "bot"

	// FeedTypeUnknown is the Unknown Feed Type
	FeedTypeUnknown FeedType = ""
)

func GetFeedType

func GetFeedType(uri string, metadata url.Values) FeedType

type FetchFeedRequest

type FetchFeedRequest struct {
	Nick string
	URI  string

	// Force whether or not to immediately fetch the feed and bypass Cache.ShouldRefreshFeed().
	Force bool

	// Type is the type of the feed being fetched (twtxt, activitypub, etc)
	Type FetchType
}

FetchFeedRequest is an single request for a twtxt.txt feed with a canonical Nickname and URL for the feed and optional request parameters that affect how the Cache fetches the feed.

func (FetchFeedRequest) Domain

func (f FetchFeedRequest) Domain() string

Domain returns the hostname/domain of the fetch feed request uri

func (FetchFeedRequest) String

func (f FetchFeedRequest) String() string

String implements the Stringer interface and returns the Feed represented as a twtxt.txt URI in the form @<nick url>.

type FetchFeedRequests

type FetchFeedRequests map[FetchFeedRequest]bool

FetchFeedRequests is a mapping of FetchFeedRequest to booleans used to ensure unique feeds Used by go.yarn.social/yarn/internal.Cache XXX: Probably shouldn't be here...

type FetchTwtsRequest

type FetchTwtsRequest struct {
	URL  string `json:"url"`
	Nick string `json:"nick"`
	Page int    `json:"page"`
}

FetchTwtsRequest ...

func NewFetchTwtsRequest

func NewFetchTwtsRequest(r io.Reader) (req FetchTwtsRequest, err error)

NewFetchTwtsRequest ...

type FetchType

type FetchType = int

FetchType is the type of feed being fetched (twtxt, activitypub, etc)

const (
	// FetchTypeTwtxt is the twtxt fetch type for Twtxt feeds
	FetchTypeTwtxt FetchType = iota

	// FetchTypeActivity is the activity fetch type for Activity Pub feeds
	FetchTypeActivity
)

type FmtOpts

type FmtOpts interface {
	LocalURL() *url.URL
	IsLocalURL(string) bool
	UserURL(string) string
	ExternalURL(nick, uri string) string
	URLForTag(tag string) string
	URLForUser(user string) string
}

type Follow

type Follow struct {
	URI           string
	Nick          string
	Failures      int
	LastFetchedAt time.Time
	LastSuccessAt time.Time
	LastFailureAt time.Time
}

func (Follow) String

func (f Follow) String() string

type FollowRequest

type FollowRequest struct {
	Nick string `json:"nick"`
	URL  string `json:"url"`
}

FollowRequest ...

func NewFollowRequest

func NewFollowRequest(r io.Reader) (req FollowRequest, err error)

NewFollowRequest ...

type Follower

type Follower struct {
	URI        string
	URL        string
	Nick       string
	LastSeenAt time.Time
}

func (*Follower) String

func (f *Follower) String() string

type Followers

type Followers []*Follower

func (Followers) AsMap

func (fs Followers) AsMap() map[string]string

AsMap returns the Followers as a map of `nick -> uri` for use by the /whoFollows resource which implements the MultiUserAegent spec See: https://dev.twtxt.net/doc/useragentextension.html

func (Followers) SortBy

func (fs Followers) SortBy(field string)

type Follows

type Follows []Follow

func (Follows) SortBy

func (fs Follows) SortBy(field string)

type HashOption

type HashOption func(opts *HashOptions)

HashOption allows for configurable Hash() behaviour such as WithHashLength() and WithHashNoCache

func WithHashLength

func WithHashLength(length int) HashOption

WithHashLength sets the encoded (base32) hash length of the Twt hash (blake2b)

func WithHashNoCache

func WithHashNoCache() HashOption

WithHashNoCache ignores the previously cached encoded hash and recomputes it (potentially with a new length)

type HashOptions

type HashOptions struct {
	Length  int
	NoCache bool
}

HashOptions control hash encoding options for length and ignoring the previously cached encoded value and recomputing the hash (with potentially a longer length).

func NewHashOptions

func NewHashOptions() *HashOptions

NewHashOptions returns a hashOptions with default values

type Info

type Info interface {
	Following() []Twter
	FollowMap() map[string]Twter

	KV
}

type InjectRequest

type InjectRequest struct {
	Twt Twt `json:"twt"`
}

InjectRequest ...

func NewInjectRequest

func NewInjectRequest(r io.Reader) (req InjectRequest, err error)

NewInjectRequest ...

type KV

type KV interface {
	Values() url.Values
	GetN(string, int) (Value, bool)
	GetAll(string) []Value
	fmt.Stringer
}
type Link struct {
	Title string
	URL   string
}
type LinkList []TwtLink
func (l LinkList) Links() []string
type Links []Link

func (Links) Len

func (ls Links) Len() int

func (Links) Less

func (ls Links) Less(i, j int) bool

func (Links) Swap

func (ls Links) Swap(i, j int)

type MentionList

type MentionList []TwtMention

func (MentionList) IsMentioned

func (ml MentionList) IsMentioned(twter Twter) bool

func (MentionList) Mentions

func (ml MentionList) Mentions() []string

type MuteRequest

type MuteRequest struct {
	Nick string `json:"nick"`
	URL  string `json:"url"`
}

MuteRequest ...

func NewMuteRequest

func NewMuteRequest(r io.Reader) (req MuteRequest, err error)

NewMuteRequest ...

type OldProfile

type OldProfile struct {
	Type string

	URL string
	// TODO: Rename to Nick
	Username string
	Avatar   string
	// TODO: Rename to Description
	Tagline string

	Links Links

	// Used by the Mobile App for "Post as..."
	Feeds []string

	// `true` if the User viewing the Profile has muted this user/feed
	Muted bool

	// `true` if the User viewing the Profile follows this user/feed
	Follows bool

	// `true` if user/feed follows the User viewing the Profile.
	FollowedBy bool

	// Timestamp of the profile's last Twt
	LastPostedAt time.Time

	// Timestamp of the profile's last activity (last seen) accurate to a day
	LastSeenAt time.Time

	Bookmarks map[string]string

	NFollowing int
	Following  map[string]string

	NFollowers int
	// TODO: Maybe migrate to use `Followers` type
	// XXX: But be aware doing so breaks API compat
	Followers map[string]string

	// `true` if the User viewing the Profile has permissions to show the
	// bookmarks/followers/followings of this user/feed
	ShowBookmarks bool
	ShowFollowers bool
	ShowFollowing bool
}

OldProfile is a backwards compatible version of `Profile` for APIv1 client compatibility such as `yarnc` and the Mobile App that uses a map of `nick -> url` for Followers and Followings. TODO: Upgrade APIv1 clients TODOL Remove this when the Mobile App has been upgraded.

type PagedRequest

type PagedRequest struct {
	Page int `json:"page"`
}

PagedRequest ...

func NewPagedRequest

func NewPagedRequest(r io.Reader) (req PagedRequest, err error)

NewPagedRequest ...

type PagedResponse

type PagedResponse struct {
	Twts  Twts `json:"twts"`
	Pager PagerResponse
}

PagedResponse ...

func (PagedResponse) Bytes

func (res PagedResponse) Bytes() ([]byte, error)

Bytes ...

type PagerResponse

type PagerResponse struct {
	Current   int `json:"current_page"`
	MaxPages  int `json:"max_pages"`
	TotalTwts int `json:"total_twts"`
}

PagerResponse ...

type PostRequest

type PostRequest struct {
	PostAs string `json:"post_as"`
	Text   string `json:"text"`
}

PostRequest ...

func NewPostRequest

func NewPostRequest(r io.Reader) (req PostRequest, err error)

NewPostRequest ...

type PostResponse

type PostResponse struct {
	Created string `json:"created"`
	Hash    string `json:"hash"`
	Text    string `json:"text"`
}

PostResponse ...

func (PostResponse) Bytes

func (res PostResponse) Bytes() ([]byte, error)

Bytes ...

type PreambleFeed

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

func ReadPreambleFeed

func ReadPreambleFeed(r ReadSeekerReaderAt, size int64) (*PreambleFeed, error)

func (*PreambleFeed) Preamble

func (p *PreambleFeed) Preamble() string

func (*PreambleFeed) Read

func (p *PreambleFeed) Read(b []byte) (n int, err error)

func (*PreambleFeed) Seek

func (p *PreambleFeed) Seek(offset int64, whence int) (int64, error)

type Profile

type Profile struct {
	Type string

	URI         string
	Nick        string
	Avatar      string
	Description string

	Links Links

	// Used by the Mobile App for "Post as..."
	Feeds []string

	// `true` if the User viewing the Profile has muted this user/feed
	Muted bool

	// `true` if the User viewing the Profile follows this user/feed
	Follows bool

	// `true` if user/feed follows the User viewing the Profile.
	FollowedBy bool

	// Timestamp of the profile's last Twt
	LastPostedAt time.Time

	// Timestamp of the profile's last activity (last seen) accurate to a day
	LastSeenAt time.Time

	Bookmarks map[string]string

	NFollowing int
	Following  Follows

	NFollowers int
	Followers  Followers

	// `true` if the User viewing the Profile has permissions to show the
	// bookmarks/followers/followings of this user/feed
	ShowBookmarks bool
	ShowFollowers bool
	ShowFollowing bool
}

Profile represents a user/feed profile

func (Profile) AsOldProfile

func (p Profile) AsOldProfile() OldProfile

AsOldProfile returns a `Profilev1` object for compatibility with APIv1 clients such as the Mobile App. TODO: Remove when Mobile App is upgraded

type ProfileResponse

type ProfileResponse struct {
	// TODO: Upgrade to `Profile` (v2) when Mobile App is upgraded
	Profile OldProfile `json:"profile"`
	Twter   Twter      `json:"twter"`
}

ProfileResponse ...

type ReadSeekerReaderAt

type ReadSeekerReaderAt interface {
	io.Reader
	io.Seeker
	io.ReaderAt
}

type RegisterRequest

type RegisterRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
}

RegisterRequest ...

func NewRegisterRequest

func NewRegisterRequest(r io.Reader) (req RegisterRequest, err error)

NewRegisterRequest ...

type ReportRequest

type ReportRequest struct {
	Nick string `json:"nick"`
	URL  string `json:"url"`

	Name     string `json:"name"`
	Email    string `json:"email"`
	Category string `json:"subject"`
	Message  string `json:"message"`
}

ReportRequest ...

func NewReportRequest

func NewReportRequest(r io.Reader) (req ReportRequest, err error)

NewReportRequest ...

type Subject

type Subject interface {
	Text() string
	Tag() TwtTag

	String() string
}

type SupportRequest

type SupportRequest struct {
	Name    string `json:"name"`
	Email   string `json:"email"`
	Subject string `json:"subject"`
	Message string `json:"message"`
}

SupportRequest ...

func NewSupportRequest

func NewSupportRequest(r io.Reader) (req SupportRequest, err error)

NewSupportRequest ...

type SyncRequest

type SyncRequest struct {
	Delete bool   `json:"delete"`
	Feed   string `json:"feed"`
	Body   []byte `json:"body"`
}

SyncRequest ...

func NewSyncRequest

func NewSyncRequest(r io.Reader) (req SyncRequest, err error)

NewSyncRequest ...

type SyncResponse

type SyncResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
	Merged  Twts   `json:"merged"`
}

SyncResponse ...

func (SyncResponse) Bytes

func (res SyncResponse) Bytes() ([]byte, error)

Bytes ...

type TagList

type TagList []TwtTag

func (*TagList) Tags

func (tags *TagList) Tags() []string

type Twt

type Twt interface {
	IsZero() bool
	Clone() Twt

	Twter() Twter
	Created() time.Time

	Hash(...HashOption) string
	Subject() Subject
	Mentions() MentionList
	Links() LinkList
	Tags() TagList

	ExpandMentions(FmtOpts, FeedLookup)

	fmt.Formatter

	// TODO: remove FormatText and add func to update links for UI
	FormatText(TwtTextFormat, FmtOpts) string
}

Twt ...

func DecodeJSON

func DecodeJSON(b []byte) (Twt, error)

func MakeTwt

func MakeTwt(twter Twter, ts time.Time, text string) Twt

func ParseLine

func ParseLine(line string, twter *Twter) (twt Twt, err error)

type TwtFile

type TwtFile interface {
	Twter() *Twter
	Prev() *ArchivedFeed
	Info() Info
	Twts() Twts
}

func ParseFile

func ParseFile(r io.Reader, twter *Twter) (TwtFile, error)
type TwtLink interface {
	Text() string
	Target() string
}

type TwtManager

type TwtManager interface {
	DecodeJSON([]byte) (Twt, error)
	ParseLine(string, *Twter) (Twt, error)
	ParseFile(io.Reader, *Twter) (TwtFile, error)
	MakeTwt(twter Twter, ts time.Time, text string) Twt
}

type TwtMap

type TwtMap map[string]Twt

TwtMap ...

type TwtMention

type TwtMention interface {
	Twter() Twter
}

type TwtTag

type TwtTag interface {
	Text() string
	Target() string
}

type TwtTextFormat

type TwtTextFormat int

TwtTextFormat represents the format of which the twt text gets formatted to

const (
	// MarkdownFmt to use markdown format
	MarkdownFmt TwtTextFormat = iota
	// ASFmt to use Activity Streams format (mostly HTML)
	ASFmt
	// HTMLFmt to use HTML format
	HTMLFmt
	// TextFmt to use for og:description
	TextFmt
	// LiteralFmt is the raw literal format as written/read to/from a feed
	LiteralFmt
)

type Twter

type Twter struct {
	Nick       string `json:"nick"`
	URI        string `json:"uri"`
	HashingURI string `json:"-"`

	// URL Deprecated field repalced by URI
	// Remove post Cache v20
	URL string `json:"-"`

	Avatar  string `json:"avatar"`
	Tagline string `json:"-"`

	Following int `json:"-"`
	Followers int `json:"-"`

	Follow map[string]Twter `json:"-"`

	// Metadata holds additinoal KV pairs (properties) of the feed
	// See: [Metadata Extension](https://dev.twtxt.net/doc/metadataextension.html)
	Metadata url.Values `json:"-"`
}

Twter ...

func NewTwter

func NewTwter(nick, uri string) Twter

func (Twter) Domain

func (twter Twter) Domain() string

func (Twter) DomainNick

func (twter Twter) DomainNick() string

func (Twter) IsZero

func (twter Twter) IsZero() bool

func (Twter) String

func (twter Twter) String() string

type Twts

type Twts []Twt

Twts typedef to be able to attach sort methods

func (Twts) Clone

func (twts Twts) Clone() Twts

func (Twts) Len

func (twts Twts) Len() int

func (Twts) Less

func (twts Twts) Less(i, j int) bool

func (Twts) LinkCount

func (twts Twts) LinkCount() map[string]int
func (twts Twts) Links() LinkList

Links ...

func (Twts) MentionCount

func (twts Twts) MentionCount() map[string]int

func (Twts) Mentions

func (twts Twts) Mentions() MentionList

Mentions ...

func (Twts) SubjectCount

func (twts Twts) SubjectCount() map[string]int

func (Twts) Subjects

func (twts Twts) Subjects() []Subject

Subjects ...

func (Twts) Swap

func (twts Twts) Swap(i, j int)

func (Twts) TagCount

func (twts Twts) TagCount() map[string]int

func (Twts) Tags

func (twts Twts) Tags() TagList

Tags ...

func (*Twts) UnmarshalJSON

func (twts *Twts) UnmarshalJSON(data []byte) error

type UnfollowRequest

type UnfollowRequest struct {
	Nick string `json:"nick"`
}

UnfollowRequest ...

func NewUnfollowRequest

func NewUnfollowRequest(r io.Reader) (req UnfollowRequest, err error)

NewUnfollowRequest ...

type UnmuteRequest

type UnmuteRequest struct {
	Nick string `json:"nick"`
}

UnmuteRequest ...

func NewUnmuteRequest

func NewUnmuteRequest(r io.Reader) (req UnmuteRequest, err error)

NewUnmuteRequest ...

type Value

type Value interface {
	Key() string
	Value() string
}

type WhoAmIResponse

type WhoAmIResponse struct {
	Username string `json:"username"`
}

WhoAmIResponse ...

func (WhoAmIResponse) Bytes

func (res WhoAmIResponse) Bytes() ([]byte, error)

Bytes ...

type Yarn

type Yarn struct {
	Root Twt
	Twts Twts
}

Yarn ...

func (Yarn) GetLastTwt

func (yarn Yarn) GetLastTwt() Twt

type Yarns

type Yarns []Yarn

Yarns ...

func (Yarns) AsTwts

func (yarns Yarns) AsTwts() Twts

func (Yarns) Len

func (yarns Yarns) Len() int

func (Yarns) Less

func (yarns Yarns) Less(i, j int) bool

func (Yarns) Swap

func (yarns Yarns) Swap(i, j int)

Jump to

Keyboard shortcuts

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