notify

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 19 Imported by: 0

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

View Source
const (
	MaxTitle   = 64
	MaxContent = 10000
)

Limits, in characters.

View Source
const (
	AudienceAll   = "all"
	AudienceUsers = "users" // ordinary users, not administrators (Blessing Skin's "normal")
)

Audiences of an announcement.

Variables

View Source
var ErrNotFound = errors.New("notification not found")

ErrNotFound means the user has no such notification.

Functions

func Markdown

func Markdown(src string) string

Markdown renders Markdown to HTML that is safe to put in a page as it is: no raw HTML, no script links.

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

func NewService(db *ent.Client, log *slog.Logger) *Service

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

func (s *Service) MarkAllRead(ctx context.Context, userID int64) (int, error)

MarkAllRead marks all of the user's notifications read and returns how many were unread.

func (*Service) MarkRead

func (s *Service) MarkRead(ctx context.Context, userID, id int64) error

MarkRead marks one of the user's notifications read (reading it again is fine).

func (*Service) Send

func (s *Service) Send(ctx context.Context, userID int64, title, content string, rec *audit.Entry) (*ent.Notification, error)

Send puts a notification in one user's inbox. rec, if not nil, is written to the audit log in the same transaction, naming the new notification.

func (*Service) Unread

func (s *Service) Unread(ctx context.Context, userID int64) (int, error)

Unread is how many unread notifications the user has.

Jump to

Keyboard shortcuts

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