Skip to content

Commit

Permalink
Add auto away function
Browse files Browse the repository at this point in the history
  • Loading branch information
max-m committed Dec 16, 2014
1 parent 43100bc commit ea693da
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
46 changes: 43 additions & 3 deletions file/js/be.bastelstu.Chat.litcoffee
Expand Up @@ -46,6 +46,7 @@ exposed by a function if necessary.
hidePrivateChannelTopic = no
isJoining = no
awayStatus = null
fileUploaded = no
errorVisible = false
inputErrorHidingTimer = null
Expand Down Expand Up @@ -205,7 +206,7 @@ and afterwards sent to the server by an AJAX request.
events.submit.fire obj
obj.text
new WCF.Action.Proxy
autoSend: true
data:
Expand Down Expand Up @@ -283,6 +284,10 @@ Reset autocompleter to default status, when the input is `click`ed, as the posit
offset: 0
value: null
caret: null
$('#timsChatInput').on 'input change', (event) ->
do pe.autoAway?.resume unless userList.current?[WCF.User.userID]?.awayStatus?
Bind user menu functions
Expand Down Expand Up @@ -489,6 +494,7 @@ Initialize the `PeriodicalExecuter`s
pe.refreshRoomList = new WCF.PeriodicalExecuter refreshRoomList, 60e3
pe.getMessages = new WCF.PeriodicalExecuter getMessages, v.config.reloadTime * 1e3
pe.autoAway = new WCF.PeriodicalExecuter autoAway, v.config.autoAwayTime * 1e3 if v.config.autoAwayTime > 0
Initialize the [**Push**](https://github.com/wbbaddons/Push) integration of **Tims Chat**. Once
the browser is connected to **Push** periodic message loading will be disabled and **Tims Chat** will
Expand Down Expand Up @@ -536,6 +542,29 @@ Hides the error message below the input.
inputErrorHidingTimer = null
do $('#timsChatInputContainer').removeClass('formError').find('.innerError').hide
Sets user’s status to away
autoAway = ->
do pe.autoAway?.stop
return if userList.current[WCF.User.userID].awayStatus?
text = $('#timsChatInput').val()
caret = do $('#timsChatInput').getCaret
insertText "/away #{WCF.Language.get 'chat.global.autoAway', {time: do (new Date).toTimeString}}",

This comment has been minimized.

Copy link
@max-m

max-m Dec 17, 2014

Author Member

Note: This fails when a private channel is opened/focused.

This comment has been minimized.

Copy link
@TimWolla

TimWolla Dec 17, 2014

Member

Spacing around the braces, please

prepend: false
append: false
submit: true
if text.length > 0
insertText text,
prepend: false
append: false
caret: caret
Free the fish.
Expand Down Expand Up @@ -744,7 +773,7 @@ Rebuild the userlist based on the given `users`.
handleUsers = (users) ->
foundUsers = { }
userList.current = { }
for user in users
do (user) ->
userList.current[user.userID] = userList.allTime[user.userID] = user
Expand All @@ -764,7 +793,15 @@ Move the user to the new position if he was found in the old list.
element.removeClass 'away'
element.removeAttr 'title'
element.data 'tooltip', ''
if user.userID is WCF.User.userID and user.awayStatus isnt awayStatus
if user.awayStatus?
do pe.autoAway?.stop # Away
else
do pe.autoAway?.resume # Back
awayStatus = user.awayStatus
if user.suspended
element.addClass 'suspended'
else
Expand Down Expand Up @@ -828,6 +865,7 @@ the existing text. If `options.submit` is true the message will be sent to the s
prepend: false
append: true
submit: false
caret: false
, options
text = text + $('#timsChatInput').val() if options.prepend
Expand All @@ -843,6 +881,8 @@ the existing text. If `options.submit` is true the message will be sent to the s
if options.submit
do $('#timsChatForm').submit
else
$('#timsChatInput').setCaret options.caret if options.caret
do $('#timsChatInput').focus
Send out notifications for the given `message`. The number of unread messages will be prepended to `document.title` and if available desktop notifications will be sent.
Expand Down
2 changes: 2 additions & 0 deletions language/de.xml
Expand Up @@ -186,6 +186,8 @@ Probieren Sie, den Chat neu zu laden<!-- , bei Risiken und Nebenwirkungen fragen
<item name="chat.global.message"><![CDATA[Nachricht]]></item>
<item name="chat.global.whispers"><![CDATA[Flüstert]]></item>

<item name="chat.global.autoAway"><![CDATA[{literal}Automatische Abwesenheit{if $time}: {$time}{/if}{/literal}]]></item>

<item name="chat.global.information"><![CDATA[Information]]></item>
<item name="chat.global.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte laden Sie die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
<item name="chat.global.information.suspension"><![CDATA[{lang}chat.suspension.{$suspension->type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]></item>
Expand Down
4 changes: 3 additions & 1 deletion language/en.xml
Expand Up @@ -94,7 +94,7 @@
<item name="wcf.acp.option.category.chat.general"><![CDATA[General]]></item>
<item name="wcf.acp.option.module_chat"><![CDATA[Tim’s Chat]]></item>
<item name="wcf.acp.option.chat_reloadtime"><![CDATA[Reload time]]></item>
<item name="wcf.acp.option.chat_reloadtime.description"><![CDATA[Time between to requests to the server [time in seconds]]]></item>
<item name="wcf.acp.option.chat_reloadtime.description"><![CDATA[Time between two requests to the server [time in seconds]]]></item>
<item name="wcf.acp.option.chat_lastmessages"><![CDATA[Number of old messages]]></item>
<item name="wcf.acp.option.chat_lastmessages.description"><![CDATA[Number of messages that will be shown when entering a chat room.]]></item>
<item name="wcf.acp.option.chat_display_join_leave"><![CDATA[Show join and leaves]]></item>
Expand Down Expand Up @@ -186,6 +186,8 @@ Please try to reload the chat.]]></item>
<item name="chat.global.message"><![CDATA[Message]]></item>
<item name="chat.global.whispers"><![CDATA[Whispers]]></item>

<item name="chat.global.autoAway"><![CDATA[{literal}Automatically set to away{if $time} at {$time}{/if}{/literal}]]></item>

<item name="chat.global.information"><![CDATA[Information]]></item>
<item name="chat.global.information.chatUpdate"><![CDATA[The chat was updated. Please reload the page.]]></item>
<item name="chat.global.information.suspension"><![CDATA[{lang}chat.suspension.{$suspension->type}{/lang} ({if $room}{$room}{else}{lang}chat.room.global{/lang}{/if})]]></item>
Expand Down
6 changes: 6 additions & 0 deletions option.xml
Expand Up @@ -36,6 +36,12 @@
<minvalue>1</minvalue>
<maxvalue>15</maxvalue>
</option>
<option name="chat_autoaway">
<categoryname>chat.general</categoryname>
<optiontype>integer</optiontype>
<defaultvalue>1800</defaultvalue>
<minvalue>0</minvalue>
</option>
<option name="chat_lastmessages">
<categoryname>chat.general</categoryname>
<optiontype>integer</optiontype>
Expand Down
4 changes: 3 additions & 1 deletion template/chat.tpl
Expand Up @@ -11,6 +11,7 @@
(function ($, window) {
$(function(){
WCF.Language.addObject({
'chat.global.autoAway': '{lang}chat.global.autoAway{/lang}',
'chat.global.ban': '{lang}chat.global.ban{/lang}',
'chat.global.closePrivateChannel': '{lang}chat.global.closePrivateChannel{/lang}',
'chat.global.closeTopic': '{lang}chat.global.closeTopic{/lang}',
Expand Down Expand Up @@ -56,7 +57,8 @@
reloadTime: {@CHAT_RELOADTIME},
messageURL: '{link application="chat" controller="NewMessages"}{/link}',
installedCommands: [ {implode from=$commands item='command'}'{$command|encodeJS}'{/implode} ],
messageTypes: { {implode from=$messageTypes key='name' item='messageType'}'{$name|substr:5|encodeJS}': {$messageType}{/implode} }
messageTypes: { {implode from=$messageTypes key='name' item='messageType'}'{$name|substr:5|encodeJS}': {$messageType}{/implode} },
autoAwayTime: {@CHAT_AUTOAWAY}
};
{event name='beforeInit'}
Expand Down

0 comments on commit ea693da

Please sign in to comment.