From a1cb794a5353300ccb21a8315cf3bd7c4669f857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Gustav=20R=C3=B8ksund?= Date: Mon, 20 Aug 2018 22:39:29 +0200 Subject: [PATCH] Removed dependencies and simplified the app - Removed gravatar user icons and used robohash instead - Removed crypto-js because it was only used for gravatar URL - Removed email as a consept (was only used for gravatar) - Removed Materialize.toast and replaced with alert (looks cool, but too many dependencies) - Removed jquery, was only used for Materialize.toast and filter out html from message - Removed emojione --- .gitmodules | 3 +++ src/main.go => main.go | 3 +-- public/app.js | 26 +++++++------------------- public/index.html | 11 +---------- vendor/github.com/gorilla/websocket | 1 + 5 files changed, 13 insertions(+), 31 deletions(-) create mode 100644 .gitmodules rename src/main.go => main.go (95%) create mode 160000 vendor/github.com/gorilla/websocket diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7501cdc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/github.com/gorilla/websocket"] + path = vendor/github.com/gorilla/websocket + url = git@github.com:gorilla/websocket.git diff --git a/src/main.go b/main.go similarity index 95% rename from src/main.go rename to main.go index 4477953..eb57491 100644 --- a/src/main.go +++ b/main.go @@ -19,14 +19,13 @@ var upgrader = websocket.Upgrader{ // Define our message object type Message struct { - Email string `json:"email"` Username string `json:"username"` Message string `json:"message"` } func main() { // Create a simple file server - fs := http.FileServer(http.Dir("../public")) + fs := http.FileServer(http.Dir("./public")) http.Handle("/", fs) // Configure websocket route diff --git a/public/app.js b/public/app.js index 45917fa..15672f3 100644 --- a/public/app.js +++ b/public/app.js @@ -5,7 +5,6 @@ new Vue({ ws: null, // Our websocket newMsg: '', // Holds new messages to be sent to the server chatContent: '', // A running list of chat messages displayed on the screen - email: null, // Email address used for grabbing an avatar username: null, // Our username joined: false // True if email and username have been filled in }, @@ -16,10 +15,9 @@ new Vue({ this.ws.addEventListener('message', function(e) { var msg = JSON.parse(e.data); self.chatContent += '
' - + '' // Avatar + + '' // Avatar + msg.username - + '
' - + emojione.toImage(msg.message) + '
'; // Parse emojis + + '' + msg.message + '
'; var element = document.getElementById('chat-messages'); element.scrollTop = element.scrollHeight; // Auto scroll to the bottom @@ -28,12 +26,11 @@ new Vue({ methods: { send: function () { - if (this.newMsg != '') { + if (this.newMsg) { this.ws.send( JSON.stringify({ - email: this.email, username: this.username, - message: $('

').html(this.newMsg).text() // Strip out html + message: this.newMsg.replace(/<(?:.|\n)*?>/gm, '') // Strip out html } )); this.newMsg = ''; // Reset newMsg @@ -41,21 +38,12 @@ new Vue({ }, join: function () { - if (!this.email) { - Materialize.toast('You must enter an email', 2000); - return - } if (!this.username) { - Materialize.toast('You must choose a username', 2000); + alert('You must choose a username', 2000); return } - this.email = $('

').html(this.email).text(); - this.username = $('

').html(this.username).text(); + this.username = this.username.replace(/<(?:.|\n)*?>/gm, ''); this.joined = true; - }, - - gravatarURL: function(email) { - return 'http://www.gravatar.com/avatar/' + CryptoJS.MD5(email); } } -}); \ No newline at end of file +}); diff --git a/public/index.html b/public/index.html index 0f0addf..81af8c4 100644 --- a/public/index.html +++ b/public/index.html @@ -5,8 +5,6 @@ Simple Chat - - @@ -39,9 +37,6 @@

-
- -
@@ -56,10 +51,6 @@
- - - - - \ No newline at end of file + diff --git a/vendor/github.com/gorilla/websocket b/vendor/github.com/gorilla/websocket new file mode 160000 index 0000000..3ff3320 --- /dev/null +++ b/vendor/github.com/gorilla/websocket @@ -0,0 +1 @@ +Subproject commit 3ff3320c2a1756a3691521efc290b4701575147c