Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1008 B
Go
61 lines
1008 B
Go
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
|
|
}
|