From 4c109a9bb8c9a158b3d2f18f3216ce95d52e2ae8 Mon Sep 17 00:00:00 2001 From: Renard Date: Thu, 12 Mar 2020 01:08:32 -0300 Subject: Implementación de historial de chat --- src/Chat.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/Chat.js') diff --git a/src/Chat.js b/src/Chat.js index 4117183..701d0a2 100644 --- a/src/Chat.js +++ b/src/Chat.js @@ -39,8 +39,21 @@ class Chat extends Component { return msg ? msg.replace(/%3A/g, ":") : ""; } - addMessage(message, stream, own = false, sender = "", color = "grey") { - var ts = new Date(); + addMessage( + message, + stream, + own = false, + sender = "", + color = "grey", + timestamp = "" + ) { + let ts; + if (timestamp) { + ts = new Date(parseInt(timestamp)); + console.log(ts); + } else { + ts = new Date(); + } this.setState( prevState => ({ chat: [ @@ -98,6 +111,17 @@ class Chat extends Component { case "MSG": this.addMessage(this.translateColon(args[2]), args[1]); break; + case "HMSG": + console.log(line); + this.addMessage( + this.translateColon(args[3]), + args[2], + false, + "", + "grey", + args[1] + ); + break; case "FMSG": this.addMessage( this.translateColon(args[3]), @@ -108,6 +132,7 @@ class Chat extends Component { break; case "WELCOME": this.addMessage("Conectado al chat, " + args[1], "", false, "green"); + this.client.send("HISTORY:10"); break; case "COUNT": this.setState({ chatUserCount: args[1] }); @@ -118,6 +143,11 @@ class Chat extends Component { "red" ); break; + case "HISTORY_OK": + /* Renard: z411: que hago con el HISTORY_OK? + Renard: me lo meto en la raja? + z411: bien adentro */ + break; default: console.error("[Chat] Unsupported command " + args[0]); break; -- cgit v1.2.1-18-gbd029