spark-server/internal/module/friend/entity/request.go
DESKTOP-L8OUL9F\gfl0034 ce9c7a13aa feat: 互相关注后自动成为好友
一方关注只记关注。双方互关时写入已有双向好友边;取消关注若不再互关只删好友边,不删消息。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-18 21:51:18 +08:00

54 lines
1.2 KiB
Go

package entity
import "time"
const (
RequestPending RequestStatus = 1
RequestAccepted RequestStatus = 2
RequestRejected RequestStatus = 3
)
// RequestStatus is persisted as friend_requests.status and returned as apply `status`.
type RequestStatus int
func (s RequestStatus) Valid() bool {
return s == RequestPending || s == RequestAccepted || s == RequestRejected
}
const (
SourceUnknown Source = 0
SourceQRCode Source = 1
SourceEmail Source = 2
SourceSparkID Source = 3
SourceFollow Source = 4
)
// Source is friend add origin on the request and the directed edge.
type Source int
func (s Source) Valid() bool {
return s == SourceUnknown || s == SourceQRCode || s == SourceEmail || s == SourceSparkID || s == SourceFollow
}
const (
ReasonMax = 128
RemarkMax = 64
)
// Request is one from→to application. Repeats update this row; they do not insert another.
type Request struct {
ID int64
FromUser int64
ToUser int64
Source Source
Reason string
Remark string
Status RequestStatus
CreatedAt time.Time
UpdatedAt time.Time
}
func ValidSource(src int) bool {
return Source(src).Valid() && Source(src) != SourceUnknown
}