diff --git a/core/chat/client.go b/core/chat/client.go index 91f8265f3..2ec56c723 100644 --- a/core/chat/client.go +++ b/core/chat/client.go @@ -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 diff --git a/core/chat/server.go b/core/chat/server.go index 40d395f95..366f4a1db 100644 --- a/core/chat/server.go +++ b/core/chat/server.go @@ -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 diff --git a/core/chatListener.go b/core/chatListener.go index 576d52427..e9328c932 100644 --- a/core/chatListener.go +++ b/core/chatListener.go @@ -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 diff --git a/go.mod b/go.mod index a58931127..3d526edeb 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/multiformats/go-multiaddr v0.2.2 github.com/radovskyb/watcher v1.0.7 github.com/sirupsen/logrus v1.6.0 + github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf github.com/yutopp/go-flv v0.2.0 github.com/yutopp/go-rtmp v0.0.0-20191212152852-4e41609a99bb golang.org/x/net v0.0.0-20200602114024-627f9648deb9 diff --git a/go.sum b/go.sum index c0f980afb..a5305f46c 100644 --- a/go.sum +++ b/go.sum @@ -920,6 +920,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= +github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA= +github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0= github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go.mod h1:XDKHRm5ThF8YJjx001LtgelzsoaEcvnA7lVWz9EeX3g= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c h1:u6SKchux2yDvFQnDHS3lPnIRmfVJ5Sxy3ao2SIdysLQ= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= diff --git a/models/chatMessage.go b/models/chatMessage.go index 3f2a4f1bd..4a442f311 100644 --- a/models/chatMessage.go +++ b/models/chatMessage.go @@ -11,12 +11,6 @@ type ChatMessage struct { MessageType string `json:"type"` } -//String converts the chat message to string -//TODO: is this required? or can we remove it -func (s ChatMessage) String() string { - return s.Author + " says " + s.Body -} - //Valid checks to ensure the message is valid func (s ChatMessage) Valid() bool { return s.Author != "" && s.Body != "" && s.ID != "" diff --git a/webroot/js/message.js b/webroot/js/message.js index e8f5d7a96..b8f37f1f7 100644 --- a/webroot/js/message.js +++ b/webroot/js/message.js @@ -207,7 +207,6 @@ class Messaging { var message = new Message({ body: content, author: this.username, - id: uuidv4(), }); const messageJSON = JSON.stringify(message); if (window && window.ws) { diff --git a/webroot/js/utils.js b/webroot/js/utils.js index 6ef317bf8..4cd966c5b 100644 --- a/webroot/js/utils.js +++ b/webroot/js/utils.js @@ -35,13 +35,6 @@ function jumpToBottom(element) { }, 50, element); } -function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -} - // convert newlines to
s function addNewlines(str) { return str.replace(/(?:\r\n|\r|\n)/g, '
');