add hubs create in http
This commit is contained in:
+47
-31
@@ -48,43 +48,51 @@ type UserProfileUpdateList struct {
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
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"`
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff []*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 NewConnection() *Connection {
|
||||
return &Connection{
|
||||
MessagesBuff: make([]*Message, config.MaxDirectMsgCache),
|
||||
}
|
||||
}
|
||||
|
||||
func (conn *Connection) AddMessageToBuff(message *Message) {
|
||||
conn.Mu.Lock()
|
||||
defer conn.Mu.Unlock()
|
||||
|
||||
conn.MessagesBuff[conn.NextBuffIdx%config.MaxDirectMsgCache] = message
|
||||
size := uint32(len(conn.MessagesBuff))
|
||||
conn.MessagesBuff[conn.NextBuffIdx%size] = message
|
||||
conn.NextBuffIdx++
|
||||
if conn.NextBuffIdx >= config.MaxDirectMsgCache {
|
||||
if conn.NextBuffIdx >= size {
|
||||
conn.HaveOverflowed = true
|
||||
}
|
||||
}
|
||||
|
||||
// GetSortedMessagesBuff returns arr, length
|
||||
func (conn *Connection) GetSortedMessagesBuff() (*[config.MaxDirectMsgCache]*Message, uint32) {
|
||||
// GetSortedMessagesBuff returns slice and its valid length.
|
||||
func (conn *Connection) GetSortedMessagesBuff() ([]*Message, uint32) {
|
||||
conn.Mu.RLock()
|
||||
defer conn.Mu.RUnlock()
|
||||
|
||||
size := uint32(len(conn.MessagesBuff))
|
||||
if !conn.HaveOverflowed {
|
||||
return &conn.MessagesBuff, conn.NextBuffIdx
|
||||
return conn.MessagesBuff, conn.NextBuffIdx
|
||||
}
|
||||
|
||||
sorted := new([config.MaxDirectMsgCache]*Message)
|
||||
for i := uint32(0); i < config.MaxDirectMsgCache; i++ {
|
||||
sorted[i] = conn.MessagesBuff[(conn.NextBuffIdx+i)%config.MaxDirectMsgCache]
|
||||
sorted := make([]*Message, size)
|
||||
for i := uint32(0); i < size; i++ {
|
||||
sorted[i] = conn.MessagesBuff[(conn.NextBuffIdx+i)%size]
|
||||
}
|
||||
return sorted, config.MaxDirectMsgCache
|
||||
return sorted, size
|
||||
}
|
||||
|
||||
type ConnectionStatusSetData struct {
|
||||
@@ -157,18 +165,26 @@ const (
|
||||
)
|
||||
|
||||
type Hub struct {
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func NewHub() *Hub {
|
||||
return &Hub{
|
||||
MessagesBuff: make([]*Message, config.MaxHubMsgCache),
|
||||
Users: make(map[uuid.UUID]*HubUser),
|
||||
Roles: make(map[uint8]*HubRole),
|
||||
}
|
||||
}
|
||||
|
||||
type HubChannelGroup struct {
|
||||
|
||||
Reference in New Issue
Block a user