From c1b2fe0dfd468ba3c576b7330d3617604a33afff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 15 Apr 2012 21:37:20 +0200 Subject: [PATCH] Adding lastActivity --- file/lib/page/ChatMessagePage.class.php | 12 +++++++++- file/lib/page/ChatPage.class.php | 6 ++++- file/lib/util/ChatUtil.class.php | 31 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php index 1a9f210..58b6ad4 100644 --- a/file/lib/page/ChatMessagePage.class.php +++ b/file/lib/page/ChatMessagePage.class.php @@ -32,6 +32,9 @@ public function readData() { $this->users = $this->room->getUsers(); } + /** + * Fetches the new messages + */ public function readMessages() { $this->messages = chat\message\ChatMessageList::getMessagesSince($this->room, \wcf\util\ChatUtil::readUserData('lastSeen')); @@ -43,9 +46,16 @@ public function readMessages() { $stmt = WCF::getDB()->prepareStatement($sql); $stmt->execute(); $row = $stmt->fetchArray(); - \wcf\util\ChatUtil::writeUserData(array('lastSeen' => $row['messageID'])); + + \wcf\util\ChatUtil::writeUserData(array( + 'lastSeen' => $row['messageID'], + 'lastActivity' => TIME_NOW + )); } + /** + * Initializes the room databaseobject. + */ public function readRoom() { $this->roomID = \wcf\util\ChatUtil::readUserData('roomID'); diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index 632dbe5..f0d31f1 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -65,7 +65,11 @@ public function readData() { $this->readRoom(); $this->userData['color'] = \wcf\util\ChatUtil::readUserData('color'); - \wcf\util\ChatUtil::writeUserData(array('roomID' => $this->room->roomID, 'away' => null)); + \wcf\util\ChatUtil::writeUserData(array( + 'roomID' => $this->room->roomID, + 'away' => null, + 'lastActivity' => TIME_NOW + )); if (CHAT_DISPLAY_JOIN_LEAVE) { $messageAction = new chat\message\ChatMessageAction(array(), 'create', array( diff --git a/file/lib/util/ChatUtil.class.php b/file/lib/util/ChatUtil.class.php index 6017aa5..a5fc525 100644 --- a/file/lib/util/ChatUtil.class.php +++ b/file/lib/util/ChatUtil.class.php @@ -38,6 +38,37 @@ final class ChatUtil { */ private static $packageID = null; + /** + * Fetches the userIDs of died users. + * + * @return array + */ + public static function getDiedUsers() { + $packageID = \wcf\util\ChatUtil::getPackageID(); + $sql = "SELECT + r.userID, r.fieldValue AS roomID + FROM + wcf".WCF_N."_user_storage r + LEFT JOIN + wcf".WCF_N."_user_storage a + ON a.userID = r.userID + AND a.field = ? + AND a.packageID = ? + WHERE + r.field = ? + AND r.packageID = ? + AND a.fieldValue IS NOT NULL + AND ( + a.fieldValue < ? + OR a.fieldValue IS NULL + )"; + $stmt = WCF::getDB()->prepareStatement($sql); + $stmt->execute(array('lastActivity', $packageID, 'roomID', $packageID, TIME_NOW - 30)); + $users = array(); + while ($users[] = $stmt->fetchArray()); + + return $users; + } /** * Returns the packageID of Tims Chat. */