1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Add first version of ChatLog

This commit is contained in:
Tim Düsterhus 2012-11-23 20:42:05 +01:00
parent b061992193
commit d1313bf5f9
7 changed files with 340 additions and 3 deletions

View File

@ -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 <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
# @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<object> 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></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></li>'
li.addClass 'activeMenuItem' if room.active
$('<a href="' + room.link + '">' + room.title + '</a>').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)

View File

@ -0,0 +1,117 @@
<?php
namespace wcf\page;
use \wcf\data\chat;
use \wcf\system\exception\IllegalLinkException;
use \wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF;
/**
* Shows the chat-log.
*
* @author Tim Düsterhus
* @copyright 2010-2012 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @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);
}
}

View File

@ -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();

View File

@ -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;

View File

@ -65,7 +65,7 @@ Hinweis: Setzen Sie diese Einstellung nur, wenn Sie wissen, was sie bewirkt. Die
<item name="wcf.chat.rooms"><![CDATA[Räume]]></item>
<item name="wcf.chat.users"><![CDATA[Nutzer]]></item>
<item name="wcf.chat.copyright"><![CDATA[<a href="http://tims.bastelstu.be">Chat: <strong>Tims Chat</strong>{if CHAT_SHOW_VERSION} {$chatVersion}{/if}, entwickelt von <strong>TimWolla</strong></a>]]></item>
<item name="wcf.chat.copyright"><![CDATA[<a href="http://tims.bastelstu.be">Chat: <strong>Tims Chat</strong>{if CHAT_SHOW_VERSION && $chatVersion|isset} {$chatVersion}{/if}, entwickelt von <strong>TimWolla</strong></a>]]></item>
<item name="wcf.chat.copyright.leader"><![CDATA[Projektleiter]]></item>
<item name="wcf.chat.copyright.developer"><![CDATA[Entwickler]]></item>
<item name="wcf.chat.copyright.graphics"><![CDATA[Grafisches]]></item>

108
template/chatLog.tpl Normal file
View File

@ -0,0 +1,108 @@
{include file='documentHeader'}
<head>
<title>{$room} - {lang}wcf.chat.log.title{/lang} - {PAGE_TITLE|language}</title>
{include file='headInclude' sandbox=false}
<style type="text/css">
#timsChatCopyrightDialog {
background-image: url("{link controller='Chat' action='Copyright' sheep=1}{/link}");
}
{assign var='type' value='\wcf\data\chat\message\ChatMessage::TYPE_'}
.timsChatMessage{$type|concat:'JOIN'|constant}, .timsChatMessage{$type|concat:'LEAVE'|constant},
.timsChatMessage{$type|concat:'INFORMATION'|constant}, .timsChatMessage{$type|concat:'ERROR'|constant} {
background-position: left top;
background-repeat: no-repeat;
background-size: 16px 16px;
}
.timsChatMessage{$type|concat:'JOIN'|constant} {
background-image: url({icon size='S'}circleArrowRight{/icon});
}
.timsChatMessage{$type|concat:'LEAVE'|constant} {
background-image: url({icon size='S'}circleArrowLeft{/icon});
}
.timsChatMessage{$type|concat:'INFORMATION'|constant} {
background-image: url({icon size='S'}systemInfo{/icon});
}
.timsChatMessage{$type|concat:'ERROR'|constant} {
background-image: url({icon size='S'}systemError{/icon});
}
</style>
</head>
<body id="tpl{$templateName|ucfirst}">
{capture assign='sidebar'}{include file='chatLogSidebar'}{/capture}
{capture assign='headerNavigation'}{include file='chatNavigationInclude'}{/capture}
{include file='header' sandbox=false sidebarOrientation='right'}
<div id="timsChatRoomContent">
<fieldset>
<div class="timsChatMessageContainer container box shadow1">
<ul>
<li class="error">{lang}wcf.chat.noJs{/lang}</li>
</ul>
</div>
</fieldset>
<div id="timsChatControls" class="marginTop">
<nav id="timsChatOptions">
<ul class="smallButtons">
<li>
<a id="timsChatFullscreen" accesskey="f" class="timsChatToggle jsTooltip button" title="{lang}wcf.global.button.disable{/lang}" data-disable-message="{lang}wcf.global.button.disable{/lang}" data-enable-message="{lang}wcf.global.button.enable{/lang}" data-status="0">
<img alt="" src="{icon size='S'}disabled{/icon}" /> <span>{lang}wcf.chat.fullscreen{/lang}</span>
</a>
</li>
<li>
<a id="timsChatMark" class="jsTooltip button" title="{lang}wcf.chat.mark.description{/lang}">
<img alt="" src="{icon size='S'}check{/icon}" /> <span>{lang}wcf.chat.mark{/lang}</span>
</a>
</li>
</ul>
</nav>
</div>
{include file='chatCopyright'}
</div>
{include file='chatJavascriptInclude'}
<script type="text/javascript">
//<![CDATA[
(function ($, window) {
// remove noscript message
$('.timsChatMessageContainer .error').remove();
// populate templates
{capture assign='chatMessageTemplate'}{include file='chatMessage'}{/capture}
be.bastelstu.WCF.Chat.Log.messageTemplate = (new WCF.Template('{@$chatMessageTemplate|encodeJS}')).compile();
{event name='shouldInit'}
// Boot the chat
be.bastelstu.WCF.Chat.Log.init();
{event name='didInit'}
// show the last X messages
be.bastelstu.WCF.Chat.Log.handleMessages([
{implode from=$messages item='message'}
{@$message->jsonify()}
{/implode}
]);
$('#timsChatCopyright').click(function (event) {
event.preventDefault();
if ($.wcfIsset('timsChatCopyrightDialog')) return WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION && $chatVersion|isset} {$chatVersion}{/if}' });
var container = $('<fieldset id="timsChatCopyrightDialog"></fieldset>');
container.load('{link controller='Chat' action='Copyright'}{/link}', function() {
$('body').append(container);
WCF.showDialog('timsChatCopyrightDialog', { title: 'Tims Chat{if CHAT_SHOW_VERSION && $chatVersion|isset} {$chatVersion}{/if}' });
});
});
})(jQuery, this)
//]]>
</script>
{include file='footer' sandbox=false}
</body>
</html>

View File