delete groups
This commit is contained in:
-43
@@ -19,7 +19,6 @@ type User struct {
|
||||
CreatedAt time.Time
|
||||
WsConn *websocket.Conn
|
||||
Id uuid.UUID
|
||||
Groups map[uuid.UUID]struct{}
|
||||
Connections map[uuid.UUID]*Connection
|
||||
Color [3]uint8
|
||||
}
|
||||
@@ -77,48 +76,6 @@ type Message struct {
|
||||
Receiver uuid.UUID `json:"receiver"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff [MaxGroupMsgCache]*Message `json:"-"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
Id uuid.UUID `json:"-"`
|
||||
CreatorId uuid.UUID `json:"creatorId"`
|
||||
OwnerId uuid.UUID `json:"ownerId"`
|
||||
Users map[uuid.UUID]struct{} `json:"-"`
|
||||
Color [3]uint8 `json:"color"`
|
||||
EnableUserColors bool `json:"enableUserColors"`
|
||||
HaveMessageBuffOverflowed bool `json:"-"`
|
||||
}
|
||||
|
||||
func (g *Group) AddMessageToBuff(message *Message) {
|
||||
g.Mu.Lock()
|
||||
defer g.Mu.Unlock()
|
||||
|
||||
g.MessagesBuff[g.NextBuffIdx%MaxGroupMsgCache] = message
|
||||
g.NextBuffIdx++
|
||||
if g.NextBuffIdx >= MaxGroupMsgCache {
|
||||
g.HaveMessageBuffOverflowed = true
|
||||
}
|
||||
}
|
||||
|
||||
// GetSortedMessagesBuff returns arr, length
|
||||
func (g *Group) GetSortedMessagesBuff() (*[MaxGroupMsgCache]*Message, uint32) {
|
||||
g.Mu.RLock()
|
||||
defer g.Mu.RUnlock()
|
||||
|
||||
if !g.HaveMessageBuffOverflowed {
|
||||
return &g.MessagesBuff, g.NextBuffIdx
|
||||
}
|
||||
|
||||
sorted := new([MaxGroupMsgCache]*Message)
|
||||
for i := uint32(0); i < MaxGroupMsgCache; i++ {
|
||||
sorted[i] = g.MessagesBuff[(g.NextBuffIdx+i)%MaxGroupMsgCache]
|
||||
}
|
||||
return sorted, MaxGroupMsgCache
|
||||
}
|
||||
|
||||
type LoginReturn struct {
|
||||
Token string `json:"token"`
|
||||
UserId uuid.UUID `json:"userId"`
|
||||
|
||||
Reference in New Issue
Block a user