Documentation
¶
Overview ¶
Package notify keeps each user's inbox: notifications sent to them, and their copies of announcements sent to many. An announcement is one row when sent; a user gets their copy the next time they look at their inbox (Blessing Skin wrote one row per user at once, which on a big site is a long write while the administrator waits).
Index ¶
- Constants
- Variables
- func Markdown(src string) string
- type Filter
- type Service
- func (s *Service) Announce(ctx context.Context, sender *int64, audience, title, content string, ...) (*ent.Announcement, error)
- func (s *Service) List(ctx context.Context, userID int64, f Filter) ([]*ent.Notification, int64, error)
- func (s *Service) MarkAllRead(ctx context.Context, userID int64) (int, error)
- func (s *Service) MarkRead(ctx context.Context, userID, id int64) error
- func (s *Service) Send(ctx context.Context, userID int64, title, content string, rec *audit.Entry) (*ent.Notification, error)
- func (s *Service) Unread(ctx context.Context, userID int64) (int, error)
Constants ¶
const ( MaxTitle = 64 MaxContent = 10000 )
Limits, in characters.
const ( AudienceAll = "all" AudienceUsers = "users" // ordinary users, not administrators (Blessing Skin's "normal") )
Audiences of an announcement.
Variables ¶
var ErrNotFound = errors.New("notification not found")
ErrNotFound means the user has no such notification.
Functions ¶
Types ¶
type Filter ¶
type Filter struct {
Unread bool
Before int64 // notifications with smaller ids (the next page)
Limit int // 1–100, default 20
}
Filter selects notifications, newest first.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements inboxes.
func NewService ¶
NewService creates the service.
func (*Service) Announce ¶
func (s *Service) Announce(ctx context.Context, sender *int64, audience, title, content string, rec *audit.Entry) (*ent.Announcement, error)
Announce sends a notification to every user of audience who exists now (later users do not get it, as with Blessing Skin). sender is nil for the admin token. rec, if not nil, is written to the audit log in the same transaction.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, userID int64, f Filter) ([]*ent.Notification, int64, error)
List returns one page of the user's inbox and the id to pass as Before for the next page (0 on the last page).
func (*Service) MarkAllRead ¶
MarkAllRead marks all of the user's notifications read and returns how many were unread.
func (*Service) MarkRead ¶
MarkRead marks one of the user's notifications read (reading it again is fine).