package entity import "time" const ( RelationNone = 0 RelationFriend = 1 RelationBlock = 2 ) const ( ListDefault = 20 ListMax = 100 ) // Relation is a bidirectional friendship. Natural key (user_small, user_big). type Relation struct { UserSmall int64 UserBig int64 CreatedAt time.Time } func NewRelation(a, b int64, at time.Time) *Relation { small, big := OrderUsers(a, b) return &Relation{UserSmall: small, UserBig: big, CreatedAt: at} } func (r *Relation) Other(me int64) int64 { if r == nil { return 0 } if r.UserSmall == me { return r.UserBig } if r.UserBig == me { return r.UserSmall } return 0 } func ClampLimit(limit int) int { if limit <= 0 { return ListDefault } if limit > ListMax { return ListMax } return limit } // ViewStatus is the viewer-centric relation: friend, blocked-by-me, or none. func ViewStatus(friend, blockedByMe bool) int { if blockedByMe { return RelationBlock } if friend { return RelationFriend } return RelationNone }