diff --git a/website/public/API/loadChatNotifications.php b/website/public/API/loadChatNotifications.php
index 3b5835f..1415a2e 100644
--- a/website/public/API/loadChatNotifications.php
+++ b/website/public/API/loadChatNotifications.php
@@ -3,6 +3,6 @@
session_start();
require_once ("../../queries/connect.php");
-require_once ("../../queries/friendship.php");
+require_once ("../../queries/private_message.php");
echo selectAllUnreadChat();
\ No newline at end of file
diff --git a/website/public/API/loadMessages.php b/website/public/API/loadMessages.php
index e30acc8..a02de26 100644
--- a/website/public/API/loadMessages.php
+++ b/website/public/API/loadMessages.php
@@ -5,9 +5,11 @@ session_start();
require_once("../../queries/connect.php");
require_once("../../queries/private_message.php");
require_once("../../queries/checkInput.php");
+require_once("../../queries/friendship.php");
if (isset($_POST["lastID"]) && $_POST["lastID"] != "") {
echo getNewChatMessages(test_input($_POST["lastID"]), test_input($_POST["destination"]));
} else {
echo getOldChatMessages(test_input($_POST["destination"]));
+ setLastVisited(test_input($_POST["destination"]));
}
\ No newline at end of file
diff --git a/website/public/js/chat.js b/website/public/js/chat.js
index 6c420a1..3c839e4 100644
--- a/website/public/js/chat.js
+++ b/website/public/js/chat.js
@@ -53,8 +53,8 @@ function switchUser(userID) {
$(".destinationID").val(userID);
$("#chat-history").html("");
$("#lastID").val("");
- $(".chat-left .friend-item").removeClass("active-friend-chat");
- $(".chat-left #friend-item-" + userID).addClass("active-friend-chat");
+ $("#chat-recent-panel .friend-item").removeClass("active-friend-chat");
+ $("#chat-left #friend-item-" + userID).addClass("active-friend-chat");
}
function sayEmpty() {
diff --git a/website/public/js/notifications.js b/website/public/js/notifications.js
index 51a8c06..e3476b2 100644
--- a/website/public/js/notifications.js
+++ b/website/public/js/notifications.js
@@ -1,7 +1,7 @@
-function showNotifications(notifications, id) {
- $("#" + id).html("");
+function showFriendNotifications(notifications) {
+ $("#friendrequestslist").html("");
for (i in notifications) {
- $("#" + id).append(" \
+ $("#friendrequestslist").append(" \
\
+ ");
+ }
+}
+
function loadNotifications() {
$.post(
"API/loadFriendRequestNotifications.php"
).done(function(data) {
if (data && data != "[]") {
- showNotifications(JSON.parse(data), "friendrequestslist");
+ showFriendNotifications(JSON.parse(data));
}
});
$.post(
"API/loadChatNotifications.php"
).done(function(data) {
if (data && data != "[]") {
- showNotifications(JSON.parse(data), "unreadChatlist");
+ showChatNotifications(JSON.parse(data));
}
});
diff --git a/website/public/styles/chat.css b/website/public/styles/chat.css
index 16505f5..6822d21 100644
--- a/website/public/styles/chat.css
+++ b/website/public/styles/chat.css
@@ -1,34 +1,38 @@
/* Overall chat-screen */
.chat {
position: fixed;
+
top: 80px;
left: 256px;
- padding: 20px 0;
width: calc(100% - 256px);
height: calc(100% - 120px);
- display: inline-flex;
+
+ padding: 20px 0;
+
+ display: inline-block;
}
-.chat-left {
+#chat-recent-panel {
width: 256px;
height: calc(100% - 100px);
- margin: 0 10px;
- overflow-y: auto;
-}
-.chat-right {
- width: calc(100% - 256px - 40px);
- height: calc(100% - 80px);
- margin-right: 10px;
+ display: inline-block;
+
+ overflow-y: auto;
}
/* Chat history. */
-.chat-history {
+#chat-history {
overflow-y: auto;
overflow-x: hidden;
- height: 100%;
+
+ width: calc(100% - 256px - 75px);
+ height: calc(100% - 80px);
+
padding: 10px;
+ display: inline-block;
+
word-wrap: break-word;
}
@@ -36,7 +40,13 @@
.chat-message {
width: 100%;
min-height: 40px;
- padding-top: 10px;
+ padding: 10px 0;
+ clear: both;
+}
+
+.chat-message::after {
+ content: '';
+ display: table;
clear: both;
}
@@ -63,7 +73,7 @@
/* Chat reply field */
.chat-field {
- width: 100%;
+ width: calc(100% - 10px);
display: table;
}
diff --git a/website/public/styles/main.css b/website/public/styles/main.css
index 3e9b51d..8c50b19 100644
--- a/website/public/styles/main.css
+++ b/website/public/styles/main.css
@@ -242,3 +242,23 @@ div[data-title]:hover:after {
line-height: normal;
font-family: Arial, sans-serif;
}
+
+.friend {
+
+}
+
+
+.friend-item, .group-item {
+ cursor: pointer;
+ transition-duration: 250ms;
+}
+
+.friend-item:hover, .group-item:hover {
+ background: #FBC02D;
+ box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
+}
+
+.friend-name {
+ display: inline-block;
+ vertical-align: middle;
+}
diff --git a/website/public/styles/menu.css b/website/public/styles/menu.css
index 25e4b91..ce294da 100644
--- a/website/public/styles/menu.css
+++ b/website/public/styles/menu.css
@@ -34,16 +34,6 @@
cursor: pointer;
}
-.friend-item, .group-item {
- cursor: pointer;
- transition-duration: 250ms;
-}
-
-.friend-item:hover, .group-item:hover {
- background: #FBC02D;
- box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
-}
-
.menu button {
background: none;
color: inherit;
diff --git a/website/queries/friendship.php b/website/queries/friendship.php
index aea1161..dc1ce46 100644
--- a/website/queries/friendship.php
+++ b/website/queries/friendship.php
@@ -5,6 +5,7 @@ function selectAllFriends($userID) {
SELECT
`userID`,
`username`,
+ LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`,
IFNULL(
`profilepicture`,
'../img/avatar-standard.png'
@@ -36,6 +37,7 @@ function selectAllFriendRequests() {
SELECT
`userID`,
`username`,
+ LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`,
IFNULL(
`profilepicture`,
'../img/avatar-standard.png'
@@ -60,4 +62,35 @@ function selectAllFriendRequests() {
$stmt->execute();
return json_encode($stmt->fetchAll());
+}
+
+
+function setLastVisited($friend) {
+ $stmt = $GLOBALS["db"]->prepare("
+ UPDATE
+ `friendship`
+ SET `friendship`.chatLastVisted1=(
+ CASE `user1ID` = :sessionUser
+ WHEN TRUE THEN NOW()
+ WHEN FALSE THEN `chatLastVisted1`
+ END
+ ),
+ `friendship`.`chatLastVisted2`=(
+ CASE `user2ID` = :sessionUser
+ WHEN TRUE THEN NOW()
+ WHEN FALSE THEN `chatLastVisted2`
+ END
+ )
+ WHERE
+ `user1ID` = :sessionUser AND
+ `user2ID` = :friend OR
+ `user2ID` = :sessionUser AND
+ `user1ID` = :friend;
+ ");
+
+ $stmt->bindParam(':sessionUser', $_SESSION["userID"], PDO::PARAM_INT);
+ $stmt->bindParam(':friend', $friend, PDO::PARAM_INT);
+ $stmt->execute();
+
+ return $stmt;
}
\ No newline at end of file
diff --git a/website/queries/private_message.php b/website/queries/private_message.php
index 46c21a3..2bb89ab 100644
--- a/website/queries/private_message.php
+++ b/website/queries/private_message.php
@@ -74,3 +74,38 @@ function getNewChatMessages($lastID, $destination) {
return json_encode($stmt->fetchAll());
}
+
+
+function selectAllUnreadChat() {
+ $stmt = $GLOBALS["db"]->prepare("
+ SELECT
+ LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`,
+ IFNULL(
+ `profilepicture`,
+ '../img/notbad.jpg'
+ ) AS profilepicture,
+ LEFT(`private_message`.`content`, 20) as `content`
+ FROM
+ `private_message`,
+ `friendship`,
+ `user`
+ WHERE
+ (`friendship`.user2ID = `private_message`.`origin` AND
+ `friendship`.user1ID = `private_message`.`destination` AND
+ `friendship`.chatLastVisted1 < `private_message`.`creationdate` OR
+ `friendship`.user1ID = `private_message`.`origin` AND
+ `friendship`.user2ID = `private_message`.`destination` AND
+ `friendship`.chatLastVisted2 < `private_message`.`creationdate`) AND
+ `private_message`.`origin` = `user`.`userID` AND
+ `private_message`.`destination` = :userID AND
+ `user`.`role` != 'banned'
+
+ GROUP BY `user`.`userID`
+ ");
+
+ $stmt->bindParam(':userID', $_SESSION["userID"]);
+
+ $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 ced8e4f..9b40f71 100644
--- a/website/views/chat-view.php
+++ b/website/views/chat-view.php
@@ -1,6 +1,6 @@
-