userActivities

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubjectTopic = "Topic"
	SubjectPost  = "Post"
	SubjectUser  = "User"
)

SubjectType 目标对象类型

Variables

This section is empty.

Functions

func Record

func Record(userId uint64, action ActionType, subjectType string, subjectId uint64, preview string) error

Record 记录一条用户行为

func RecordWithTime

func RecordWithTime(userId uint64, action ActionType, subjectType string, subjectId uint64, preview string, t time.Time) error

RecordWithTime 记录一条带有指定时间的用户行为(用于数据修复)

Types

type ActionCount added in v0.2.2

type ActionCount struct {
	Action int
	Count  int64
}

func CountActionsByUser added in v0.2.2

func CountActionsByUser(userId uint64) (items []ActionCount)

type ActionType

type ActionType int

ActionType 行为类型枚举

const (
	ActionSignUp  ActionType = 1 // 注册帐号
	ActionPost    ActionType = 2 // 发帖/发布话题
	ActionLike    ActionType = 3 // 点赞
	ActionFollow  ActionType = 4 // 关注
	ActionComment ActionType = 5 // 回复/评论
)

type Entity

type Entity struct {
	Id             uint64    `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`                                                // 主键
	UserId         uint64    `gorm:"column:user_id;type:bigint unsigned;not null;default:0;index:idx_user_activity_created;" json:"userId"` // 发起者 ID
	Action         int       `gorm:"column:action;type:int;not null;default:0;" json:"action"`                                              // 行为类型
	SubjectType    string    `gorm:"column:subject_type;type:varchar(32);not null;default:'';" json:"subjectType"`                          // 目标类型
	SubjectId      uint64    `gorm:"column:subject_id;type:bigint unsigned;not null;default:0;" json:"subjectId"`                           // 目标 ID
	ContentPreview string    `gorm:"column:content_preview;type:text;" json:"contentPreview"`                                               // 内容摘要
	CreatedAt      time.Time `gorm:"column:created_at;index;autoCreateTime;index:idx_user_activity_created;" json:"createdAt"`              //
}

func GetUserTimeline

func GetUserTimeline(userId uint64, lastId uint64, limit int) (entities []*Entity, err error)

GetUserTimeline 获取用户的动态时间轴(基于主键的分页)

func (*Entity) TableName

func (itself *Entity) TableName() string

Jump to

Keyboard shortcuts

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