From 95fd3c0040abd55e1e0e90b409d8d8283a931976 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Wed, 18 Jan 2017 15:09:52 +0100 Subject: [PATCH] chat is done? --- website/public/js/chat.js | 7 ++ website/public/styles/chat.css | 4 ++ website/queries/friendship.php | 1 + website/queries/private_message.php | 6 +- website/views/chat-view.php | 100 +++++++++++++++++++--------- 5 files changed, 84 insertions(+), 34 deletions(-) diff --git a/website/public/js/chat.js b/website/public/js/chat.js index 5b56586..dd0b00f 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -12,6 +12,7 @@ function loadMessages() { messages = JSON.parse(data); addMessages(messages); $("#lastID").val(messages[messages.length - 1].messageID); + $("#chat-history").scrollTop($("#chat-history")[0].scrollHeight); } }); @@ -47,4 +48,10 @@ function addMessages(messages) { \ '); } +} + +function switchUser(userID) { + $(".destinationID").val(userID); + $("#chat-history").html(""); + $("#lastID").val(""); } \ No newline at end of file diff --git a/website/public/styles/chat.css b/website/public/styles/chat.css index 8f486bb..132c750 100644 --- a/website/public/styles/chat.css +++ b/website/public/styles/chat.css @@ -16,6 +16,10 @@ overflow-y: auto; } +.chat-left .friend-item { + cursor: pointer; +} + .chat-right { width: calc(100% - 256px - 40px); height: calc(100% - 80px); diff --git a/website/queries/friendship.php b/website/queries/friendship.php index 56ce274..dc7a669 100644 --- a/website/queries/friendship.php +++ b/website/queries/friendship.php @@ -3,6 +3,7 @@ function selectAllFriends($db, $userID) { return $db->query(" SELECT + `user`.`userID`, `user`.`username`, `user`.`profilepicture`, `user`.`onlinestatus`, diff --git a/website/queries/private_message.php b/website/queries/private_message.php index 56c0c26..6cf8b16 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -6,7 +6,7 @@ session_start(); function getOldChatMessages($user2ID) { $db = $GLOBALS["db"]; - $user1ID = 2; + $user1ID = $_SESSION["userID"]; $stmt = $db->prepare(" SELECT @@ -49,7 +49,7 @@ function sendMessage($destination, $content) { "); return $stmt->execute(array( - "origin" => 2, + "origin" => $_SESSION["userID"], "destination" => $destination, "content" => $content )); @@ -57,7 +57,7 @@ function sendMessage($destination, $content) { function getNewChatMessages($lastID, $destination) { $db = $GLOBALS["db"]; - $origin = 2; + $origin = $_SESSION["userID"]; $stmt = $db->prepare(" SELECT diff --git a/website/views/chat-view.php b/website/views/chat-view.php index dabd348..1f9a0d8 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -1,40 +1,76 @@
-