eventNotification

package
v0.2.62 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	EventTypeComment   = "comment"    // 主题收到新 post
	EventTypePostReply = "post_reply" // post 回复通知
	EventTypeTopicPost = "topic_post" // 关注主题的新 post 通知
	EventTypeSystem    = "system"     // 系统通知
	EventTypeFollow    = "follow"     // 关注通知
	EventTypeBadge     = "badge"      // 徽章通知
)

Event Types

View Source
const (
	TemplateComment   = "notifications.templates.comment"
	TemplatePostReply = "notifications.templates.postReply"
	TemplateTopicPost = "notifications.templates.topicPost"
	TemplateFollow    = "notifications.templates.follow"
	TemplateBadge     = "notifications.templates.badge"
)

Variables

This section is empty.

Functions

func Create

func Create(entity *Entity) error

Create 创建通知

func CreateBatch added in v0.2.12

func CreateBatch(entities []*Entity, batchSize int) error

func GetUnreadCount

func GetUnreadCount(userId uint64) (count int64, err error)

GetUnreadCount 获取用户未读通知数量

func GetUnreadCountForAudience added in v0.2.61

func GetUnreadCountForAudience(userID uint64, readableCategoryIDs []uint64, filterAudience bool) (count int64, err error)

func MarkAllAsRead

func MarkAllAsRead(userId uint64) error

MarkAllAsRead 标记用户所有通知为已读

func MarkAsRead

func MarkAsRead(notificationId uint64, userId uint64) error

MarkAsRead 标记通知为已读

Types

type Entity

type Entity struct {
	Id     uint64 `` /* 128-byte string literal not displayed */
	UserId uint64 `` // 接收通知的用户ID
	/* 169-byte string literal not displayed */
	TopicId   uint64              `gorm:"column:topic_id;type:bigint unsigned;not null;default:0;index:idx_notification_topic;" json:"topicId"`
	Payload   NotificationPayload `gorm:"column:payload;type:json;serializer:json" json:"payload"`                                // 通知内容(JSON)
	EventType string              `gorm:"column:event_type;type:varchar(16);index:idx_user_id_event_type_read;" json:"eventType"` // 通知类型
	IsRead    bool                ``                                                                                              // 是否已读
	/* 150-byte string literal not displayed */
	ReadAt    *time.Time `gorm:"column:read_at;type:timestamp;null;" json:"readAt"`                  // 读取时间
	CreatedAt time.Time  `gorm:"column:created_at;index;autoCreateTime;<-:create;" json:"createdAt"` // 创建时间
	UpdatedAt time.Time  `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`                 // 更新时间
}

func GetLastUnread added in v0.0.3

func GetLastUnread(userId uint64) (entity Entity)

GetLastUnread 获取用户未读通知数量

func GetLastUnreadForAudience added in v0.2.61

func GetLastUnreadForAudience(userID uint64, readableCategoryIDs []uint64, filterAudience bool) (entity Entity)

func QueryByUserId added in v0.0.3

func QueryByUserId(userId uint64, limit int, startId uint64, unreadOnly bool) (notifications []*Entity, err error)

QueryByUserId 获取用户的通知列表

func QueryByUserIdForAudience added in v0.2.61

func QueryByUserIdForAudience(userID uint64, limit int, startID uint64, unreadOnly bool, readableCategoryIDs []uint64, filterAudience bool) (notifications []*Entity, err error)

func (*Entity) TableName

func (itself *Entity) TableName() string

type Extra added in v0.0.10

type Extra struct {
	FollowerName string `json:"followerName"`
	BadgeCode    string `json:"badgeCode,omitempty"`
	BadgeName    string `json:"badgeName,omitempty"`
	BadgeIconURL string `json:"badgeIconUrl,omitempty"`
	ProfileURL   string `json:"profileUrl,omitempty"`
}

type NotificationPayload

type NotificationPayload struct {
	Title          string                     `json:"title,omitempty"`
	Content        string                     `json:"content,omitempty"`
	TemplateKey    string                     `json:"templateKey,omitempty"`
	TemplateParams NotificationTemplateParams `json:"templateParams"`
	// 通用字段
	ActorId   uint64 `json:"actorId"`             // 触发者ID
	ActorName string `json:"actorName,omitempty"` // 触发者名称
	// Topic / post references
	TopicId    uint64 `json:"topicId,omitempty"`
	TopicTitle string `json:"topicTitle,omitempty"`
	PostId     uint64 `json:"postId,omitempty"`
	// 其他元数据
	Extra Extra `json:"metadata"`
}

NotificationPayload 通知内容的基础结构

type NotificationTemplateParams added in v0.2.12

type NotificationTemplateParams struct {
	Preview      string `json:"preview,omitempty"`
	FollowerName string `json:"followerName,omitempty"`
	BadgeCode    string `json:"badgeCode,omitempty"`
	BadgeName    string `json:"badgeName,omitempty"`
}

Jump to

Keyboard shortcuts

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