From 41e8379fb66c12d5468bda329560fd9c66c066cf Mon Sep 17 00:00:00 2001 From: Renard Date: Thu, 12 Mar 2020 01:22:29 -0300 Subject: printMessage() --- src/Chat.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Chat.js b/src/Chat.js index 701d0a2..6840415 100644 --- a/src/Chat.js +++ b/src/Chat.js @@ -47,13 +47,7 @@ class Chat extends Component { color = "grey", timestamp = "" ) { - let ts; - if (timestamp) { - ts = new Date(parseInt(timestamp)); - console.log(ts); - } else { - ts = new Date(); - } + const ts = timestamp ? new Date(parseInt(timestamp)) : new Date(); this.setState( prevState => ({ chat: [ @@ -77,6 +71,10 @@ class Chat extends Component { ); } + printMessage(message, color) { + this.addMessage(message, "", false, "", color); + } + componentWillMount() { this.client = new W3CWebSocket( "wss://radio.bienvenidoainternet.org/daemon/" @@ -89,7 +87,7 @@ class Chat extends Component { }; this.client.onerror = () => { this.setState({ isChatOnline: false }); - this.addMessage("Ha ocurrido un error conectándose al chat.", "red"); + this.printMessage("Ha ocurrido un error conectándose al chat.", "red"); }; } @@ -131,14 +129,14 @@ class Chat extends Component { ); break; case "WELCOME": - this.addMessage("Conectado al chat, " + args[1], "", false, "green"); + this.printMessage("Conectado al chat, " + args[1], "green"); this.client.send("HISTORY:10"); break; case "COUNT": this.setState({ chatUserCount: args[1] }); break; case "FLOOD": - this.addMessage( + this.printMessage( "Error: Estas enviando mensajes demasido rápido!", "red" ); -- cgit v1.2.1-18-gbd029