diff --git a/website/public/js/chat.js b/website/public/js/chat.js index 5566d15..014d723 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -1,6 +1,7 @@ var previousDate = new Date("1970-01-01 00:00:00"); +var previousTime = "00:00"; var gettingMessages = false; - +var previousType = "robot"; $(document).ready(function() { setInterval(loadMessages, 1000); @@ -39,34 +40,51 @@ function sendMessage() { } function addMessages(messages) { + var messagesText = ""; for(var i in messages) { - thisDate = new Date(messages[i].creationdate); + // Initialize message variables + var thisDate = new Date(messages[i].creationdate); + var thisTime = thisDate.getHours() + ":" + thisDate.getMinutes(); + var type; thisDate.setHours(0,0,0,0); + if (messages[i].destination == $(".destinationID").val()) { type = "chat-message-self"; } else { type = "chat-message-other"; } - if (thisDate > previousDate) { + if (i == 0) { + messagesText += '
'; + previousDate = thisDate; - $("#chat-history").append('\ - \ - '); + previousTime = thisTime; + previousType = type; + if (thisDate > previousDate) { + messagesText += '\ + '; + } + + messagesText += ''; + + $("#chat-history").append(messagesText); + + $("#chat-history").scrollTop($("#chat-history")[0].scrollHeight - $('#chat-history')[0].clientHeight); } function switchUser(userID) { @@ -80,5 +98,5 @@ function switchUser(userID) { } function sayEmpty() { - $("#chat-history").html("Begin nu met chatten!"); + $("#chat-history").html("Probeer ook eens foto's en video's te sturen"); } \ No newline at end of file diff --git a/website/public/styles/chat.css b/website/public/styles/chat.css index 75a4a6d..47b0639 100644 --- a/website/public/styles/chat.css +++ b/website/public/styles/chat.css @@ -134,4 +134,14 @@ body { .chat-message a { text-decoration: underline; +} + +.chat-time { + color: #666666; + font-size: 12px; + margin-bottom: -3px; +} + +.chat-message-other .chat-time { + text-align: right; } \ No newline at end of file