add per channel/group for user cahcing
This commit is contained in:
+53
-31
@@ -187,17 +187,37 @@ func PermissionAll() Permissions {
|
||||
return math.MaxUint32
|
||||
}
|
||||
|
||||
type BoundRoles [3]uint64
|
||||
type HubBoundRoles [3]uint64
|
||||
|
||||
const BoundRolesMax uint8 = 191
|
||||
const HubBoundRolesMax uint8 = 191
|
||||
|
||||
func (r *BoundRoles) Add(bit uint8) { r[bit>>6] |= 1 << (bit & 63) }
|
||||
func (r *BoundRoles) Remove(bit uint8) { r[bit>>6] &^= 1 << (bit & 63) }
|
||||
func (r *BoundRoles) Has(bit uint8) bool { return r[bit>>6]>>(bit&63)&1 == 1 }
|
||||
func (r *BoundRoles) HasSameId(against BoundRoles) bool {
|
||||
func (r *HubBoundRoles) Add(bit uint8) { r[bit>>6] |= 1 << (bit & 63) }
|
||||
func (r *HubBoundRoles) Remove(bit uint8) { r[bit>>6] &^= 1 << (bit & 63) }
|
||||
func (r *HubBoundRoles) Has(bit uint8) bool { return r[bit>>6]>>(bit&63)&1 == 1 }
|
||||
func (r *HubBoundRoles) HasSameId(against HubBoundRoles) bool {
|
||||
return against[0]&r[0] != 0 || against[1]&r[1] != 0 || against[2]&r[2] != 0
|
||||
}
|
||||
|
||||
type CachedUserPermissions uint8
|
||||
|
||||
const (
|
||||
CachedUserCanView CachedUserPermissions = 1 << iota
|
||||
CachedUserCanReadHistory
|
||||
CachedUserCanMessage
|
||||
)
|
||||
|
||||
func (p *CachedUserPermissions) SetCanView() { *p |= CachedUserCanView }
|
||||
func (p *CachedUserPermissions) ClearCanView() { *p &^= CachedUserCanView }
|
||||
func (p CachedUserPermissions) CanView() bool { return p&CachedUserCanView != 0 }
|
||||
|
||||
func (p *CachedUserPermissions) SetCanReadHistory() { *p |= CachedUserCanReadHistory }
|
||||
func (p *CachedUserPermissions) ClearCanReadHistory() { *p &^= CachedUserCanReadHistory }
|
||||
func (p CachedUserPermissions) CanReadHistory() bool { return p&CachedUserCanReadHistory != 0 }
|
||||
|
||||
func (p *CachedUserPermissions) SetCanMessage() { *p |= CachedUserCanMessage }
|
||||
func (p *CachedUserPermissions) ClearCanMessage() { *p &^= CachedUserCanMessage }
|
||||
func (p CachedUserPermissions) CanMessage() bool { return p&CachedUserCanMessage != 0 }
|
||||
|
||||
type Hub struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
@@ -242,12 +262,12 @@ func (h *HubRole) HasPermission(r Permissions) bool {
|
||||
}
|
||||
|
||||
type HubUser struct {
|
||||
Mu sync.RWMutex `json:"mu"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Roles BoundRoles `json:"-"`
|
||||
Name string `json:"name"` // Name empty = original name
|
||||
OriginalId uuid.UUID `json:"originalId"`
|
||||
IsMuted bool `json:"isMuted"`
|
||||
Mu sync.RWMutex `json:"mu"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Roles HubBoundRoles `json:"-"`
|
||||
Name string `json:"name"` // Name empty = original name
|
||||
OriginalId uuid.UUID `json:"originalId"`
|
||||
IsMuted bool `json:"isMuted"`
|
||||
}
|
||||
|
||||
func NewHubUser() *HubUser {
|
||||
@@ -255,11 +275,12 @@ func NewHubUser() *HubUser {
|
||||
}
|
||||
|
||||
type HubGroup struct {
|
||||
Name string `json:"name"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Color Rgba `json:"color"`
|
||||
RolesCanView BoundRoles `json:"rolesCanView"`
|
||||
Id uint8 `json:"id"` // Id 0 for unused
|
||||
Name string `json:"name"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Color Rgba `json:"color"`
|
||||
RolesCanView HubBoundRoles `json:"rolesCanView"`
|
||||
UsersCachedPermissions map[uuid.UUID]CachedUserPermissions `json:"-"`
|
||||
Id uint8 `json:"id"` // Id 0 for unused
|
||||
}
|
||||
|
||||
func NewHubGroup() *HubGroup {
|
||||
@@ -267,20 +288,21 @@ func NewHubGroup() *HubGroup {
|
||||
}
|
||||
|
||||
type HubChannel struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
MessagesBuff []*Message `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IconUrl string `json:"iconUrl"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
RolesCanView BoundRoles `json:"rolesCanView"`
|
||||
RolesCanMessage BoundRoles `json:"rolesCanMessage"`
|
||||
RolesCanReadHistory BoundRoles `json:"rolesCanReadHistory"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
ParentId uint8 `json:"parentId"`
|
||||
Position uint8 `json:"position"`
|
||||
HaveOverflowed bool `json:"-"`
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
MessagesBuff []*Message `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IconUrl string `json:"iconUrl"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
RolesCanView HubBoundRoles `json:"rolesCanView"`
|
||||
RolesCanMessage HubBoundRoles `json:"rolesCanMessage"`
|
||||
RolesCanReadHistory HubBoundRoles `json:"rolesCanReadHistory"`
|
||||
UsersCachedPermissions map[uuid.UUID]CachedUserPermissions `json:"-"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
ParentId uint8 `json:"parentId"`
|
||||
Position uint8 `json:"position"`
|
||||
HaveOverflowed bool `json:"-"`
|
||||
}
|
||||
|
||||
func NewHubChannel() *HubChannel {
|
||||
|
||||
Reference in New Issue
Block a user