complete hub save endpoint

This commit is contained in:
2026-04-23 20:07:09 +02:00
parent c0d7e53884
commit 8aaa27a6dc
3 changed files with 151 additions and 90 deletions
+29 -24
View File
@@ -128,7 +128,7 @@ type RolePermission uint32
const (
// Hub permissions
PermissionSetHubName RolePermission = iota
PermissionSetHubName RolePermission = 1 << iota
PermissionSetHubBg
PermissionSetHubColor
PermissionRemoveHub
@@ -165,38 +165,43 @@ const (
)
type Hub struct {
Mu sync.RWMutex `json:"-"`
Id uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
MessagesBuff []*Message `json:"-"`
NextBuffIdx uint32 `json:"-"`
HaveOverflowed bool `json:"-"`
Users map[uuid.UUID]*HubUser `json:"-"`
Roles map[uint8]*HubRole `json:"-"`
Creator uuid.UUID `json:"creator"`
Name string `json:"name"`
Color Rgba `json:"color"`
AllowUserColor bool `json:"allowUserColor"`
Mu sync.RWMutex `json:"-"`
Id uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
MessagesBuff []*Message `json:"-"`
NextBuffIdx uint32 `json:"-"`
HaveOverflowed bool `json:"-"`
Users map[uuid.UUID]*HubUser `json:"-"`
Roles map[uint8]*HubRole `json:"-"`
ChannelGroups map[uuid.UUID]*HubChannelGroup `json:"-"`
Creator uuid.UUID `json:"creator"`
Name string `json:"name"`
Color Rgba `json:"color"`
AllowUserColor bool `json:"allowUserColor"`
}
func NewHub() *Hub {
return &Hub{
MessagesBuff: make([]*Message, config.MaxHubMsgCache),
Users: make(map[uuid.UUID]*HubUser),
Roles: make(map[uint8]*HubRole),
Id: uuid.New(),
MessagesBuff: make([]*Message, config.MaxHubMsgCache),
Users: make(map[uuid.UUID]*HubUser),
Roles: make(map[uint8]*HubRole),
ChannelGroups: make(map[uuid.UUID]*HubChannelGroup),
}
}
type HubChannelGroup struct {
Id uuid.UUID `json:"id"`
Name string `json:"name"`
Color Rgba `json:"color"`
Id uuid.UUID `json:"id"`
Name string `json:"name"`
Color Rgba `json:"color"`
Position uint8 `json:"position"`
}
type HubChannel struct {
Id uuid.UUID `json:"id"`
Name uuid.UUID `json:"name"`
ParentGroupId uuid.UUID `json:"parentGroupId"`
Position uint8 `json:"position"`
}
type HubUser struct {
@@ -213,22 +218,22 @@ type HubRole struct {
Color Rgba `json:"color"`
}
func (h HubRole) GrantPermission(r RolePermission) {
func (h *HubRole) GrantPermission(r RolePermission) {
h.RolePermission |= r
}
func (h HubRole) GrantPermissions(rs []RolePermission) {
func (h *HubRole) GrantPermissions(rs []RolePermission) {
for _, r := range rs {
h.RolePermission |= r
}
}
func (h HubRole) RevokePermission(r RolePermission) {
func (h *HubRole) RevokePermission(r RolePermission) {
h.RolePermission &^= r
}
func (h HubRole) RevokePermissions(rs []RolePermission) {
func (h *HubRole) RevokePermissions(rs []RolePermission) {
for _, r := range rs {
h.RolePermission &^= r
}
}
func (h HubRole) HasPermission(r RolePermission) bool {
func (h *HubRole) HasPermission(r RolePermission) bool {
return h.RolePermission&r != 0
}