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

Add user online locations for chat

This commit is contained in:
Tim Düsterhus 2013-05-10 17:51:48 +02:00
parent ee8d677d23
commit 28c67c1a52
7 changed files with 105 additions and 33 deletions

View File

@ -58,9 +58,10 @@ Attributes needed for notificationss
Attributes needed for autocompleter Attributes needed for autocompleter
autocompleteOffset: 0 autocomplete:
autocompleteValue: null offset: 0
autocompleteCaret: 0 value: null
caret: 0
Attributes needed for automated scrolling Attributes needed for automated scrolling
@ -117,7 +118,7 @@ Finished!
**autocomplete(firstChars, offset = @autocompleteOffset)** **autocomplete(firstChars, offset = @autocompleteOffset)**
Autocompletes a username based on the `firstChars` given and the given `offset`. `offset` allows to skip users. Autocompletes a username based on the `firstChars` given and the given `offset`. `offset` allows to skip users.
autocomplete: (firstChars, offset = @autocompleteOffset) -> autocompleter: (firstChars, offset = @autocomplete.offset) ->
Create an array of active chatters with usernames beginning with `firstChars` Create an array of active chatters with usernames beginning with `firstChars`
@ -171,18 +172,19 @@ Calls the submit handler (`@submit`) when the `#timsChatForm` is `submit`ted.
Autocompletes a username when TAB is pressed. Autocompletes a username when TAB is pressed.
$('#timsChatInput').keydown (event) => $('#timsChatInput').keydown (event) =>
if event.keyCode is 9 if event.keyCode is $.ui.keyCode.TAB
input = $(event.currentTarget)
event.preventDefault() event.preventDefault()
Calculate `firstChars` to autocomplete, based on the caret position. Calculate `firstChars` to autocomplete, based on the caret position.
@autocompleteValue = $('#timsChatInput').val() if @autocompleteValue is null @autocomplete.value ?= input.val()
@autocompleteCaret = $('#timsChatInput').getCaret() if @autocompleteCaret is null @autocomplete.caret ?= input.getCaret()
beforeCaret = @autocompleteValue.substring 0, @autocompleteCaret beforeCaret = @autocomplete.value.substring 0, @autocomplete.caret
lastSpace = beforeCaret.lastIndexOf ' ' lastSpace = beforeCaret.lastIndexOf ' '
beforeComplete = @autocompleteValue.substring 0, lastSpace + 1 beforeComplete = @autocomplete.value.substring 0, lastSpace + 1
toComplete = @autocompleteValue.substring lastSpace + 1 toComplete = @autocomplete.value.substring lastSpace + 1
nextSpace = toComplete.indexOf ' ' nextSpace = toComplete.indexOf ' '
if nextSpace is -1 if nextSpace is -1
afterComplete = ''; afterComplete = '';
@ -195,25 +197,25 @@ Calculate `firstChars` to autocomplete, based on the caret position.
Insert completed value into `#timsChatInput` Insert completed value into `#timsChatInput`
name = @autocomplete toComplete name = @autocompleter toComplete
$('#timsChatInput').val "#{beforeComplete}#{name} #{afterComplete}" input.val "#{beforeComplete}#{name} #{afterComplete}"
$('#timsChatInput').setCaret (beforeComplete + name).length + 1 input.setCaret (beforeComplete + name).length + 1
@autocompleteOffset++ @autocompleteOffset++
Resets autocompleter to default status, when a key is pressed that is not TAB. Resets autocompleter to default status, when a key is pressed that is not TAB.
else else
@autocompleteOffset = 0 @autocomplete.offset = 0
@autocompleteValue = null @autocomplete.value = null
@autocompleteCaret = null @autocomplete.caret = null
Resets autocompleter to default status, when input is `click`ed, as the position of the caret may have changed. Resets autocompleter to default status, when input is `click`ed, as the position of the caret may have changed.
$('#timsChatInput').click => $('#timsChatInput').click =>
@autocompleteOffset = 0 @autocomplete.offset = 0
@autocompleteValue = null @autocomplete.value = null
@autocompleteCaret = null @autocomplete.caret = null
Refreshes the room list when the associated button is `click`ed. Refreshes the room list when the associated button is `click`ed.
@ -526,7 +528,7 @@ Build HTML of new user and append it.
menu.append $ "<li><a>#{WCF.Language.get('chat.general.kick')}</a></li>" menu.append $ "<li><a>#{WCF.Language.get('chat.general.kick')}</a></li>"
menu.append $ "<li><a>#{WCF.Language.get('chat.general.ban')}</a></li>" menu.append $ "<li><a>#{WCF.Language.get('chat.general.ban')}</a></li>"
# TODO: SID and co # TODO: SID and co
menu.append $ """<li><a href="index.php/User/#{user.userID}-#{encodeURI(user.username)}/">#{WCF.Language.get('chat.general.profile')}</a></li>""" menu.append $ """<li><a href="#{user.link}">#{WCF.Language.get('chat.general.profile')}</a></li>"""
@events.userMenu.fire user, menu @events.userMenu.fire user, menu
li.append menu li.append menu

View File

@ -79,6 +79,11 @@ class ChatPage extends \wcf\page\AbstractPage {
*/ */
public $userData = array(); public $userData = array();
/**
* @see wcf\page\AbstractPage::$enableTracking
*/
public $enableTracking = true;
/** /**
* @see \wcf\page\IPage::assignVariables() * @see \wcf\page\IPage::assignVariables()
*/ */
@ -221,4 +226,18 @@ public function show() {
)); ));
exit; exit;
} }
/**
* @see wcf\page\ITrackablePage::getObjectType()
*/
public function getObjectType() {
return 'be.bastelstu.chat.room';
}
/**
* @see wcf\page\ITrackablePage::getObjectID()
*/
public function getObjectID() {
return $this->room->roomID;
}
} }

View File

@ -1,5 +1,7 @@
<?php <?php
namespace chat\page; namespace chat\page;
use wcf\system\request\LinkHandler;
use \chat\data; use \chat\data;
use \wcf\system\exception\IllegalLinkException; use \wcf\system\exception\IllegalLinkException;
use \wcf\system\WCF; use \wcf\system\WCF;
@ -132,7 +134,10 @@ public function show() {
24 => $user->getAvatar()->getImageTag(24), 24 => $user->getAvatar()->getImageTag(24),
32 => $user->getAvatar()->getImageTag(32), 32 => $user->getAvatar()->getImageTag(32),
48 => $user->getAvatar()->getImageTag(48) 48 => $user->getAvatar()->getImageTag(48)
) ),
'link' => LinkHandler::getInstance()->getLink('User', array(
'user' => $user->getDecoratedObject()
))
); );
} }

View File

@ -0,0 +1,35 @@
<?php
namespace chat\system\user\online\location;
use chat\data;
/**
* Implementation of IUserOnlineLocation for the chat.
*
* @author Tim Düsterhus
* @copyright 2010-2013 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package be.bastelstu.chat
* @subpackage page
*/
class ChatLocation implements \wcf\system\user\online\location\IUserOnlineLocation {
/**
* @see wcf\system\user\online\location\IUserOnlineLocation::cache()
*/
public function cache(\wcf\data\user\online\UserOnline $user) {}
/**
* @see wcf\system\user\online\location\IUserOnlineLocation::get()
*/
public function get(\wcf\data\user\online\UserOnline $user, $languageVariable = '') {
$cache = data\room\Room::getCache();
if (isset($cache[$user->objectID])) {
if ($cache[$user->objectID]->canEnter()) {
return \wcf\system\WCF::getLanguage()->getDynamicVariable($languageVariable, array(
'room' => $cache[$user->objectID]
));
}
}
return '';
}
}

View File

@ -51,7 +51,15 @@
<item name="wcf.acp.option.chat_log_archivetime"><![CDATA[Speicherzeit]]></item> <item name="wcf.acp.option.chat_log_archivetime"><![CDATA[Speicherzeit]]></item>
<item name="wcf.acp.option.chat_log_archivetime.description"><![CDATA[Gibt die Zeit in Minuten an, die eine Nachricht im Protokoll gespeichert bleibt.]]></item> <item name="wcf.acp.option.chat_log_archivetime.description"><![CDATA[Gibt die Zeit in Minuten an, die eine Nachricht im Protokoll gespeichert bleibt.]]></item>
</category> </category>
<category name="chat.error">
<item name="chat.error"><![CDATA[Fehler]]></item>
<item name="chat.error.notFound"><![CDATA[Der Befehl wurde nicht gefunden.]]></item>
<item name="chat.error.userNotFound"><![CDATA[Der Benutzer „{$exception->getUsername()}“ wurde nicht gefunden.]]></item>
<item name="chat.error.permissionDenied"><![CDATA[Sie dürfen diesen Befehl nicht verwenden.]]></item>
<item name="chat.error.exception"><![CDATA[Es gab ein Problem bei der Ausführung dieses Befehls. Bitte wenden Sie sich an einen Administrator.]]></item>
</category>
<category name="chat.general"> <category name="chat.general">
<item name="chat.general.title"><![CDATA[Chat]]></item> <item name="chat.general.title"><![CDATA[Chat]]></item>
<item name="chat.general.protocol"><![CDATA[Protokoll]]></item> <item name="chat.general.protocol"><![CDATA[Protokoll]]></item>
@ -85,12 +93,8 @@
<item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte lade die Seite neu, da es sonst zu Fehlern kommen kann.]]></item> <item name="chat.general.information.chatUpdate"><![CDATA[Der Chat wurde aktualisiert. Bitte lade die Seite neu, da es sonst zu Fehlern kommen kann.]]></item>
</category> </category>
<category name="chat.error"> <category name="chat.header">
<item name="chat.error"><![CDATA[Fehler]]></item> <item name="chat.header.menu.chat"><![CDATA[Chat]]></item>
<item name="chat.error.notFound"><![CDATA[Der Befehl wurde nicht gefunden.]]></item>
<item name="chat.error.userNotFound"><![CDATA[Der Benutzer „{$exception->getUsername()}“ wurde nicht gefunden.]]></item>
<item name="chat.error.permissionDenied"><![CDATA[Sie dürfen diesen Befehl nicht verwenden.]]></item>
<item name="chat.error.exception"><![CDATA[Es gab ein Problem bei der Ausführung dieses Befehls. Bitte wenden Sie sich an einen Administrator.]]></item>
</category> </category>
<category name="chat.message"> <category name="chat.message">
@ -118,8 +122,8 @@
<item name="chat.room.topic1"><![CDATA[Vielen Dank, dass Sie sich für Tims Chat entschieden haben. Bitte besuchen Sie das ACP um diesen Text anzupassen.]]></item> <item name="chat.room.topic1"><![CDATA[Vielen Dank, dass Sie sich für Tims Chat entschieden haben. Bitte besuchen Sie das ACP um diesen Text anzupassen.]]></item>
<item name="chat.room.titleTemp"><![CDATA[Raum_{$roomID}]]></item> <item name="chat.room.titleTemp"><![CDATA[Raum_{$roomID}]]></item>
</category> </category>
<category name="chat.header"> <category name="chat.user">
<item name="chat.header.menu.chat"><![CDATA[Chat]]></item> <item name="chat.user.usersOnline.location.ChatPage"><![CDATA[<a href="{link controller='Chat' application='chat' object=$room}{/link}">Chatraum „{$room}“</a>]]></item>
</category> </category>
</language> </language>

View File

@ -17,5 +17,12 @@
<points>0</points> <points>0</points>
<classname>wcf\system\user\activity\point\DefaultUserActivityPointObjectProcessor</classname><!-- We are unable to recalc those points --> <classname>wcf\system\user\activity\point\DefaultUserActivityPointObjectProcessor</classname><!-- We are unable to recalc those points -->
</type> </type>
<type>
<name>be.bastelstu.chat.ChatPage</name>
<definitionname>com.woltlab.wcf.user.online.location</definitionname>
<controller>chat\page\ChatPage</controller>
<classname>chat\system\user\online\location\ChatLocation</classname>
<languagevariable>chat.user.usersOnline.location.ChatPage</languagevariable>
</type>
</import> </import>
</data> </data>

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription> <packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription> <packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
<isapplication>1</isapplication> <isapplication>1</isapplication>
<version>3.0.0 Alpha 21</version><!-- Codename: Codenames are overrated --> <version>3.0.0 Alpha 22</version><!-- Codename: Codenames are overrated -->
<date>2011-11-26</date> <date>2011-11-26</date>
</packageinformation> </packageinformation>
@ -49,7 +49,7 @@
<instruction type="objectType">objectType.xml</instruction> <instruction type="objectType">objectType.xml</instruction>
<instruction type="option">option.xml</instruction> <instruction type="option">option.xml</instruction>
<instruction type="templateListener">templateListener.xml</instruction> <instruction type="templateListener">templateListener.xml</instruction>
<instruction type="pageMenu">pageMenu.xml</instruction> <!--instruction type="pageMenu">pageMenu.xml</instruction-->
<instruction type="aclOption">aclOption.xml</instruction> <instruction type="aclOption">aclOption.xml</instruction>
<instruction type="acpMenu">acpMenu.xml</instruction> <instruction type="acpMenu">acpMenu.xml</instruction>
<instruction type="userGroupOption">userGroupOption.xml</instruction> <instruction type="userGroupOption">userGroupOption.xml</instruction>