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>
52 lines
944 B
Go
52 lines
944 B
Go
package entity
|
|
|
|
const (
|
|
RoleOwner = 1
|
|
RoleAdmin = 2
|
|
RoleMember = 3
|
|
)
|
|
|
|
// Member is a row in group_members. SpeakMuted is send-ban, not 免打扰.
|
|
type Member struct {
|
|
GroupID int64
|
|
UserID int64
|
|
Role int
|
|
Nickname string
|
|
SpeakMuted bool
|
|
JoinedAtMS int64
|
|
}
|
|
|
|
func ValidRole(role int) bool {
|
|
return role == RoleOwner || role == RoleAdmin || role == RoleMember
|
|
}
|
|
|
|
func (m *Member) CanManage() bool {
|
|
return m != nil && (m.Role == RoleOwner || m.Role == RoleAdmin)
|
|
}
|
|
|
|
func (m *Member) CanSpeak(mutedAll bool) bool {
|
|
if m == nil || m.SpeakMuted {
|
|
return false
|
|
}
|
|
if mutedAll && m.Role == RoleMember {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func UniqueUIDs(ids []int64) []int64 {
|
|
seen := make(map[int64]struct{}, len(ids))
|
|
out := make([]int64, 0, len(ids))
|
|
for _, id := range ids {
|
|
if id <= 0 {
|
|
continue
|
|
}
|
|
if _, ok := seen[id]; ok {
|
|
continue
|
|
}
|
|
seen[id] = struct{}{}
|
|
out = append(out, id)
|
|
}
|
|
return out
|
|
}
|