63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
// Package entity holds group domain types. Persistence belongs in model.
|
|
package entity
|
|
|
|
const (
|
|
StatusActive Status = 1
|
|
StatusDissolved Status = 2
|
|
|
|
MaxNameLen = 32
|
|
MaxAnnouncementLen = 1024
|
|
MaxRemarkLen = 32
|
|
MaxMembers = 200
|
|
ListDefault = 20
|
|
ListMax = 100
|
|
MemberListMax = 200
|
|
MaxCollageFaces = 9
|
|
)
|
|
|
|
// Status is persisted as groups.status.
|
|
type Status int
|
|
|
|
func (s Status) Valid() bool {
|
|
return s == StatusActive || s == StatusDissolved
|
|
}
|
|
|
|
// Group is a type-2 chat. ID is the AUTO_INCREMENT 群号; ConversationID is Snowflake.
|
|
type Group struct {
|
|
ID int64
|
|
ConversationID int64
|
|
Name string
|
|
Avatar string
|
|
Announcement string
|
|
OwnerID int64
|
|
MutedAll bool
|
|
MemberCount int
|
|
Status Status
|
|
CreatedAtMS int64
|
|
UpdatedAtMS int64
|
|
}
|
|
|
|
func (g *Group) Active() bool {
|
|
return g != nil && g.Status == StatusActive
|
|
}
|
|
|
|
func ClampLimit(limit int) int {
|
|
if limit <= 0 {
|
|
return ListDefault
|
|
}
|
|
if limit > ListMax {
|
|
return ListMax
|
|
}
|
|
return limit
|
|
}
|
|
|
|
func ClampMemberLimit(limit int) int {
|
|
if limit <= 0 {
|
|
return MemberListMax
|
|
}
|
|
if limit > MemberListMax {
|
|
return MemberListMax
|
|
}
|
|
return limit
|
|
}
|