diff --git a/file/js/be.bastelstu.WCF.Chat.Log.coffee b/file/js/be.bastelstu.WCF.Chat.Log.coffee new file mode 100644 index 0000000..d168b04 --- /dev/null +++ b/file/js/be.bastelstu.WCF.Chat.Log.coffee @@ -0,0 +1,110 @@ +### +# be.bastelstu.WCF.Chat.Log +# +# @author Tim Düsterhus +# @copyright 2010-2012 Tim Düsterhus +# @license Creative Commons Attribution-NonCommercial-ShareAlike +# @package be.bastelstu.wcf.chat +### + +(($, window, _console) -> + be.bastelstu.WCF.Chat.Log = $.extend true, { }, be.bastelstu.WCF.Chat, + init: () -> + console.log 'Initializing' + @bindEvents() + console.log 'Finished initializing - Shields at 104 percent' + ### + # Binds all the events needed for Tims Chat. + ### + bindEvents: () -> + # Switch sidebar tab + $('.timsChatSidebarTabs li').click $.proxy (event) -> + event.preventDefault() + @toggleSidebarContents $ event.target + , @ + + # Refreshes the roomlist + $('#timsChatRoomList button').click $.proxy(@refreshRoomList, @) + + # Toggle Buttons + $('.timsChatToggle').click (event) -> + element = $ @ + icon = element.find 'img' + if element.data('status') is 1 + element.data 'status', 0 + icon.attr 'src', icon.attr('src').replace /enabled(Inverse)?.([a-z]{3})$/, 'disabled$1.$2' + element.attr 'title', element.data 'enableMessage' + else + element.data 'status', 1 + icon.attr 'src', icon.attr('src').replace /disabled(Inverse)?.([a-z]{3})$/, 'enabled$1.$2' + element.attr 'title', element.data 'disableMessage' + + $('#timsChatInput').focus() + + # Enable fullscreen-mode + $('#timsChatFullscreen').click (event) -> + if $(@).data 'status' + $('html').addClass 'fullscreen' + else + $('html').removeClass 'fullscreen' + ### + # Inserts the new messages. + # + # @param array messages + ### + handleMessages: (messages) -> + # Insert the messages + for message in messages + continue if $.wcfIsset 'timsChatMessage' + message.messageID # Prevent problems with race condition + + output = @messageTemplate.fetch message + li = $ '
  • ' + li.attr 'id', 'timsChatMessage'+message.messageID + li.addClass 'timsChatMessage timsChatMessage'+message.type + li.append output + + li.appendTo $ '.timsChatMessageContainer > ul' + ### + # Refreshes the room-list. + ### + refreshRoomList: () -> + console.log 'Refreshing the roomlist' + $('#toggleRooms a').addClass 'ajaxLoad' + + $.ajax $('#toggleRooms a').data('refreshUrl'), + dataType: 'json' + type: 'POST' + success: $.proxy((data, textStatus, jqXHR) -> + $('#timsChatRoomList li').remove() + $('#toggleRooms a').removeClass 'ajaxLoad' + $('#toggleRooms .badge').text data.length + + for room in data + li = $ '
  • ' + li.addClass 'activeMenuItem' if room.active + $('' + room.title + '').addClass('timsChatRoom').appendTo li + $('#timsChatRoomList ul').append li + + console.log 'Found ' + data.length + ' rooms' + , @) + ### + # Toggles between user- and room-list. + # + # @param jQuery-object target + ### + toggleSidebarContents: (target) -> + return if target.parents('li').hasClass 'active' + + if target.parents('li').attr('id') is 'toggleUsers' + $('#toggleUsers').addClass 'active' + $('#toggleRooms').removeClass 'active' + + $('#timsChatRoomList').hide() + $('#timsChatUserList').show() + else if target.parents('li').attr('id') is 'toggleRooms' + $('#toggleRooms').addClass 'active' + $('#toggleUsers').removeClass 'active' + + $('#timsChatUserList').hide() + $('#timsChatRoomList').show() +)(jQuery, @, console) diff --git a/file/lib/page/ChatLogPage.class.php b/file/lib/page/ChatLogPage.class.php new file mode 100644 index 0000000..90fed7f --- /dev/null +++ b/file/lib/page/ChatLogPage.class.php @@ -0,0 +1,117 @@ + + * @package be.bastelstu.wcf.chat + * @subpackage page + */ +class ChatLogPage extends AbstractPage { + /** + * @see wcf\page\AbstractPage::$loginRequired + */ + public $loginRequired = true; + + /** + * TODO: comment this + * + * @var array<\wcf\data\chat\message\ChatMessage> + */ + public $messages = array(); + + /** + * @see \wcf\page\AbstractPage::$neededModules + */ + public $neededModules = array('CHAT_ACTIVE'); + + /** + * @see \wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array(); + + /** + * given roomID + * @var integer + */ + public $roomID = 0; + + /** + * given room + * @var \wcf\data\chat\room\ChatRoom + */ + public $room = null; + + /** + * all rooms in the current installation + * @var array<\wcf\data\chat\room\ChatRoom> + */ + public $rooms = array(); + + /** + * shortcut for the active request + * @see wcf\system\request\Request::getRequestObject() + */ + public $request = null; + + /** + * Disallows direct access. + * + * @see wcf\page\IPage::__run() + */ + public function __run() { + if (($this->request = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()) === $this) throw new IllegalLinkException(); + + parent::__run(); + } + + /** + * @see \wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'messages' => $this->messages, + 'room' => $this->room, + 'roomID' => $this->roomID, + 'rooms' => $this->rooms, + 'sidebarCollapsed' => \wcf\system\user\collapsible\content\UserCollapsibleContentHandler::getInstance()->isCollapsed('com.woltlab.wcf.collapsibleSidebar', 'be.bastelstu.wcf.chat.ChatLogPage'), + 'sidebarName' => 'be.bastelstu.wcf.chat.ChatLogPage' + )); + } + + /** + * @see \wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id']; + } + + /** + * @see \wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + $cache = chat\room\ChatRoom::getCache(); + if (!isset($cache[$this->roomID])) throw new IllegalLinkException(); + + $this->room = $cache[$this->roomID]; + if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); + $ph = new \wcf\system\chat\permission\ChatPermissionHandler(); + if (!$ph->getPermission($this->room, 'mod.canReadLog')) throw new \wcf\system\exception\PermissionDeniedException(); + + // TODO: actually read the correct messages + $this->messages = chat\message\ChatMessageList::getNewestMessages($this->room, 150); + } +} diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index 0136a40..f1b3a29 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -192,6 +192,8 @@ public function readParameters() { $this->request->__run(); exit; case 'Log': + $this->request = new ChatLogPage(); + $this->request->__run(); exit; case 'RefreshRoomList': $this->request = new ChatRefreshRoomListPage(); diff --git a/file/style/be.bastelstu.wcf.chat.less b/file/style/be.bastelstu.wcf.chat.less index 5ef28b0..53ffdf1 100644 --- a/file/style/be.bastelstu.wcf.chat.less +++ b/file/style/be.bastelstu.wcf.chat.less @@ -7,7 +7,7 @@ * @package be.bastelstu.wcf.chat */ -#tplChat { +#tplChat, #tplChatLog { #content { #timsChatRoomContent { text-align: left; @@ -319,7 +319,7 @@ html.fullscreen { height: 100%; overflow: hidden; - #tplChat { + #tplChat, #tplChatLog { height: 100%; overflow: hidden; diff --git a/language/de.xml b/language/de.xml index 0ca1405..183c6c6 100644 --- a/language/de.xml +++ b/language/de.xml @@ -65,7 +65,7 @@ Hinweis: Setzen Sie diese Einstellung nur, wenn Sie wissen, was sie bewirkt. Die - Chat: Tims Chat{if CHAT_SHOW_VERSION} {$chatVersion}{/if}, entwickelt von TimWolla]]> + Chat: Tims Chat{if CHAT_SHOW_VERSION && $chatVersion|isset} {$chatVersion}{/if}, entwickelt von TimWolla]]> diff --git a/template/chatLog.tpl b/template/chatLog.tpl new file mode 100644 index 0000000..9aa89fe --- /dev/null +++ b/template/chatLog.tpl @@ -0,0 +1,108 @@ +{include file='documentHeader'} + + + {$room} - {lang}wcf.chat.log.title{/lang} - {PAGE_TITLE|language} + + {include file='headInclude' sandbox=false} + + + + +{capture assign='sidebar'}{include file='chatLogSidebar'}{/capture} +{capture assign='headerNavigation'}{include file='chatNavigationInclude'}{/capture} +{include file='header' sandbox=false sidebarOrientation='right'} + +
    +
    +
    +
      +
    • {lang}wcf.chat.noJs{/lang}
    • +
    +
    +
    + + + {include file='chatCopyright'} +
    +{include file='chatJavascriptInclude'} + + +{include file='footer' sandbox=false} + + \ No newline at end of file diff --git a/template/chatLogSidebar.tpl b/template/chatLogSidebar.tpl new file mode 100644 index 0000000..e69de29