Documentation
¶
Overview ¶
Package posts is everything users do with posts: write, edit, autosave, publish and delete them, comment on them, prompt others to write, export and import a blog, and the API v1 that does the same for scripts.
Index ¶
- Constants
- Variables
- type Action
- type CommentInput
- type CommentMailArgs
- type CommentPostedArgs
- type EditView
- type ListInput
- type Listing
- type NewPostMailArgs
- type Option
- type PromptAnswerMailArgs
- type PromptMailArgs
- type PublishedArgs
- type SaveInput
- type Saved
- type Service
- func (s *Service) AddComment(ctx context.Context, actor *model.User, in CommentInput) error
- func (s *Service) CanPrompt(ctx context.Context, actor *model.User) error
- func (s *Service) CheckComment(ctx context.Context, actor *model.User, postID, replyTo string) error
- func (s *Service) CheckEdit(ctx context.Context, actor *model.User, post *model.Post) error
- func (s *Service) Delete(ctx context.Context, actor *model.User, postID string) error
- func (s *Service) DeleteDraft(ctx context.Context, actor *model.User, postID string) error
- func (s *Service) DirectConnections(ctx context.Context, actor *model.User) ([]*model.User, error)
- func (s *Service) DismissPrompt(ctx context.Context, actor *model.User, promptID string) error
- func (s *Service) EditComment(ctx context.Context, actor *model.User, commentID, body string) error
- func (s *Service) ExportBlog(ctx context.Context, actor *model.User) ([]byte, error)
- func (s *Service) ExportPost(ctx context.Context, authorID, postID string) ([]byte, error)
- func (s *Service) FanOutComment(ctx context.Context, a CommentPostedArgs) error
- func (s *Service) FanOutPublished(ctx context.Context, a PublishedArgs) error
- func (s *Service) ForEdit(ctx context.Context, actor *model.User, postID string) (*EditView, error)
- func (s *Service) Import(ctx context.Context, actor *model.User, archive []byte) (*postops.InjectStats, error)
- func (s *Service) InjectPosts(ctx context.Context, actor *model.User, posts []*postops.PostWithMeta, ...) (*postops.InjectStats, error)
- func (s *Service) List(ctx context.Context, actor *model.User, in ListInput) (*Listing, error)
- func (s *Service) PostURL(postID string) string
- func (s *Service) PromptFor(ctx context.Context, actor *model.User, promptID string) (*postops.PostPrompt, error)
- func (s *Service) RegisterJobs(r *jobs.Registry)
- func (s *Service) RenderComment(ctx context.Context, a CommentMailArgs) (*mail.Envelope, error)
- func (s *Service) RenderNewPost(ctx context.Context, a NewPostMailArgs) (*mail.Envelope, error)
- func (s *Service) RenderPrompt(ctx context.Context, a PromptMailArgs) (*mail.Envelope, error)
- func (s *Service) RenderPromptAnswer(ctx context.Context, a PromptAnswerMailArgs) (*mail.Envelope, error)
- func (s *Service) Save(ctx context.Context, actor *model.User, in SaveInput) (*Saved, error)
- func (s *Service) SendPrompt(ctx context.Context, actor, recipient *model.User, message string) error
- func (s *Service) SubscriberReach(ctx context.Context, actor *model.User, post *model.Post) (*SubscriberReach, error)
- func (s *Service) TextLimits() TextLimits
- func (s *Service) UploadImage(ctx context.Context, actor *model.User, r io.Reader) (string, error)
- type SubscriberReach
- type Subscribers
- type TextLimits
Constants ¶
const ( DefaultCommentMaxLength = 6_000 DefaultPostBodyMaxLength = 20_000 DefaultPostSubjectMaxLength = 100 DefaultPromptMaxLength = 1_400 )
Default text limits, used for every limit the configuration leaves zero; they are also the configuration's defaults.
const ( CommentMinLength = 3 PromptMinLength = 3 )
Minimum lengths are not tunable.
const ListMax = 100
ListMax is the most posts one call of List returns.
Variables ¶
var DefaultTextLimits = TextLimits{ CommentMaxLength: DefaultCommentMaxLength, PostBodyMaxLength: DefaultPostBodyMaxLength, PostSubjectMaxLength: DefaultPostSubjectMaxLength, PromptMaxLength: DefaultPromptMaxLength, }
DefaultTextLimits are the limits of a service built without configuration.
Functions ¶
This section is empty.
Types ¶
type CommentInput ¶
type CommentInput struct {
PostID string
// ReplyTo is the comment being answered, empty for a top level comment.
ReplyTo string
Body string
}
CommentInput is a comment as its author submitted it.
type CommentMailArgs ¶
type CommentMailArgs struct {
CommentID string `json:"comment_id"`
RecipientID string `json:"recipient_id"`
Edited bool `json:"edited"`
}
CommentMailArgs is the mail about a new or edited comment to the post's author or to another participant of the discussion; the recipient decides which of the two it is.
type CommentPostedArgs ¶
CommentPostedArgs is the job adding or editing a comment enqueues: its worker tells the post's author and the other participants. It is not unique: an edit made while an earlier fan-out runs gets a fan-out of its own, and sent_emails drops the mails that end up the same.
type EditView ¶
type EditView struct {
// Post has its author, stats and linked URL loaded.
Post *model.Post
Prompt *postops.PostPrompt
}
EditView is a post as the edit page shows it.
type ListInput ¶
type ListInput struct {
// UpdatedSince is a Unix time; only posts updated after it are listed.
UpdatedSince int64
// Cursor is the Cursor of the previous page.
Cursor string
// Limit is the page size, between 1 and ListMax.
Limit int
}
ListInput selects a page of the actor's posts.
type NewPostMailArgs ¶
type NewPostMailArgs struct {
PostID string `json:"post_id"`
ConnectionID string `json:"connection_id"`
}
NewPostMailArgs is the mail that tells a connection of the author about a published post.
type Option ¶
type Option func(*Service)
Option changes how New builds the service.
func WithIdentity ¶
WithIdentity tells the service the site its mail links point to and the address the mail comes from.
func WithMaxUploadSize ¶
WithMaxUploadSize sets the most bytes an uploaded or imported image may have; zero keeps the media service's default.
func WithSubscriptions ¶
func WithSubscriptions(subs Subscribers) Option
WithSubscriptions lets saves mail posts to the author's email subscribers; without it nobody can subscribe to an author as far as this service knows.
func WithTextLimits ¶
func WithTextLimits(l TextLimits) Option
WithTextLimits sets the text length limits; a zero field keeps its default.
type PromptAnswerMailArgs ¶
type PromptAnswerMailArgs struct {
PostID string `json:"post_id"`
}
PromptAnswerMailArgs is the mail that tells the asker of a prompt that the post answering it is published.
func (PromptAnswerMailArgs) Kind ¶
func (PromptAnswerMailArgs) Kind() string
Kind names the job kind.
type PromptMailArgs ¶
type PromptMailArgs struct {
PromptID string `json:"prompt_id"`
RecipientID string `json:"recipient_id"`
}
PromptMailArgs is the mail that tells a user about a prompt to write.
type PublishedArgs ¶
type PublishedArgs struct {
PostID string `json:"post_id"`
}
PublishedArgs is the job saving a published post enqueues: it tells the author's direct connections. It is unique by post, so a post saved again before the job ran is fanned out once.
func (PublishedArgs) InsertOpts ¶
func (PublishedArgs) InsertOpts() river.InsertOpts
InsertOpts makes the job unique by post.
type SaveInput ¶
type SaveInput struct {
// PostID is the post to change, empty for a new one.
PostID string
// PromptID is the prompt a new post answers, if any.
PromptID string
Subject string
URL string
Body string
Visibility model.PostVisibility
Action Action
// NotifySubscribers says whether the save mails the post to the author's
// email subscribers. Nil takes the default: yes on the save that
// publishes the post, no on any other save, such as one that makes a
// published post public. It counts only for a save the author asked for
// (never an autosave) that leaves the post published and public, and a
// post is mailed to its subscribers at most once.
NotifySubscribers *bool
}
SaveInput is a post as the author submitted it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) AddComment ¶
AddComment leaves a comment on a post the actor is connected to, and tells the post's author and everybody else who commented on it.
func (*Service) CanPrompt ¶
CanPrompt reports whether the actor may send a prompt right now: prompts are rate limited. The error reads as a sentence.
func (*Service) CheckComment ¶
func (s *Service) CheckComment(ctx context.Context, actor *model.User, postID, replyTo string) error
CheckComment reports whether the actor may leave a comment on the post, as a reply to replyTo if it is not empty: ErrNotFound for a post or a comment that is not there and for somebody else's draft, ErrForbidden for the actor's own draft and for a post the actor is not connected to.
func (*Service) CheckEdit ¶
CheckEdit reports whether the actor may edit the post: only its author may, as postops.GetPostCapabilities says. Anybody else gets ErrForbidden.
func (*Service) Delete ¶
Delete removes the actor's post, draft or published. Somebody else's post is not found.
func (*Service) DeleteDraft ¶
DeleteDraft removes the actor's post if it is still a draft. What the author sees when there is no such draft is the database's own words, as it always was.
func (*Service) DirectConnections ¶
DirectConnections lists the actor's direct connections, the users they may prompt.
func (*Service) DismissPrompt ¶
DismissPrompt hides a prompt addressed to the actor. What the actor sees when there is no such prompt is the database's own words, as it always was.
func (*Service) EditComment ¶
EditComment replaces the body of the actor's own comment and tells the post's author and the other participants about it. The actor must still be connected to the post's author. The comment stays as it is, and nobody is told, when the body does not change.
func (*Service) ExportBlog ¶
ExportBlog is every post of the actor, with the images they embed, as a zip archive.
func (*Service) ExportPost ¶
ExportPost is one post of its author, with the images it embeds, as a zip archive. Whether the viewer may see the post is for the caller to decide.
func (*Service) FanOutComment ¶
func (s *Service) FanOutComment(ctx context.Context, a CommentPostedArgs) error
FanOutComment enqueues the comment mail of the post's author and of every other participant who may read the comments now, except the comment's own author, in one transaction. A comment or post gone since enqueues nothing.
func (*Service) FanOutPublished ¶
func (s *Service) FanOutPublished(ctx context.Context, a PublishedArgs) error
FanOutPublished enqueues the new post mail of every direct connection of the post's author, in one transaction. A mail already sent is dropped by its unique id, so running the job again sends nothing twice.
func (*Service) ForEdit ¶
ForEdit loads the actor's post for the edit page: ErrNotFound if there is no such post, ErrForbidden if it is somebody else's.
func (*Service) Import ¶
func (s *Service) Import(ctx context.Context, actor *model.User, archive []byte) (*postops.InjectStats, error)
Import adds the posts and images of an exported archive to the actor's blog. A post that is the actor's own already is updated in place.
func (*Service) InjectPosts ¶
func (s *Service) InjectPosts(ctx context.Context, actor *model.User, posts []*postops.PostWithMeta, images map[string][]byte) (*postops.InjectStats, error)
InjectPosts stores parsed posts and images in the actor's blog, in one transaction. A post the actor owns already is updated in place, any other is created. An image the actor uploaded under that name before is not uploaded again.
func (*Service) PromptFor ¶
func (s *Service) PromptFor(ctx context.Context, actor *model.User, promptID string) (*postops.PostPrompt, error)
PromptFor returns the prompt with the given ID if it is addressed to the actor, and nil otherwise.
func (*Service) RegisterJobs ¶
RegisterJobs registers the workers of the service's job kinds on r.
func (*Service) RenderComment ¶
RenderComment builds the mail about a comment, as the comment and its post are now.
func (*Service) RenderNewPost ¶
RenderNewPost builds the mail that tells a connection about a post, as the post is now.
func (*Service) RenderPrompt ¶
RenderPrompt builds the mail about a prompt.
func (*Service) RenderPromptAnswer ¶
func (s *Service) RenderPromptAnswer(ctx context.Context, a PromptAnswerMailArgs) (*mail.Envelope, error)
RenderPromptAnswer builds the mail that tells the asker about the post answering their prompt.
func (*Service) Save ¶
Save creates or changes the actor's post, or deletes it. Publishing notifies the author's direct connections, and the asker of the prompt the post answers, in the same transaction; then, as SaveInput.NotifySubscribers decides, the author's email subscribers.
func (*Service) SendPrompt ¶
func (s *Service) SendPrompt(ctx context.Context, actor, recipient *model.User, message string) error
SendPrompt asks a user to write a post on a subject, and tells them by mail. The recipient must be a direct connection of the actor; anyone else is refused with the wording the prompt form always used.
func (*Service) SubscriberReach ¶
func (s *Service) SubscriberReach(ctx context.Context, actor *model.User, post *model.Post) (*SubscriberReach, error)
SubscriberReach tells the actor about their email subscribers for the form of post, nil for a new post. Nobody can subscribe to an anonymous actor.
func (*Service) TextLimits ¶
func (s *Service) TextLimits() TextLimits
TextLimits returns the service's text length limits. Forms read them to check their fields; the service enforces them on save.
type SubscriberReach ¶
type SubscriberReach struct {
// Subscribable is whether readers may subscribe to the author; the
// Public option then names Count.
Subscribable bool
// Count is how many confirmed subscribers the author has.
Count int
// CanNotify is whether the form offers to mail the post to them: the
// author can be subscribed to, has subscribers, and the post was never
// mailed to them.
CanNotify bool
// NotifyByDefault is whether the offer starts checked: it does for a
// post that isn't published yet, as its publish mails it by default.
NotifyByDefault bool
}
SubscriberReach is what the post form tells the author about their email subscribers.
type Subscribers ¶
type Subscribers interface {
Subscribable(author *model.User) bool
ActiveCount(ctx context.Context, tx *repo.Store, authorID string) (int, error)
NotifyPost(ctx context.Context, tx *repo.Store, author *model.User, post *model.Post) error
}
Subscribers is what a save needs of the email subscriptions service (*subscriptions.Service).