From 47bce1e4aa9d1254043abdff633b0ccfd725b0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 18 Oct 2014 19:30:03 +0200 Subject: [PATCH 1/9] Fix chat room pruning --- file/lib/data/room/RoomAction.class.php | 18 +++++++----------- file/lib/util/ChatUtil.class.php | 1 - 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index 267a1c4..8ba22aa 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -69,16 +69,12 @@ public function prune() { WHERE permanent = ? AND roomID NOT IN ( - SELECT - fieldValue AS roomID - FROM - wcf".WCF_N."_user_storage - WHERE - field = ? - AND fieldValue IS NOT NULL - )"; + SELECT chatRoomID + FROM wcf".WCF_N."_user + WHERE chatRoomID IS NOT NULL + )"; $stmt = \wcf\system\WCF::getDB()->prepareStatement($sql); - $stmt->execute(array(0, 'roomID')); + $stmt->execute(array(0)); $objectIDs = array(); while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID; @@ -251,7 +247,7 @@ public function join() { \wcf\system\user\activity\point\UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.join', $result, WCF::getUser()->userID); // send push message about join - \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join'); + \wcf\system\push\PushHandler::getInstance()->sendMessage('be.bastelstu.chat.join'); $messages = array(); foreach ($newestMessages as $message) $messages[] = $message->jsonify(true); @@ -318,7 +314,7 @@ public function leave() { 'chatRoomID' => null )); - \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.leave'); + \wcf\system\push\PushHandler::getInstance()->sendMessage('be.bastelstu.chat.leave'); } /** diff --git a/file/lib/util/ChatUtil.class.php b/file/lib/util/ChatUtil.class.php index b9c1f2f..06c50a5 100644 --- a/file/lib/util/ChatUtil.class.php +++ b/file/lib/util/ChatUtil.class.php @@ -1,7 +1,6 @@ Date: Sat, 18 Oct 2014 21:48:33 +0200 Subject: [PATCH 2/9] Fixup "Fix chat room pruning" --- file/lib/data/room/RoomAction.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index 8ba22aa..97f9861 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -247,7 +247,7 @@ public function join() { \wcf\system\user\activity\point\UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.join', $result, WCF::getUser()->userID); // send push message about join - \wcf\system\push\PushHandler::getInstance()->sendMessage('be.bastelstu.chat.join'); + \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join'); $messages = array(); foreach ($newestMessages as $message) $messages[] = $message->jsonify(true); @@ -314,7 +314,7 @@ public function leave() { 'chatRoomID' => null )); - \wcf\system\push\PushHandler::getInstance()->sendMessage('be.bastelstu.chat.leave'); + \wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.leave'); } /** From dad63c7967d9fd22d238542ccfc6783dee11da1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 18 Oct 2014 22:13:47 +0200 Subject: [PATCH 3/9] Bump version number --- package.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/package.xml b/package.xml index 33e39ec..248f7d8 100644 --- a/package.xml +++ b/package.xml @@ -6,8 +6,8 @@ 1 - 3.0.1 - 2014-08-14 + 3.0.2 + 2014-10-18 ]]> @@ -40,6 +40,12 @@ acp/be.bastelstu.chat.install.php + + language/*.xml + file.tar + acp/be.bastelstu.chat.update.php + + language/*.xml file.tar From 79196bade9923d36bc76888e1c4173b77bf8c0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 31 Oct 2014 02:01:32 +0100 Subject: [PATCH 4/9] Fix clock shift issue in MessageLogDownloadPage --- .../acp/page/MessageLogDownloadPage.class.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/file/lib/acp/page/MessageLogDownloadPage.class.php b/file/lib/acp/page/MessageLogDownloadPage.class.php index e96bd60..a8360c3 100644 --- a/file/lib/acp/page/MessageLogDownloadPage.class.php +++ b/file/lib/acp/page/MessageLogDownloadPage.class.php @@ -43,9 +43,9 @@ class MessageLogDownloadPage extends \wcf\page\AbstractPage { /** * given date * - * @var integer + * @var \DateTime */ - public $date = 0; + public $date = null; /** * active room @@ -69,11 +69,13 @@ class MessageLogDownloadPage extends \wcf\page\AbstractPage { public function readData() { parent::readData(); - if ($this->date > TIME_NOW) { + $now = new \DateTime('now', WCF::getUser()->getTimeZone()); + if ($this->date->getTimestamp() > $now->getTimestamp()) { throw new \wcf\system\exception\IllegalLinkException(); } - if (CHAT_LOG_ARCHIVETIME !== -1 && $this->date < strtotime('today 00:00:00 -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day')) { + $oldest = new \DateTime('today -'.ceil(CHAT_LOG_ARCHIVETIME / 1440).'day', WCF::getUser()->getTimeZone()); + if (CHAT_LOG_ARCHIVETIME !== -1 && $this->date->getTimestamp() < $oldest->getTimestamp()) { throw new \wcf\system\exception\IllegalLinkException(); } @@ -85,7 +87,7 @@ public function readData() { $file = new \wcf\system\io\File($this->tmpFile); $file->write(WCF::getLanguage()->get('chat.acp.log.title') . ': ' . (string) $this->room . "\n"); - for ($start = $this->date, $end = $start + 86399; $start < $end; $start += 1800) { + for ($start = $this->date->getTimestamp(), $end = $this->date->add(\DateInterval::createFromDateString('1day'))->sub(\DateInterval::createFromDateString('1second'))->getTimestamp(); $start < $end; $start += 1800) { $file->write(WCF::getTpl()->fetch('messageLogDownload', 'chat', array('messages' => \chat\data\message\MessageList::getMessagesBetween($this->room, $start, $start + 1799)))); } @@ -117,8 +119,12 @@ public function readParameters() { if (isset($_REQUEST['date'])) $date = $_REQUEST['date'].' 00:00:00'; else $date = 'today 00:00:00'; - $this->date = @strtotime($date); - if ($this->date === false) throw new \wcf\system\exception\IllegalLinkException(); + try { + $this->date = new \DateTime($date, WCF::getUser()->getTimeZone()); + } + catch (\Exception $e) { + throw new \wcf\system\exception\IllegalLinkException(); + } } /** @@ -127,9 +133,7 @@ public function readParameters() { public function show() { parent::show(); - $dateTime = \wcf\util\DateUtil::getDateTimeByTimestamp($this->date); - - $fileReader = new \wcf\util\FileReader($this->tmpFile, array('mimeType' => 'text/plain', 'filename' => str_replace(' ', '-', WCF::getLanguage()->get('chat.acp.log.title') . ' ' . $this->room.'-'.\wcf\util\DateUtil::format($dateTime, 'Y-m-d').'.txt'))); + $fileReader = new \wcf\util\FileReader($this->tmpFile, array('mimeType' => 'text/plain', 'filename' => str_replace(' ', '-', WCF::getLanguage()->get('chat.acp.log.title') . ' ' . $this->room.'-'.\wcf\util\DateUtil::format($this->date, 'Y-m-d').'.txt'))); $fileReader->send(); exit; From 80db5cf3c98423097f8c46a4053914576aba1fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 31 Oct 2014 02:19:33 +0100 Subject: [PATCH 5/9] Add date to message if they are from a previous day --- acptemplate/__messageLogTable.tpl | 2 +- acptemplate/messageLogDownload.tpl | 2 +- file/lib/data/message/Message.class.php | 4 +++- language/de.xml | 3 +++ language/en.xml | 3 +++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/acptemplate/__messageLogTable.tpl b/acptemplate/__messageLogTable.tpl index 157f124..821cbb6 100644 --- a/acptemplate/__messageLogTable.tpl +++ b/acptemplate/__messageLogTable.tpl @@ -13,7 +13,7 @@ {foreach from=$messages item="message"} {$message->messageID} - {$message->time|date:"H:i:s"} + {$message->time|date:"chat.global.timeFormat"}

{@$message->getUserProfile()->getAvatar()->getImageTag(24)}

{$message->username} {@$message->getFormattedMessage("text/simplified-html")} diff --git a/acptemplate/messageLogDownload.tpl b/acptemplate/messageLogDownload.tpl index cbfa157..dd12fcc 100644 --- a/acptemplate/messageLogDownload.tpl +++ b/acptemplate/messageLogDownload.tpl @@ -1,5 +1,5 @@ {foreach from=$messages item=$rawMessage}{* *}{assign var=message value=$rawMessage->jsonify(true)}{* - *}({$message['time']|date:'H:i:s'}) {$message[username]|str_pad:15:' ':STR_PAD_LEFT}{$message[separator]} {$message[message]} + *}({$message['time']|date:'chat.global.timeFormat'}) {$message[username]|str_pad:15:' ':STR_PAD_LEFT}{$message[separator]} {$message[message]} {/foreach} diff --git a/file/lib/data/message/Message.class.php b/file/lib/data/message/Message.class.php index f97f794..ccceb0c 100644 --- a/file/lib/data/message/Message.class.php +++ b/file/lib/data/message/Message.class.php @@ -153,10 +153,12 @@ public function jsonify($raw = false) { break; } + $time = \wcf\util\DateUtil::getDateTimeByTimestamp($this->time); + $startOfDay = new \DateTime('today', WCF::getUser()->getTimezone()); $array = array( 'formattedUsername' => $this->getUsername(true), 'formattedMessage' => $this->getFormattedMessage('text/html'), - 'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'), + 'formattedTime' => ($time->getTimestamp() < $startOfDay->getTimestamp() ? \wcf\util\DateUtil::format($time, 'chat.global.dateFormat').' ' : '').\wcf\util\DateUtil::format($time, 'chat.global.timeFormat'), 'separator' => $separator, 'message' => $this->getFormattedMessage('text/plain'), 'sender' => (int) $this->sender, diff --git a/language/de.xml b/language/de.xml index 7a23b6e..2b76555 100644 --- a/language/de.xml +++ b/language/de.xml @@ -193,6 +193,9 @@ Probieren Sie, den Chat neu zu laden