Use endpoint for chat history instead of websocket (#67)

* Change placeholder when chat is disabled

* Use the /chat endpoint for bulk chat history population instead of websocket. For #47

* Force LiveUI/seek bar during live to show. Closes #11.

* Change pulling chat history into app.js

* Force new messages to have visability = true
This commit is contained in:
Gabe Kangas
2020-07-18 17:27:04 -07:00
committed by GitHub
parent a266633a9a
commit 2855027f22
4 changed files with 28 additions and 13 deletions

View File

@@ -111,6 +111,7 @@ func (c *Client) listenRead() {
msg.ID = id msg.ID = id
msg.MessageType = "CHAT" msg.MessageType = "CHAT"
msg.Timestamp = time.Now() msg.Timestamp = time.Now()
msg.Visible = true
if err := websocket.JSON.Receive(c.ws, &msg); err == io.EOF { if err := websocket.JSON.Receive(c.ws, &msg); err == io.EOF {
c.doneCh <- true c.doneCh <- true

View File

@@ -56,12 +56,6 @@ func (s *server) err(err error) {
s.errCh <- err s.errCh <- err
} }
func (s *server) sendPastMessages(c *Client) {
for _, msg := range s.Messages {
c.Write(msg)
}
}
func (s *server) sendAll(msg models.ChatMessage) { func (s *server) sendAll(msg models.ChatMessage) {
for _, c := range s.Clients { for _, c := range s.Clients {
c.Write(msg) c.Write(msg)
@@ -104,7 +98,6 @@ func (s *server) Listen() {
s.Clients[c.id] = c s.Clients[c.id] = c
s.listener.ClientAdded(c.id) s.listener.ClientAdded(c.id)
s.sendPastMessages(c)
// remove a client // remove a client
case c := <-s.delCh: case c := <-s.delCh:

View File

@@ -86,6 +86,8 @@ class Owncast {
onError: this.handlePlayerError, onError: this.handlePlayerError,
}); });
this.player.init(); this.player.init();
this.getChatHistory();
}; };
setConfigData(data) { setConfigData(data) {
@@ -132,16 +134,20 @@ class Owncast {
return; return;
} }
const message = new Message(model); const message = new Message(model);
this.addMessage(message);
};
this.websocket = ws;
this.messagingInterface.setWebsocket(this.websocket);
};
addMessage(message) {
const existing = this.vueApp.messages.filter(function (item) { const existing = this.vueApp.messages.filter(function (item) {
return item.id === message.id; return item.id === message.id;
}) })
if (existing.length === 0 || !existing) { if (existing.length === 0 || !existing) {
this.vueApp.messages = [...this.vueApp.messages, message]; this.vueApp.messages = [...this.vueApp.messages, message];
} }
}; }
this.websocket = ws;
this.messagingInterface.setWebsocket(this.websocket);
};
// fetch /config data // fetch /config data
getConfig() { getConfig() {
@@ -276,4 +282,18 @@ class Owncast {
this.handleOfflineMode(); this.handleOfflineMode();
// stop timers? // stop timers?
}; };
async getChatHistory() {
const url = "/chat";
const response = await fetch(url);
const data = await response.json();
const messages = data.map(function (message) {
return new Message(message);
})
this.setChatHistory(messages);
}
setChatHistory(messages) {
this.vueApp.messages = messages;
}
}; };

View File

@@ -81,6 +81,7 @@ class MessagingInterface {
} else { } else {
this.tagAppContainer.classList.add('desktop'); this.tagAppContainer.classList.add('desktop');
} }
} }
setWebsocket(socket) { setWebsocket(socket) {