1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-21 21:30:08 +00:00

Merge branch 'UserOptions'

This commit is contained in:
Maximilian Mader 2014-12-14 01:51:09 +01:00
commit 43100bcdf9
5 changed files with 136 additions and 26 deletions

View File

@ -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.
@ -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'
@ -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.
@ -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
@ -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

View File

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

View File

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

View File

@ -153,14 +153,14 @@
</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>
@ -168,7 +168,7 @@
{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>

24
userOption.xml Normal file
View File

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