Documentation
¶
Index ¶
- Constants
- Variables
- func CreateNotification(ctx context.Context, pool *pgxpool.Pool, notif *Notification) error
- func NotificationDelete(ctx context.Context, pool *pgxpool.Pool, userID string, ids []string) error
- func NotificationSave(ctx context.Context, pool *pgxpool.Pool, ...) error
- func NotificationSend(ctx context.Context, pool *pgxpool.Pool, deliver Deliverer, ...) error
- func NotificationSendAll(ctx context.Context, pool *pgxpool.Pool, deliver Deliverer, n *Notification) error
- func NotificationsDeleteId(ctx context.Context, pool *pgxpool.Pool, userID string, ids ...string) error
- func NotificationsUpdate(ctx context.Context, pool *pgxpool.Pool, updates ...NotificationUpdate) error
- func ValidateRuntimeCode(code int16) error
- type Deliverer
- type List
- type Notification
- type NotificationUpdate
Constants ¶
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 ¶
var ( ErrNotificationCursorInvalid = errors.New("notification cursor invalid") ErrNotificationCodeInvalid = errors.New("notification code invalid") )
Functions ¶
func CreateNotification ¶
CreateNotification inserts a persistent notification (legacy helper). Prefer NotificationSend.
func NotificationDelete ¶
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 ¶
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.
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).