diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index c1ff418..8350c59 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -210,6 +210,20 @@ public function leave() { \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join'); } + /** + * Forces dead users to leave the chat. + */ + public function removeDeadUsers() { + $deadUsers = Room::getDeadUsers(); + + foreach ($deadUsers as $deadUser) { + $roomAction = new self(array(), 'leave', array( + 'user' => $deadUser + )); + $roomAction->executeAction(); + } + } + /** * Validates permissions. */ diff --git a/file/lib/page/NewMessagesPage.class.php b/file/lib/page/NewMessagesPage.class.php index e59a78b..34ffde5 100644 --- a/file/lib/page/NewMessagesPage.class.php +++ b/file/lib/page/NewMessagesPage.class.php @@ -65,13 +65,8 @@ public function readData() { $this->readMessages(); $this->users = $this->room->getUsers(); - $deadUsers = data\room\Room::getDeadUsers(); - foreach ($deadUsers as $deadUser) { - $roomAction = new data\room\RoomAction(array(), 'leave', array( - 'user' => $deadUser - )); - $roomAction->executeAction(); - } + $roomAction = new data\room\RoomAction(array(), 'removeDeadUsers'); + $roomAction->executeAction(); } /** diff --git a/file/lib/system/cronjob/CleanupCronjob.class.php b/file/lib/system/cronjob/CleanupCronjob.class.php index 460399b..47e6a03 100644 --- a/file/lib/system/cronjob/CleanupCronjob.class.php +++ b/file/lib/system/cronjob/CleanupCronjob.class.php @@ -24,29 +24,7 @@ public function execute(\wcf\data\cronjob\Cronjob $cronjob) { $suspensionAction->executeAction(); // kill dead users - $deadUsers = \chat\util\ChatUtil::getDiedUsers(); - foreach ($deadUsers as $deadUser) { - if (!$deadUser) continue; - - $user = new \wcf\data\user\User($deadUser['userID']); - if (CHAT_DISPLAY_JOIN_LEAVE) { - $userData['color'] = \chat\util\ChatUtil::readUserData('color', $user); - - $messageAction = new data\message\MessageAction(array(), 'create', array( - 'data' => array( - 'roomID' => $deadUser['roomID'], - 'sender' => $user->userID, - 'username' => $user->username, - 'time' => TIME_NOW, - 'type' => data\message\Message::TYPE_LEAVE, - 'message' => '', - 'color1' => $userData['color'][1], - 'color2' => $userData['color'][2] - ) - )); - $messageAction->executeAction(); - } - \chat\util\ChatUtil::writeUserData(array('roomID' => null), $user); - } + $roomAction = new data\room\RoomAction(array(), 'removeDeadUsers'); + $roomAction->executeAction(); } }