FINALLY FIXED THE UNREAD CHAT MESSAGES!
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
Reference in New Issue
Block a user