create types for hubs
This commit is contained in:
+77
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user