notification

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeDmRequest        int16 = -1
	CodeFriendRequest    int16 = -2
	CodeFriendAccept     int16 = -3
	CodeGroupAdd         int16 = -4
	CodeGroupJoinRequest int16 = -5
	CodeFriendJoinGame   int16 = -6
	CodeSingleSocket     int16 = -7
	CodeUserBanned       int16 = -8
	CodeFriendRemove     int16 = -9
	CodeFriendImport     int16 = -1001 // UGE extension (custom negative band)
)

Reserved system notification codes (reference-aligned).

Variables

View Source
var (
	ErrNotificationCursorInvalid = errors.New("notification cursor invalid")
	ErrNotificationCodeInvalid   = errors.New("notification code invalid")
)

Functions

func CreateNotification

func CreateNotification(ctx context.Context, pool *pgxpool.Pool, notif *Notification) error

CreateNotification inserts a persistent notification (legacy helper). Prefer NotificationSend.

func NotificationDelete

func NotificationDelete(ctx context.Context, pool *pgxpool.Pool, userID string, ids []string) error

NotificationDelete deletes notifications for a user by id.

func NotificationSave

func NotificationSave(ctx context.Context, pool *pgxpool.Pool, notifications map[string][]*Notification) error

NotificationSave batch-inserts notifications.

func NotificationSend

func NotificationSend(ctx context.Context, pool *pgxpool.Pool, deliver Deliverer, notifications map[string][]*Notification) error

NotificationSend persists persistent notifications and delivers all to online recipients.

func NotificationSendAll

func NotificationSendAll(ctx context.Context, pool *pgxpool.Pool, deliver Deliverer, n *Notification) error

NotificationSendAll sends one notification to all users (persistent) or all connected (non-persistent).

func NotificationsDeleteId

func NotificationsDeleteId(ctx context.Context, pool *pgxpool.Pool, userID string, ids ...string) error

NotificationsDeleteId deletes by ids; empty userID deletes globally by id.

func NotificationsUpdate

func NotificationsUpdate(ctx context.Context, pool *pgxpool.Pool, updates ...NotificationUpdate) error

NotificationsUpdate applies partial updates.

func ValidateRuntimeCode

func ValidateRuntimeCode(code int16) error

ValidateRuntimeCode checks runtime/game send codes (>0 or [-2000,-1000]).

Types

type Deliverer

type Deliverer interface {
	SendNotifications(userID string, notifs []*Notification)
	// SendNotificationsToAll delivers to every connected notifications-stream session (non-persistent send-all).
	SendNotificationsToAll(notifs []*Notification)
}

Deliverer pushes live notifications to online sessions.

var DefaultDeliverer Deliverer = noopDeliverer{}

DefaultDeliverer is set by the API/socket layer at startup.

type List

type List struct {
	Notifications   []*Notification `json:"notifications"`
	CacheableCursor string          `json:"cacheable_cursor,omitempty"`
}

List is a paginated list response.

func NotificationList

func NotificationList(ctx context.Context, pool *pgxpool.Pool, userID string, limit int, cursor string) (*List, error)

NotificationList lists persistent notifications ASC with cacheable_cursor.

type Notification

type Notification struct {
	ID         string    `json:"id"`
	UserID     string    `json:"user_id"`
	Subject    string    `json:"subject"`
	Content    string    `json:"content"`
	Code       int16     `json:"code"`
	SenderID   string    `json:"sender_id"`
	CreateTime time.Time `json:"create_time"`
	Persistent bool      `json:"persistent"`
}

Notification is an in-app notification (DB row and/or wire payload).

func ListNotifications

func ListNotifications(ctx context.Context, pool *pgxpool.Pool, userID string, limit int) ([]*Notification, error)

ListNotifications is a convenience wrapper (limit default 100 for runtime).

func NotificationsGetId

func NotificationsGetId(ctx context.Context, pool *pgxpool.Pool, userID string, ids ...string) ([]*Notification, error)

NotificationsGetId returns notifications by id for a user (empty userID = any user / admin).

type NotificationUpdate

type NotificationUpdate struct {
	ID       string
	Subject  *string
	Content  *string
	SenderID *string
}

NotificationUpdate is a partial update request.

Jump to

Keyboard shortcuts

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