diff --git a/website/public/chat.php b/website/public/chat.php index f077a4d..09be336 100644 --- a/website/public/chat.php +++ b/website/public/chat.php @@ -5,6 +5,7 @@ + \ +
\ + ' + messages[i].content + '\ +
\ + \ + '); + } +} + +function switchUser(userID) { + $(".destinationID").val(userID); + $("#chat-history").html(""); + $("#lastID").val(""); +} \ No newline at end of file diff --git a/website/public/sendMessage.php b/website/public/sendMessage.php new file mode 100644 index 0000000..e555e2a --- /dev/null +++ b/website/public/sendMessage.php @@ -0,0 +1,16 @@ +query(" SELECT + `user`.`userID`, `user`.`username`, `user`.`profilepicture`, `user`.`onlinestatus`, diff --git a/website/queries/private_message.php b/website/queries/private_message.php new file mode 100644 index 0000000..2d953c5 --- /dev/null +++ b/website/queries/private_message.php @@ -0,0 +1,85 @@ +prepare(" + SELECT + * + FROM + `private_message` + WHERE + `origin` = :user1 AND + `destination` = :user2 OR + `origin` = :user2 AND + `destination` = :user1 + ORDER BY + `messageID` ASC + "); + + $stmt->bindParam(":user1", $user1ID); + $stmt->bindParam(":user2", $user2ID); + + $stmt->execute(); + + return json_encode($stmt->fetchAll()); +} + +function sendMessage($destination, $content) { + $db = $GLOBALS["db"]; + $stmt = $db->prepare(" + INSERT INTO + `private_message` + ( + `origin`, + `destination`, + `content` + ) + VALUES + ( + :origin, + :destination, + :content + ) + "); + + return $stmt->execute(array( + "origin" => $_SESSION["userID"], + "destination" => $destination, + "content" => $content + )); +} + +function getNewChatMessages($lastID, $destination) { + $db = $GLOBALS["db"]; + $origin = $_SESSION["userID"]; + + $stmt = $db->prepare(" + SELECT + * + FROM + `private_message` + WHERE + ( + `origin` = :user1 AND + `destination` = :user2 OR + `origin` = :user2 AND + `destination` = :user1) AND + `messageID` > :lastID + ORDER BY + `messageID` ASC + "); + + $stmt->bindParam(':user1', $origin); + $stmt->bindParam(':user2', $destination); + $stmt->bindParam(':lastID', $lastID); + + $stmt->execute(); + + return json_encode($stmt->fetchAll()); +} \ No newline at end of file diff --git a/website/views/chat-view.php b/website/views/chat-view.php index a23a1c5..a3acd4c 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -1,52 +1,83 @@
-