needed save users that can view channel instead of checking
This commit is contained in:
+23
-23
@@ -187,23 +187,22 @@ func PermissionAll() Permissions {
|
||||
return math.MaxUint32
|
||||
}
|
||||
|
||||
type BoundRoles uint64
|
||||
type BoundRoles [3]uint64
|
||||
|
||||
func (b *BoundRoles) Add(id uint8) {
|
||||
*b |= 1 << id
|
||||
}
|
||||
func (b *BoundRoles) Remove(id uint8) {
|
||||
*b &^= 1 << id
|
||||
}
|
||||
func (b *BoundRoles) Has(id uint8) bool {
|
||||
return *b&(1<<id) != 0
|
||||
const BoundRolesMax 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 {
|
||||
return against[0]&r[0] != 0 || against[1]&r[1] != 0 || against[2]&r[2] != 0
|
||||
}
|
||||
|
||||
type Hub struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Roles [256]*HubRole `json:"-"`
|
||||
Users [256]*HubUser `json:"-"`
|
||||
Users map[uuid.UUID]*HubUser `json:"-"`
|
||||
Groups [256]*HubGroup `json:"-"`
|
||||
Channels map[uuid.UUID]*HubChannel `json:"-"`
|
||||
Name string `json:"name"`
|
||||
@@ -218,6 +217,7 @@ type Hub struct {
|
||||
|
||||
func NewHub() *Hub {
|
||||
return &Hub{
|
||||
Users: make(map[uuid.UUID]*HubUser),
|
||||
Channels: make(map[uuid.UUID]*HubChannel),
|
||||
}
|
||||
}
|
||||
@@ -241,6 +241,19 @@ func (h *HubRole) HasPermission(r Permissions) bool {
|
||||
return h.Permissions&r != 0
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func NewHubUser() *HubUser {
|
||||
return &HubUser{}
|
||||
}
|
||||
|
||||
type HubGroup struct {
|
||||
Name string `json:"name"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
@@ -253,19 +266,6 @@ func NewHubGroup() *HubGroup {
|
||||
return &HubGroup{}
|
||||
}
|
||||
|
||||
type HubUser struct {
|
||||
Mu sync.RWMutex `json:"mu"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Roles BoundRoles `json:"-"`
|
||||
Name string `json:"name"`
|
||||
OriginalId uuid.UUID `json:"originalId"`
|
||||
IsMuted bool `json:"isMuted"`
|
||||
}
|
||||
|
||||
func NewHubUser() *HubUser {
|
||||
return &HubUser{}
|
||||
}
|
||||
|
||||
type HubChannel struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
MessagesBuff []*Message `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user