rework ws responses to user, send events to user via ws

This commit is contained in:
2026-04-12 13:18:54 +02:00
parent 9076a5c5c8
commit 63b585313a
9 changed files with 149 additions and 103 deletions
+31 -14
View File
@@ -5,6 +5,7 @@ import (
"time"
"go-socket/Enums/ConnectionState"
"go-socket/Enums/WsEventType"
"github.com/coder/websocket"
"github.com/google/uuid"
@@ -24,15 +25,16 @@ type User struct {
}
type Connection struct {
Mu sync.RWMutex `json:"-"`
Id uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
MessagesBuff [MaxDirectMsgCache]*Message `json:"-"`
NextBuffIdx uint32 `json:"-"`
HaveOverflowed bool `json:"-"`
RequestorId uint32 `json:"requestorId"`
RecipientId uint32 `json:"recipientId"`
State ConnectionState.ConnectionState `json:"state"`
Mu sync.RWMutex `json:"-"`
Id uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
MessagesBuff [MaxDirectMsgCache]*Message `json:"-"`
NextBuffIdx uint32 `json:"-"`
RequestorId uint32 `json:"requestorId"`
RecipientId uint32 `json:"recipientId"`
UserWantingToElevate uint32 `json:"userWantingToElevate"` // TODO add to database
HaveOverflowed bool `json:"-"`
State ConnectionState.ConnectionState `json:"state"`
}
func (conn *Connection) AddMessageToBuff(message *Message) {
@@ -62,12 +64,17 @@ func (conn *Connection) GetSortedMessagesBuff() (*[MaxDirectMsgCache]*Message, u
return sorted, MaxDirectMsgCache
}
type ConnectionElevationData struct {
Id uuid.UUID `json:"id"`
NewState ConnectionState.ConnectionState `json:"newState"`
}
type Message struct {
Id uuid.UUID `json:"id"`
Content string `json:"content"`
CreatedAt time.Time `json:"createdAt"`
Sender uint32 `json:"sender"`
Receiver uuid.UUID `json:"receiver"`
Id uuid.UUID `json:"id"`
Content string `json:"content"`
CreatedAt time.Time `json:"createdAt"`
Sender uint32 `json:"sender"`
Receiver uuid.UUID `json:"receiver"`
}
type Group struct {
@@ -85,3 +92,13 @@ type LoginReturn struct {
Token string `json:"token"`
UserId uint32 `json:"userId"`
}
type WsEventMessage struct {
Type WsEventType.WsEventType `json:"type"`
Event any `json:"event"`
}
type WsAuthMessage struct {
Success bool `json:"success"`
Error string `json:"error"`
}