diff --git a/packages/globals/globals.go b/packages/globals/globals.go index a0e1d92..00d4279 100644 --- a/packages/globals/globals.go +++ b/packages/globals/globals.go @@ -3,7 +3,8 @@ package globals import "time" const ( - MaxDirectMsgCache uint32 = 12 + MaxDirectMsgCache uint32 = 32 + MaxHubMsgCache FileStorageBucketName string = "communicator" MaxPostBytes uint32 = 4 << 10 MaxPostWithFileBytes uint32 = 1 << 30 diff --git a/packages/types/types.go b/packages/types/types.go index ba4cb72..e19d2e1 100644 --- a/packages/types/types.go +++ b/packages/types/types.go @@ -87,7 +87,7 @@ func (conn *Connection) GetSortedMessagesBuff() (*[globals.MaxDirectMsgCache]*Me return sorted, globals.MaxDirectMsgCache } -type ConnectionStatusChangeData struct { +type ConnectionStatusSetData struct { Id uuid.UUID `json:"id"` NewState ConnectionState.ConnectionState `json:"newState"` } @@ -115,3 +115,79 @@ type WsAuthMessage struct { Success bool `json:"success"` Error string `json:"error"` } + +type RolePermission uint32 + +const ( + RoleSetHubName RolePermission = iota + RoleSetHubBg + RoleSetHubColor + RoleRemoveHub + RoleSetUserColorAllowed + + RoleAddUser + RoleRemoveUser + RoleRenameUser + RoleMuteUser + + RoleAddRole + RoleRemoveRole + + RoleAddChannelGroup + RoleRemoveChannelGroup + RoleSetChannelGroupName + RoleSetChannelGroupColor + RoleSetChannelGroupPermittedVisibleRoles + + RoleAddChannel + RoleRemoveChannel + RoleSetChannelName + RoleSetChannelPermittedVisibleRoles + RoleSetChannelPermittedSendMessageRoles + RoleSetChannelPermittedReadHistoryRoles +) + +type Hub struct { + Mu sync.RWMutex `json:"-"` + Id uuid.UUID `json:"id"` + CreatedAt time.Time `json:"createdAt"` + MessagesBuff [globals.MaxHubMsgCache]*Message `json:"-"` + NextBuffIdx uint32 `json:"-"` + HaveOverflowed bool `json:"-"` + Users map[uuid.UUID]*HubUser `json:"-"` + Roles map[uint8]*HubRole `json:"-"` + Creator uuid.UUID `json:"creator"` +} + +type HubUser struct { + Id uuid.UUID `json:"id"` + Username string `json:"username"` + Roles []uint8 `json:"roles"` + CreatedAt time.Time `json:"createdAt"` +} + +type HubRole struct { + Name string `json:"role"` + Id uint8 `json:"id"` + RolePermission RolePermission `json:"rolePermission"` +} + +func (h HubRole) GrantPermission(r RolePermission) { + h.RolePermission |= r +} +func (h HubRole) GrantPermissions(rs []RolePermission) { + for _, r := range rs { + h.RolePermission |= r + } +} +func (h HubRole) RevokePermission(r RolePermission) { + h.RolePermission &^= r +} +func (h HubRole) RevokePermissions(rs []RolePermission) { + for _, r := range rs { + h.RolePermission &^= r + } +} +func (h HubRole) HasPermission(r RolePermission) bool { + return h.RolePermission&r != 0 +}