add configs from file, continue develpoment on hubs
This commit is contained in:
+36
-31
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"go-socket/packages/Enums/ConnectionState"
|
||||
"go-socket/packages/Enums/WsEventType"
|
||||
"go-socket/packages/globals"
|
||||
"go-socket/packages/config"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
"github.com/google/uuid"
|
||||
@@ -17,11 +17,11 @@ import (
|
||||
type Rgba [4]uint8
|
||||
type Sha256Hash [sha256.Size]byte
|
||||
|
||||
func (r Rgba) GetRandom() *Rgba {
|
||||
func (r Rgba) GetRandom() Rgba {
|
||||
for i := range r {
|
||||
r[i] = uint8(rand.IntN(256))
|
||||
}
|
||||
return &r
|
||||
return r
|
||||
}
|
||||
|
||||
type User struct {
|
||||
@@ -36,7 +36,7 @@ type User struct {
|
||||
WsConn *websocket.Conn `json:"-"`
|
||||
Id uuid.UUID `json:"-"`
|
||||
Connections map[uuid.UUID]*Connection `json:"-"`
|
||||
Color *Rgba `json:"color"`
|
||||
Color Rgba `json:"color"`
|
||||
}
|
||||
|
||||
type UserProfileUpdateList struct {
|
||||
@@ -48,31 +48,31 @@ type UserProfileUpdateList struct {
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff [globals.MaxDirectMsgCache]*Message `json:"-"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
RequestorId uuid.UUID `json:"requestorId"`
|
||||
RecipientId uuid.UUID `json:"recipientId"`
|
||||
UserWantingToElevate uuid.UUID `json:"userWantingToElevate"` // TODO add to database
|
||||
HaveOverflowed bool `json:"-"`
|
||||
State ConnectionState.ConnectionState `json:"state"`
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff [config.MaxDirectMsgCache]*Message `json:"-"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
RequestorId uuid.UUID `json:"requestorId"`
|
||||
RecipientId uuid.UUID `json:"recipientId"`
|
||||
UserWantingToElevate uuid.UUID `json:"userWantingToElevate"` // TODO add to database
|
||||
HaveOverflowed bool `json:"-"`
|
||||
State ConnectionState.ConnectionState `json:"state"`
|
||||
}
|
||||
|
||||
func (conn *Connection) AddMessageToBuff(message *Message) {
|
||||
conn.Mu.Lock()
|
||||
defer conn.Mu.Unlock()
|
||||
|
||||
conn.MessagesBuff[conn.NextBuffIdx%globals.MaxDirectMsgCache] = message
|
||||
conn.MessagesBuff[conn.NextBuffIdx%config.MaxDirectMsgCache] = message
|
||||
conn.NextBuffIdx++
|
||||
if conn.NextBuffIdx >= globals.MaxDirectMsgCache {
|
||||
if conn.NextBuffIdx >= config.MaxDirectMsgCache {
|
||||
conn.HaveOverflowed = true
|
||||
}
|
||||
}
|
||||
|
||||
// GetSortedMessagesBuff returns arr, length
|
||||
func (conn *Connection) GetSortedMessagesBuff() (*[globals.MaxDirectMsgCache]*Message, uint32) {
|
||||
func (conn *Connection) GetSortedMessagesBuff() (*[config.MaxDirectMsgCache]*Message, uint32) {
|
||||
conn.Mu.RLock()
|
||||
defer conn.Mu.RUnlock()
|
||||
|
||||
@@ -80,11 +80,11 @@ func (conn *Connection) GetSortedMessagesBuff() (*[globals.MaxDirectMsgCache]*Me
|
||||
return &conn.MessagesBuff, conn.NextBuffIdx
|
||||
}
|
||||
|
||||
sorted := new([globals.MaxDirectMsgCache]*Message)
|
||||
for i := uint32(0); i < globals.MaxDirectMsgCache; i++ {
|
||||
sorted[i] = conn.MessagesBuff[(conn.NextBuffIdx+i)%globals.MaxDirectMsgCache]
|
||||
sorted := new([config.MaxDirectMsgCache]*Message)
|
||||
for i := uint32(0); i < config.MaxDirectMsgCache; i++ {
|
||||
sorted[i] = conn.MessagesBuff[(conn.NextBuffIdx+i)%config.MaxDirectMsgCache]
|
||||
}
|
||||
return sorted, globals.MaxDirectMsgCache
|
||||
return sorted, config.MaxDirectMsgCache
|
||||
}
|
||||
|
||||
type ConnectionStatusSetData struct {
|
||||
@@ -138,6 +138,7 @@ const (
|
||||
PermissionChangeRoleName
|
||||
PermissionChangeRoleColor
|
||||
PermissionChangeRolePermissions
|
||||
PermissionOnlySelfRoleRemove
|
||||
|
||||
// Channel group permissions
|
||||
PermissionAddChannelGroup
|
||||
@@ -156,21 +157,24 @@ const (
|
||||
)
|
||||
|
||||
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"`
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff [config.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"`
|
||||
Name string `json:"name"`
|
||||
Color Rgba `json:"color"`
|
||||
AllowUserColor bool `json:"allowUserColor"`
|
||||
}
|
||||
|
||||
type HubChannelGroup struct {
|
||||
Id uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
Color Rgba `json:"color"`
|
||||
}
|
||||
|
||||
type HubChannel struct {
|
||||
@@ -190,6 +194,7 @@ type HubRole struct {
|
||||
Name string `json:"role"`
|
||||
Id uint8 `json:"id"`
|
||||
RolePermission RolePermission `json:"rolePermission"`
|
||||
Color Rgba `json:"color"`
|
||||
}
|
||||
|
||||
func (h HubRole) GrantPermission(r RolePermission) {
|
||||
|
||||
Reference in New Issue
Block a user