reading

package
v0.0.0-...-41f0c78 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package reading decides who may read what: a single post with its comments, a user's journal, the explore page, the feed and the RSS feeds built from them. Every visibility rule of pcom is applied here, on top of the pure checks in postops.

Index

Constants

View Source
const DefaultPageSize = 30

DefaultPageSize is how many items a page of a list holds (the feed, explore, the index page and a journal) unless WithLimits sets it.

View Source
const DefaultRSSLimit = 50

DefaultRSSLimit caps every RSS output, which isn't paged, unless WithLimits sets it.

Variables

This section is empty.

Functions

func CanSeeProfile

func CanSeeProfile(profile *core.User, visitor *core.User, connRadius graph.Radius) bool

func CannotSeeProfileLite

func CannotSeeProfileLite(profile *core.User, visitor *core.User) bool

Types

type Cursor

type Cursor struct {
	Time time.Time
	Kind string
	ID   string
}

Cursor is where a page starts: right after the item with this sort time, kind and ID. Clients get it as an opaque string.

func ParseCursor

func ParseCursor(s string) (Cursor, error)

ParseCursor decodes a cursor. An empty string is the first page, the zero Cursor; one that doesn't parse is service.Invalid.

func (Cursor) String

func (c Cursor) String() string

String encodes the cursor, base64url.

type Feed

type Feed struct {
	Items             []*FeedItem
	Next              string
	DirectConnections []*core.User
	OpenPrompts       []*postops.PostPrompt
	// FeedToken is the actor's private RSS feed token, nil when they have none.
	FeedToken *core.UserFeedToken
}

Feed is a page of the actor's feed. Only the first page carries the connections, prompts and feed token. Next is the cursor of the next page, empty on the last one.

type FeedItem

type FeedItem struct {
	Post     *postops.Post
	FeedItem *feeds.RssFeedItem
	Comment  *postops.Comment
}

FeedItem is one entry of the feed: a post, an RSS item or a comment.

func (*FeedItem) AddedToFeedAt

func (i *FeedItem) AddedToFeedAt() time.Time

type Journal

type Journal struct {
	Author            *core.User
	ConnectionRadius  graph.Radius
	ConnectionAllowed bool
	MediationRequest  *core.UserConnectionMediationRequest
	Posts             []*postops.Post
	About             string // the author's "About" text, empty when there is none
	// Next is the cursor of the next page of posts, empty on the last one.
	Next string
}

Journal is a user's profile page as the actor may see it.

type Option

type Option func(*Service)

Option changes how New builds the service.

func WithLimits

func WithLimits(pageSize, rssLimit int) Option

WithLimits sets how many items a page of a list holds and how many an RSS output lists. A value that isn't positive keeps the default.

type Post

type Post struct {
	Post      *postops.Post
	Comments  []*postops.Comment
	PostShare *core.PostShare
}

Post is a post as the actor may see it: the comments and the share link are set only when the post's capabilities let the actor see them.

type Posts

type Posts struct {
	Posts []*postops.Post
	Next  string
}

Posts is a page of posts. Next is the cursor of the next page, empty on the last one.

type PrivateFeed

type PrivateFeed struct {
	Owner *core.User
	Posts []*postops.Post
}

PrivateFeed is what a private RSS feed lists: the posts of its owner's feed.

type Service

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

func New

func New(store *repo.Store, opts ...Option) *Service

func (*Service) Explore

func (s *Service) Explore(ctx context.Context, actor *core.User, cursor string) (*Posts, error)

Explore lists the page after cursor (empty for the first) of the published public posts of the profiles the actor could open without a connection: public ones, and for a logged in actor those open to registered users. Nobody gets comments or actions there.

func (*Service) Feed

func (s *Service) Feed(ctx context.Context, actor *core.User, cursor string) (*Feed, error)

Feed is the page after cursor (empty for the first) of what the actor reads at /feed, newest first: the published posts of their direct connections, the posts of second-degree connections shared that far, their RSS items and the comments on posts they take part in.

func (*Service) Journal

func (s *Service) Journal(ctx context.Context, actor *core.User, username, cursor string) (*Journal, error)

Journal opens the profile of the user with that username for the actor, nil for an anonymous visitor: the page after cursor (empty for the first) of the published posts the actor may read, and how the actor could connect to the author. A profile the actor may not see is not found, so whether it exists isn't revealed.

func (*Service) Post

func (s *Service) Post(ctx context.Context, actor *core.User, postID string, editPreview bool) (*Post, error)

Post opens a post for the actor, nil for an anonymous visitor. A post the actor may not see is not found, so its existence isn't revealed, except that an anonymous visitor is asked to log in. editPreview marks the page the author previews while editing.

func (*Service) PrivateFeed

func (s *Service) PrivateFeed(ctx context.Context, token string) (*PrivateFeed, error)

PrivateFeed resolves a private RSS feed token. Anybody who has the token may read the feed, so there is no actor. It lists the newest rss limit posts of the owner's feed.

func (*Service) PublicFeed

func (s *Service) PublicFeed(ctx context.Context, username string) (*Journal, error)

PublicFeed is what the public RSS feed of the user with that username lists: the journal an anonymous visitor sees. Only a public profile has one. It lists the newest rss limit posts (WithLimits).

func (*Service) PublicPosts

func (s *Service) PublicPosts(ctx context.Context, cursor string) (*Posts, error)

PublicPosts is the page after cursor (empty for the first) of the public feed (Q15): the published public posts by authors whose profile is public, newest publication first. A public post of a profile open to registered users or connections only stays readable at its own page but is not listed here. Posts are built for nobody: no actor, no comments, no actions.

func (*Service) PublicPostsRSS

func (s *Service) PublicPostsRSS(ctx context.Context) ([]*postops.Post, error)

PublicPostsRSS is the newest rss limit posts of the public feed, for its RSS output.

Jump to

Keyboard shortcuts

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