Skip to content

Commit

Permalink
Merge branch 'UserOptions'
Browse files Browse the repository at this point in the history
  • Loading branch information
max-m committed Dec 14, 2014
2 parents a30a922 + a2a1a86 commit 43100bc
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 26 deletions.
86 changes: 63 additions & 23 deletions file/js/be.bastelstu.Chat.litcoffee
Expand Up @@ -181,7 +181,7 @@ Open the smiley wcfDialog
Handle private channel menu
$('#timsChatMessageTabMenu > .tabMenu').on 'click', '.timsChatMessageTabMenuAnchor', ->
openPrivateChannel $(@).data 'userID'
openPrivateChannel $(@).data 'userID'
Handle submitting the form. The message will be validated by some basic checks, passed to the `submit` eventlisteners
and afterwards sent to the server by an AJAX request.
Expand Down Expand Up @@ -318,8 +318,30 @@ Handle toggling of the toggleable buttons.
do $('#timsChatInput').focus
Handle saving of persistent toggleable buttons
$('.timsChatToggle.persists').click (event) ->
do event.preventDefault
new WCF.Action.Proxy
autoSend: true
data:
actionName: 'updateOption'
className: 'chat\\data\\user\\UserAction'
parameters:
optionName: "chatButton#{$(@).attr('id').replace /^timsChat/, ''}"
optionValue: $(@).data 'status'
showLoadingOverlay: false
suppressErrors: true
Mark smilies as disabled when they are disabled.
if $('#timsChatSmilies').data('status') is 0
$('#smilies').addClass 'invisible'
else
$('#smilies').removeClass 'invisible'
$('#timsChatSmilies').click (event) ->
if $(@).data 'status'
$('#smilies').removeClass 'invisible'
Expand All @@ -328,20 +350,34 @@ Mark smilies as disabled when they are disabled.
Toggle fullscreen mode.
$('#timsChatFullscreen').click (event) ->
# Force dropdowns to reorientate
$('.dropdownMenu').data 'orientationX', ''
if $(@).data 'status'
messageContainerSize = $('.timsChatMessageContainer').height()
do ->
fullscreen = (status = true) ->
if status
messageContainerSize = $('.timsChatMessageContainer').height()
$('html').addClass 'fullscreen'
do $(window).resize
else
$('.timsChatMessageContainer').height messageContainerSize
$('#timsChatUserList').height userListSize
$('html').removeClass 'fullscreen'
do $(window).resize
$('#timsChatFullscreen').click (event) ->
# Force dropdowns to reorientate
$('.dropdownMenu').data 'orientationX', ''
$('html').addClass 'fullscreen'
do $(window).resize
if $(@).data 'status'
fullscreen on
else
fullscreen off
Switch to fullscreen mode on mobile devices or if fullscreen is active on boot
if $('#timsChatFullscreen').data('status') is 1
fullscreen on
else
$('.timsChatMessageContainer').height messageContainerSize
$('#timsChatUserList').height userListSize
$('html').removeClass 'fullscreen'
do $(window).resize
do $('#timsChatFullscreen').click if WCF.System.Mobile.UX._enabled
Toggle checkboxes.
Expand Down Expand Up @@ -433,12 +469,20 @@ Enable duplicate tab detection.
Ask for permissions to use Desktop notifications when notifications are activated.
if window.Notification?
$('#timsChatNotify').click (event) ->
return unless $(@).data 'status'
unless window.Notification.permission is 'granted'
window.Notification.requestPermission (permission) ->
window.Notification.permission ?= permission
do ->
askForPermission = ->
unless window.Notification.permission is 'granted'
window.Notification.requestPermission (permission) ->
window.Notification.permission ?= permission
if $('#timsChatNotify').data('status') is 1
do askForPermission
$('#timsChatNotify').click (event) ->
return unless $(@).data 'status'
do askForPermission
events.newMessage.add notify
Initialize the `PeriodicalExecuter`s
Expand Down Expand Up @@ -466,10 +510,6 @@ load messages if the appropriate event arrives.
be.bastelstu.wcf.push.onMessage 'be.bastelstu.chat.join', refreshRoomList
be.bastelstu.wcf.push.onMessage 'be.bastelstu.chat.leave', refreshRoomList
Switch to fullscreen mode on mobile devices
do $('#timsChatFullscreen').click if WCF.System.Mobile.UX._enabled
Finished! Enable the input now and join the chat.
join roomID
Expand Down
45 changes: 45 additions & 0 deletions file/lib/data/user/UserAction.class.php
@@ -0,0 +1,45 @@
<?php
namespace chat\data\user;
use wcf\system\WCF;

/**
* User related chat actions.
*
* @author Maximilian Mader
* @copyright 2010-2014 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package be.bastelstu.chat
* @subpackage data.user
*/
class UserAction extends \wcf\data\AbstractDatabaseObjectAction {
/**
* @see \wcf\data\AbstractDatabaseObjectAction::$className
*/
protected $className = 'wcf\data\user\UserEditor';

/**
* Validates updating of chat user options
*/
public function validateUpdateOption() {
$this->readString('optionName');
$this->readBoolean('optionValue');

if (!preg_match('~^chat[A-Z]~', $this->parameters['optionName'])) throw new \wcf\system\exception\UserInputException('optionName');

$this->optionID = \wcf\data\user\User::getUserOptionID($this->parameters['optionName']);

if (!$this->optionID) throw new \wcf\system\exception\UserInputException('optionName');
}

/**
* Updates chat user options
*/
public function updateOption() {
$userAction = new \wcf\data\user\UserAction(array(WCF::getUser()), 'update', array(
'options' => array(
$this->optionID => $this->parameters['optionValue'] ? 1 : 0
)
));
$userAction->executeAction();
}
}
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -34,6 +34,7 @@
<instruction type="pageMenu">pageMenu.xml</instruction>
<instruction type="aclOption">aclOption.xml</instruction>
<instruction type="acpMenu">acpMenu.xml</instruction>
<instruction type="userOption">userOption.xml</instruction>
<instruction type="userGroupOption">userGroupOption.xml</instruction>
<instruction type="eventListener">eventListener.xml</instruction>
<instruction type="dashboardBox">dashboardBox.xml</instruction>
Expand Down
6 changes: 3 additions & 3 deletions template/chat.tpl
Expand Up @@ -153,22 +153,22 @@
</li>
<li>
<a id="timsChatFullscreen" accesskey="f" class="button timsChatToggle jsTooltip" title="{lang}chat.global.fullscreen{/lang}" data-status="0">
<a id="timsChatFullscreen" accesskey="f" class="button{if $__wcf->getUser()->chatButtonFullscreen} active{/if} timsChatToggle persists jsTooltip" title="{lang}chat.global.fullscreen{/lang}" data-status="{@$__wcf->getUser()->chatButtonFullscreen}">
<span class="icon icon16 icon-fullscreen"></span>
<span class="invisible">{lang}chat.global.fullscreen{/lang}</span>
</a>
</li>
<li>
<a id="timsChatNotify" accesskey="n" class="button timsChatToggle jsTooltip" title="{lang}chat.global.notify{/lang}" data-status="0">
<a id="timsChatNotify" accesskey="n" class="button{if $__wcf->getUser()->chatButtonNotify} active{/if} timsChatToggle persists jsTooltip" title="{lang}chat.global.notify{/lang}" data-status="{@$__wcf->getUser()->chatButtonNotify}">
<span class="icon icon16 icon-bell-alt"></span>
<span class="invisible">{lang}chat.global.notify{/lang}</span>
</a>
</li>
{if MODULE_SMILEY && $smileyCategories|count}
<li>
<a id="timsChatSmilies" accesskey="e" class="button{if ENABLE_SMILIES_DEFAULT_VALUE} active{/if} timsChatToggle jsTooltip" title="{lang}chat.global.smilies{/lang}" data-status="{@ENABLE_SMILIES_DEFAULT_VALUE}">
<a id="timsChatSmilies" accesskey="e" class="button{if $__wcf->getUser()->chatButtonSmilies} active{/if} timsChatToggle persists jsTooltip" title="{lang}chat.global.smilies{/lang}" data-status="{@$__wcf->getUser()->chatButtonSmilies}">
<span class="icon icon16 icon-smile"></span>
<span class="invisible">{lang}chat.global.smilies{/lang}</span>
</a>
Expand Down
24 changes: 24 additions & 0 deletions userOption.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/userOption.xsd">
<import>
<options>
<option name="chatButtonFullscreen">
<categoryname>hidden</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
</option>

<option name="chatButtonNotify">
<categoryname>hidden</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
</option>

<option name="chatButtonSmilies">
<categoryname>hidden</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>1</defaultvalue>
</option>
</options>
</import>
</data>

0 comments on commit 43100bc

Please sign in to comment.