FINALLY FIXED THE UNREAD CHAT MESSAGES!

This commit is contained in:
Lars van Hijfte
2017-01-24 14:26:15 +01:00
parent c4e4508b53
commit a88483ae47
12 changed files with 167 additions and 39 deletions

View File

@@ -5,6 +5,7 @@ function selectAllFriends($userID) {
SELECT
`userID`,
`username`,
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`,
IFNULL(
`profilepicture`,
'../img/notbad.jpg'
@@ -36,6 +37,7 @@ function selectAllFriendRequests() {
SELECT
`userID`,
`username`,
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 20) as `name`,
IFNULL(
`profilepicture`,
'../img/notbad.jpg'
@@ -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;
}