Documentation
¶
Overview ¶
Package subscriptions - the subscriptions module: users follow a content item's comments or a term's new content; what happens there becomes their notifications, on the site (the profile's Notifications tab, the user menu) and by e-mail (at once, a daily digest or never).
Index ¶
- Constants
- Variables
- func RegisterRoutes(r modulekit.Mux, store *sessions.CookieStore, c *Controller)
- func Wire(d modulekit.Deps) modulekit.Parts
- type Controller
- func (c *Controller) Follow(w http.ResponseWriter, r *http.Request)
- func (c *Controller) NodePage(ctx context.Context, node modulekit.Node) modulekit.NodePageParts
- func (c *Controller) Open(w http.ResponseWriter, r *http.Request)
- func (c *Controller) PageData(r *http.Request, data map[string]any)
- func (c *Controller) ProfileTab() modulekit.ProfileTab
- func (c *Controller) ReadAll(w http.ResponseWriter, r *http.Request)
- func (c *Controller) TermPage(ctx context.Context, term modulekit.TaxonomyTerm) any
- func (c *Controller) Unfollow(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Unsubscribe(w http.ResponseWriter, r *http.Request)
- type FollowState
- type Item
- type MailTemplate
- type Mailer
- type MailerDeps
- type Notification
- type Notifier
- type Repo
- func (r *Repo) AddNotifications(ctx context.Context, ns []Notification, mailed map[int]bool) error
- func (r *Repo) AutoSubscribe(ctx context.Context, userID int, t Target) error
- func (r *Repo) DeleteOlder(ctx context.Context, t time.Time) (int, error)
- func (r *Repo) Followers(ctx context.Context, t Target) (map[int]Subscription, error)
- func (r *Repo) MailDef() modulekit.MailDef
- func (r *Repo) MailTemplate(ctx context.Context) (MailTemplate, error)
- func (r *Repo) MarkAllRead(ctx context.Context, userID int) error
- func (r *Repo) MarkRead(ctx context.Context, n Notification) error
- func (r *Repo) Notification(ctx context.Context, userID, id int) (*Notification, error)
- func (r *Repo) Notifications(ctx context.Context, userID, offset, limit int) ([]Notification, int, error)
- func (r *Repo) SaveMailTemplate(ctx context.Context, t MailTemplate) error
- func (r *Repo) SaveUserSettings(ctx context.Context, userID int, s UserSettings) error
- func (r *Repo) Subscribe(ctx context.Context, userID int, t Target) error
- func (r *Repo) Subscribed(ctx context.Context, userID int, t Target) (bool, error)
- func (r *Repo) SubscriptionByID(ctx context.Context, userID, id int) (*Subscription, error)
- func (r *Repo) SubscriptionByToken(ctx context.Context, token string) (*Subscription, error)
- func (r *Repo) TermFollowers(ctx context.Context, termIDs []int) (map[int]Subscription, error)
- func (r *Repo) ToldOfContent(ctx context.Context, nodeID int, userIDs []int) (map[int]bool, error)
- func (r *Repo) UnreadCount(ctx context.Context, userID int) (int, error)
- func (r *Repo) Unsubscribe(ctx context.Context, userID int, t Target) error
- func (r *Repo) UserSettings(ctx context.Context, userIDs []int) (map[int]UserSettings, error)
- func (r *Repo) UserSettingsSection() modulekit.UserSettingsSection
- func (r *Repo) UserSubscriptions(ctx context.Context, userID int) ([]Subscription, error)
- func (r *Repo) WaitingMail(ctx context.Context) (map[int][]Notification, error)
- type Subscription
- type SubscriptionView
- type Target
- type UserSettings
Constants ¶
const ( // KindReply - a reply to the user's comment. KindReply = "reply" // KindComment - a comment on content the user follows. KindComment = "comment" // KindContent - new content with a term the user follows. KindContent = "content" )
The kinds of notifications.
const ( MailNow = "now" MailDaily = "daily" MailNever = "never" )
The users' e-mail modes.
const DigestHour = 8
DigestHour - the hour of the site's day the daily digests go out at.
const MailNotifications = manifest.Name + ".notifications"
MailNotifications - the notifications e-mail (modulekit.AddMail).
Variables ¶
var Assets embed.FS
Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.
var MailPlaceholders = []string{"[subscriptions:subject]", "[subscriptions:list]", "[subscriptions:url]"}
MailPlaceholders - the module's placeholders of the e-mail: its subject (what it tells of, or how many things), the list of what happened and the Notifications tab's address.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(r modulekit.Mux, store *sessions.CookieStore, c *Controller)
RegisterRoutes registers the module's pages: following content and terms, the tab's actions, a notification's link (a guest signs in first), the e-mails' unsubscribe link (no sign-in).
func Wire ¶
Wire - the module's tables, the notifier on the core's events (a comment posted, content becoming public), the e-mails' background jobs, the profile's settings and Notifications tab, the e-mail (its text on the Mail page), the buttons of content and terms, the unread count on the user menu.
Types ¶
type Controller ¶
type Controller struct {
*modulekit.BaseController
// contains filtered or unexported fields
}
Controller - the module's pages: following content and terms, the Notifications tab, a notification's link, the e-mails' unsubscribe link.
func NewController ¶
func NewController(base *modulekit.BaseController, repo *Repo, d describeDeps, nodes interface { ByID(ctx context.Context, nodeID int) (*modulekit.Node, error) }, terms interface { TermByID(ctx context.Context, id int) (*modulekit.TaxonomyTerm, error) }) *Controller
NewController - the module's pages on base and repo; d names the notifications' items, nodes and terms load what is followed.
func (*Controller) Follow ¶
func (c *Controller) Follow(w http.ResponseWriter, r *http.Request)
Follow handles POST /subscriptions/follow/{kind}/{id} (kind: node or term): action "unsubscribe" stops following, else follows (public content only: the tab shows the titles of what the user follows); back to the page.
func (*Controller) NodePage ¶
func (c *Controller) NodePage(ctx context.Context, node modulekit.Node) modulekit.NodePageParts
NodePage - the module's part of a content page (AddNodePage): its comments' subscription button, on public content only (the others' comments tell nobody).
func (*Controller) Open ¶
func (c *Controller) Open(w http.ResponseWriter, r *http.Request)
Open handles GET /notifications/{id}: the notification (with the rest of its group) read, to what it tells of. A guest signs in first.
func (*Controller) PageData ¶
func (c *Controller) PageData(r *http.Request, data map[string]any)
PageData - every page's data (AddPageData): the signed-in user's unread notifications, data["subscriptionsUnread"] (the user menu's item) and on the user menu's toggle.
func (*Controller) ProfileTab ¶
func (c *Controller) ProfileTab() modulekit.ProfileTab
ProfileTab - the Notifications tab: the viewer's own only.
func (*Controller) ReadAll ¶
func (c *Controller) ReadAll(w http.ResponseWriter, r *http.Request)
ReadAll handles POST /notifications/read: every notification of the user read; back to the tab.
func (*Controller) TermPage ¶
func (c *Controller) TermPage(ctx context.Context, term modulekit.TaxonomyTerm) any
TermPage - the module's part of a term's page (AddTermPage): its follow button.
func (*Controller) Unfollow ¶
func (c *Controller) Unfollow(w http.ResponseWriter, r *http.Request)
Unfollow handles POST /subscriptions/delete/{id}: the tab's unsubscribe button.
func (*Controller) Unsubscribe ¶
func (c *Controller) Unsubscribe(w http.ResponseWriter, r *http.Request)
Unsubscribe handles GET and POST /subscriptions/unsubscribe/{token}: an e-mail's unsubscribe link, no sign-in needed - GET asks, POST does it (a mail client opening links mustn't unsubscribe anyone).
type FollowState ¶
type FollowState struct {
SignedIn bool
Following bool
// Action - where the button posts; Back - where to come back.
Action string
Back string
}
FollowState - the subscription button of a content item's comments or a term (comments_actions_subscriptions, term_actions_subscriptions).
type Item ¶
type Item struct {
Notification
Actor string
Actors []string
Count int
NodeTitle string
NodeURL string
TermName string
Excerpt string
}
Item - a notification as shown: on the Notifications tab (where the comments of one content item are one item: Count, Actors) and in an e-mail.
type MailTemplate ¶
type MailTemplate = modulekit.MailTemplate
MailTemplate - the notifications e-mail's subject and body: the core's placeholders ([site:…], [user:…]) and the module's (MailPlaceholders).
type Mailer ¶
type Mailer struct {
// contains filtered or unexported fields
}
Mailer - the notifications' e-mails: at once (a minute's events in one e-mail), the daily digest, and the cleanup of old notifications.
func NewMailer ¶
func NewMailer(d MailerDeps) *Mailer
NewMailer - the notifications' e-mails with the repository, users, site, mail sender and visitor of d.
func (*Mailer) SendDigests ¶
SendDigests mails the daily digests: once a day, from DigestHour of the site's day.
type MailerDeps ¶
type MailerDeps struct {
Repo *Repo
Describe describeDeps
Users interface {
ByID(ctx context.Context, id int) (*modulekit.User, error)
}
Site modulekit.SiteInformationRepository
Mail mailtemplate.Mailer
BaseURL func() string
Logger *slog.Logger
// Visitor - what of the content a user may not view
// (AuthService.ContentVisitor): no e-mail tells them of such content.
// Nil - nothing.
Visitor func(ctx context.Context, user *modulekit.User) (modulekit.ContentVisitor, error)
}
MailerDeps - what NewMailer needs.
type Notification ¶
type Notification struct {
ID int
UserID int
Kind string
NodeID int
CommentID int
ActorID int
TermID int
CreatedAt time.Time
Read bool
}
Notification - something told to a user.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier turns the core's events into notifications: a comment posted (CommentPosted) and a content item becoming public (NodePublished).
func NewNotifier ¶
func NewNotifier(repo *Repo, nodes notifierNodes, comments notifierComments, terms notifierTerms) *Notifier
NewNotifier - the notifier writing to repo; nodes, comments and terms are the core's, read for the events.
func (*Notifier) CommentPosted ¶
CommentPosted tells of comment c: the author of the comment it replies to (unless they turned the replies off), then the content's followers; nobody twice, nor its own author, who then follows the content (unless they turned that off or unsubscribed from it). Only of public content: the others can't see it.
func (*Notifier) NodePublished ¶
NodePublished tells of content node becoming public: its author follows its comments (unless they turned that off), and the followers of its terms are told of it, each once (published again, it tells nobody twice), its author not.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo - the module's tables.
func (*Repo) AddNotifications ¶
AddNotifications stores ns; mailed - whether each user's are to be e-mailed (their mode isn't "never").
func (*Repo) AutoSubscribe ¶
AutoSubscribe makes userID follow t unless they ever subscribed to it or unsubscribed from it.
func (*Repo) DeleteOlder ¶
DeleteOlder deletes the notifications from before t; how many.
func (*Repo) MailDef ¶
MailDef - the notifications e-mail on the Mail page: its text kept in the module's settings (MailTemplate, SaveMailTemplate).
func (*Repo) MailTemplate ¶
func (r *Repo) MailTemplate(ctx context.Context) (MailTemplate, error)
MailTemplate - the e-mail's template: a blank subject or body (never saved, or cleared) is the default's.
func (*Repo) MarkAllRead ¶
MarkAllRead marks every notification of userID read.
func (*Repo) MarkRead ¶
func (r *Repo) MarkRead(ctx context.Context, n Notification) error
MarkRead marks n read with the unread ones of the same content and kind (a group of comments is read at once).
func (*Repo) Notification ¶
Notification - userID's notification id; nil - none of theirs.
func (*Repo) Notifications ¶
func (r *Repo) Notifications(ctx context.Context, userID, offset, limit int) ([]Notification, int, error)
Notifications - a page of userID's notifications, newest first, and how many they have.
func (*Repo) SaveMailTemplate ¶
func (r *Repo) SaveMailTemplate(ctx context.Context, t MailTemplate) error
SaveMailTemplate stores the e-mail's template.
func (*Repo) SaveUserSettings ¶
SaveUserSettings stores userID's settings (the row made on the first save).
func (*Repo) Subscribed ¶
Subscribed - userID follows t (and didn't unsubscribe).
func (*Repo) SubscriptionByID ¶
SubscriptionByID - userID's subscription id; nil - none of theirs.
func (*Repo) SubscriptionByToken ¶
SubscriptionByToken - the subscription of an e-mail's unsubscribe link; nil - none.
func (*Repo) TermFollowers ¶
TermFollowers - the users following any of termIDs, with one of the subscriptions each (the first term's of the list they follow).
func (*Repo) ToldOfContent ¶
ToldOfContent - those of userIDs already told of the new content nodeID (a node published again tells nobody twice).
func (*Repo) UnreadCount ¶
UnreadCount - userID's notifications not opened yet.
func (*Repo) Unsubscribe ¶
Unsubscribe makes userID stop following t: the row stays muted, so an automatic subscription doesn't come back.
func (*Repo) UserSettings ¶
UserSettings - the settings of userIDs (the defaults for those who never saved theirs).
func (*Repo) UserSettingsSection ¶
func (r *Repo) UserSettingsSection() modulekit.UserSettingsSection
UserSettingsSection - the user's notification settings on their profile form (template "user_settings_subscriptions"): how often the e-mails come, the replies, the automatic subscriptions. The form marks the section shown (subscriptions_user_settings): a form without it (a theme's own) leaves them as they are.
func (*Repo) UserSubscriptions ¶
UserSubscriptions - what userID follows, newest first.
func (*Repo) WaitingMail ¶
WaitingMail - the notifications waiting for their e-mail, by user, oldest first.
type Subscription ¶
Subscription - a user following a Target.
type SubscriptionView ¶
type SubscriptionView struct {
Subscription
Title string
URL string
// Kind - the term's vocabulary, or empty for content.
Kind string
}
SubscriptionView - a subscription as the tab lists it.
type Target ¶
Target - what a subscription follows: a content item's comments (NodeID) or a term's new content (TermID).
type UserSettings ¶
UserSettings - a user's settings of the module; the zero row's are the defaults (DefaultUserSettings).
func DefaultUserSettings ¶
func DefaultUserSettings() UserSettings
DefaultUserSettings - the settings of a user who never saved theirs.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ent - the subscriptions module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
|
Package ent - the subscriptions module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema). |
|
schema
Package schema - the subscriptions module's own ent schema: its tables, apart from the core's.
|
Package schema - the subscriptions module's own ent schema: its tables, apart from the core's. |
|
Package manifest declares the subscriptions module (its registry entry): subscriptions to content's comments and to terms, the notifications of them on the site and by e-mail.
|
Package manifest declares the subscriptions module (its registry entry): subscriptions to content's comments and to terms, the notifications of them on the site and by e-mail. |