add per channel/group for user cahcing
This commit is contained in:
@@ -53,7 +53,7 @@ func HandleHubCreate(response http.ResponseWriter, request *http.Request) {
|
|||||||
creator.Roles.Add(rootRole.Id)
|
creator.Roles.Add(rootRole.Id)
|
||||||
|
|
||||||
memberRole := &types.HubRole{
|
memberRole := &types.HubRole{
|
||||||
Id: types.BoundRolesMax,
|
Id: types.HubBoundRolesMax,
|
||||||
Name: "member",
|
Name: "member",
|
||||||
Color: types.Rgba{}.GetRandom(),
|
Color: types.Rgba{}.GetRandom(),
|
||||||
CreatedAt: hub.CreatedAt,
|
CreatedAt: hub.CreatedAt,
|
||||||
@@ -83,6 +83,7 @@ func HandleHubCreate(response http.ResponseWriter, request *http.Request) {
|
|||||||
channel.RolesCanView.Add(memberRole.Id)
|
channel.RolesCanView.Add(memberRole.Id)
|
||||||
channel.RolesCanReadHistory.Add(rootGroup.Id)
|
channel.RolesCanReadHistory.Add(rootGroup.Id)
|
||||||
channel.RolesCanReadHistory.Add(memberRole.Id)
|
channel.RolesCanReadHistory.Add(memberRole.Id)
|
||||||
|
channel.UsersCanView.Add()
|
||||||
hub.Channels[channel.Id] = channel
|
hub.Channels[channel.Id] = channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+53
-31
@@ -187,17 +187,37 @@ func PermissionAll() Permissions {
|
|||||||
return math.MaxUint32
|
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 *HubBoundRoles) Add(bit uint8) { r[bit>>6] |= 1 << (bit & 63) }
|
||||||
func (r *BoundRoles) Remove(bit uint8) { r[bit>>6] &^= 1 << (bit & 63) }
|
func (r *HubBoundRoles) 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 *HubBoundRoles) Has(bit uint8) bool { return r[bit>>6]>>(bit&63)&1 == 1 }
|
||||||
func (r *BoundRoles) HasSameId(against BoundRoles) bool {
|
func (r *HubBoundRoles) HasSameId(against HubBoundRoles) bool {
|
||||||
return against[0]&r[0] != 0 || against[1]&r[1] != 0 || against[2]&r[2] != 0
|
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 {
|
type Hub struct {
|
||||||
Mu sync.RWMutex `json:"-"`
|
Mu sync.RWMutex `json:"-"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
@@ -242,12 +262,12 @@ func (h *HubRole) HasPermission(r Permissions) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HubUser struct {
|
type HubUser struct {
|
||||||
Mu sync.RWMutex `json:"mu"`
|
Mu sync.RWMutex `json:"mu"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
Roles BoundRoles `json:"-"`
|
Roles HubBoundRoles `json:"-"`
|
||||||
Name string `json:"name"` // Name empty = original name
|
Name string `json:"name"` // Name empty = original name
|
||||||
OriginalId uuid.UUID `json:"originalId"`
|
OriginalId uuid.UUID `json:"originalId"`
|
||||||
IsMuted bool `json:"isMuted"`
|
IsMuted bool `json:"isMuted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHubUser() *HubUser {
|
func NewHubUser() *HubUser {
|
||||||
@@ -255,11 +275,12 @@ func NewHubUser() *HubUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HubGroup struct {
|
type HubGroup struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
Color Rgba `json:"color"`
|
Color Rgba `json:"color"`
|
||||||
RolesCanView BoundRoles `json:"rolesCanView"`
|
RolesCanView HubBoundRoles `json:"rolesCanView"`
|
||||||
Id uint8 `json:"id"` // Id 0 for unused
|
UsersCachedPermissions map[uuid.UUID]CachedUserPermissions `json:"-"`
|
||||||
|
Id uint8 `json:"id"` // Id 0 for unused
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHubGroup() *HubGroup {
|
func NewHubGroup() *HubGroup {
|
||||||
@@ -267,20 +288,21 @@ func NewHubGroup() *HubGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HubChannel struct {
|
type HubChannel struct {
|
||||||
Mu sync.RWMutex `json:"-"`
|
Mu sync.RWMutex `json:"-"`
|
||||||
MessagesBuff []*Message `json:"-"`
|
MessagesBuff []*Message `json:"-"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
IconUrl string `json:"iconUrl"`
|
IconUrl string `json:"iconUrl"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
RolesCanView BoundRoles `json:"rolesCanView"`
|
RolesCanView HubBoundRoles `json:"rolesCanView"`
|
||||||
RolesCanMessage BoundRoles `json:"rolesCanMessage"`
|
RolesCanMessage HubBoundRoles `json:"rolesCanMessage"`
|
||||||
RolesCanReadHistory BoundRoles `json:"rolesCanReadHistory"`
|
RolesCanReadHistory HubBoundRoles `json:"rolesCanReadHistory"`
|
||||||
NextBuffIdx uint32 `json:"-"`
|
UsersCachedPermissions map[uuid.UUID]CachedUserPermissions `json:"-"`
|
||||||
Id uuid.UUID `json:"id"`
|
NextBuffIdx uint32 `json:"-"`
|
||||||
ParentId uint8 `json:"parentId"`
|
Id uuid.UUID `json:"id"`
|
||||||
Position uint8 `json:"position"`
|
ParentId uint8 `json:"parentId"`
|
||||||
HaveOverflowed bool `json:"-"`
|
Position uint8 `json:"position"`
|
||||||
|
HaveOverflowed bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHubChannel() *HubChannel {
|
func NewHubChannel() *HubChannel {
|
||||||
|
|||||||
Reference in New Issue
Block a user