Documentation
¶
Overview ¶
Package notificationcenter is an in-app notification inbox for togo — the "database channel" + bell that complements the notifications plugin (which delivers to external providers like email/Slack/push).
Store a per-user notification, list the inbox, count unread, and mark read/deleted. A current user is resolved from the request context (X-User-Id header or an auth claim).
nc, _ := notificationcenter.FromKernel(k)
nc.Notify(ctx, "user-1", notificationcenter.Notification{
Type: "comment", Title: "New comment", Body: "Sam replied to you", ActionURL: "/posts/9",
})
Index ¶
- func WithUser(ctx context.Context, userID string) context.Context
- type Filter
- type Notification
- type Service
- func (s *Service) Delete(id string) bool
- func (s *Service) List(userID string, f Filter) []*Notification
- func (s *Service) MarkAllRead(userID string) int
- func (s *Service) MarkRead(id string) bool
- func (s *Service) Notify(ctx context.Context, userID string, n Notification) *Notification
- func (s *Service) UnreadCount(userID string) int
- func (s *Service) WithStore(store Store) *Service
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Notification ¶
type Notification struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Type string `json:"type,omitempty"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
Data map[string]any `json:"data,omitempty"`
ActionURL string `json:"action_url,omitempty"`
Read bool `json:"read"`
CreatedAt time.Time `json:"created_at"`
ReadAt *time.Time `json:"read_at,omitempty"`
}
Notification is a single inbox item for a user.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the notification-center runtime stored on the kernel.
func FromKernel ¶
FromKernel returns the notification-center Service.
func (*Service) List ¶
func (s *Service) List(userID string, f Filter) []*Notification
List returns a user's notifications, newest first.
func (*Service) MarkAllRead ¶
MarkAllRead marks every notification for a user read; returns how many changed.
func (*Service) Notify ¶
func (s *Service) Notify(ctx context.Context, userID string, n Notification) *Notification
Notify stores a notification for a user and returns the stored record. If a realtime broker is present on the kernel it is also published so a connected bell can update live.
func (*Service) UnreadCount ¶
UnreadCount returns the number of unread notifications for a user.
type Store ¶
type Store interface {
Add(n *Notification)
ByUser(userID string) []*Notification
Get(id string) (*Notification, bool)
Delete(id string) bool
}
Store is the persistence seam (swap the default in-memory store for a DB one).