Make IDs for chat messages generated server-side, not client. For #26

This commit is contained in:
Gabe Kangas
2020-06-24 22:00:49 -07:00
parent 5dffaf215b
commit a297e33eff
8 changed files with 11 additions and 19 deletions

View File

@@ -10,6 +10,8 @@ import (
"github.com/gabek/owncast/models"
"github.com/gabek/owncast/utils"
"github.com/teris-io/shortid"
)
const channelBufSize = 100
@@ -102,6 +104,12 @@ func (c *Client) listenRead() {
// read data from websocket connection
default:
var msg models.ChatMessage
id, err := shortid.Generate()
if err != nil {
log.Panicln(err)
}
msg.ID = id
if err := websocket.JSON.Receive(c.ws, &msg); err == io.EOF {
c.doneCh <- true

View File

@@ -69,8 +69,6 @@ func (s *server) sendAll(msg models.ChatMessage) {
}
func (s *server) ping() {
// fmt.Println("Start pinging....", len(s.clients))
ping := models.PingMessage{MessageType: "PING"}
for _, c := range s.Clients {
c.pingch <- ping

View File

@@ -3,8 +3,6 @@ package core
import (
"errors"
log "github.com/sirupsen/logrus"
"github.com/gabek/owncast/core/chat"
"github.com/gabek/owncast/models"
)
@@ -24,7 +22,6 @@ func (cl ChatListenerImpl) ClientRemoved(clientID string) {
//MessageSent is for when a message is sent
func (cl ChatListenerImpl) MessageSent(message models.ChatMessage) {
log.Printf("Message sent to all: %s", message.String())
}
//SendMessageToChat sends a message to the chat server