mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Implement invitations in frontend
This commit is contained in:
parent
09fb08b633
commit
47a84a9d7f
@ -101,7 +101,7 @@ Initialize **Tims Chat**. Bind needed DOM events and initialize data structures.
|
||||
When **Tims Chat** becomes focused mark the chat as active and remove the number of new messages from the title.
|
||||
|
||||
$(window).focus ->
|
||||
document.title = v.titleTemplate.fetch(roomList.active) if roomList.active?.title? and roomList.active.title.trim() isnt ''
|
||||
document.title = v.titleTemplate.fetch(getRoomList().active) if roomList.active?.title? and roomList.active.title.trim() isnt ''
|
||||
|
||||
newMessageCount = 0
|
||||
isActive = true
|
||||
@ -177,7 +177,7 @@ Open the smiley wcfDialog
|
||||
overlaySmileyList.css
|
||||
'max-height': $(window).height() - overlaySmileyList.parent().siblings('.dialogTitlebar').outerHeight()
|
||||
'overflow': 'auto'
|
||||
|
||||
|
||||
Handle private channel menu
|
||||
|
||||
$('#timsChatMessageTabMenu > .tabMenu').on 'click', '.timsChatMessageTabMenuAnchor', ->
|
||||
@ -351,6 +351,25 @@ Toggle checkboxes.
|
||||
else
|
||||
$('.timsChatMessageContainer').removeClass 'markEnabled'
|
||||
|
||||
Show invite dialog.
|
||||
|
||||
$('#timsChatInvite').click (event) ->
|
||||
do event.preventDefault
|
||||
|
||||
new WCF.Action.Proxy
|
||||
autoSend: true
|
||||
data:
|
||||
actionName: 'prepareInvite'
|
||||
className: 'chat\\data\\user\\UserAction'
|
||||
showLoadingOverlay: true
|
||||
suppressErrors: false
|
||||
success: (data) ->
|
||||
$('<div id="timsChatInviteDialog"></div>').appendTo 'body' unless $.wcfIsset 'timsChatInviteDialog'
|
||||
|
||||
$('#timsChatInviteDialog').html(data.returnValues.template).wcfDialog
|
||||
title: WCF.Language.get 'chat.global.invite'
|
||||
|
||||
|
||||
Hide topic container.
|
||||
|
||||
$('#timsChatTopicCloser').on 'click', ->
|
||||
@ -858,7 +877,7 @@ Fetch the roomlist from the server and update it in the GUI.
|
||||
roomList =
|
||||
active: {}
|
||||
available: {}
|
||||
|
||||
|
||||
do $('.timsChatRoom').remove
|
||||
$('#toggleRooms .badge').text data.returnValues.length
|
||||
|
||||
@ -874,7 +893,7 @@ Fetch the roomlist from the server and update it in the GUI.
|
||||
a.appendTo li
|
||||
$("""<span class="badge">#{WCF.String.formatNumeric room.userCount}</span>""").appendTo li
|
||||
$('#timsChatRoomList ul').append li
|
||||
|
||||
|
||||
if window.history?.replaceState?
|
||||
$('.timsChatRoom a').click (event) ->
|
||||
do event.preventDefault
|
||||
@ -887,7 +906,7 @@ Fetch the roomlist from the server and update it in the GUI.
|
||||
join target.data 'roomID'
|
||||
$('#timsChatRoomList .active').removeClass 'active'
|
||||
target.parent().addClass 'active'
|
||||
|
||||
|
||||
console.log "Found #{data.returnValues.length} rooms"
|
||||
|
||||
Shows an unrecoverable error with the given text.
|
||||
@ -945,7 +964,7 @@ Joins a room.
|
||||
|
||||
$('.timsChatMessage').addClass 'unloaded'
|
||||
|
||||
document.title = v.titleTemplate.fetch roomList.active
|
||||
document.title = v.titleTemplate.fetch getRoomList().active
|
||||
handleMessages roomList.active.messages
|
||||
do getMessages
|
||||
do refreshRoomList
|
||||
@ -1068,6 +1087,8 @@ Remove the given callback from the given event.
|
||||
|
||||
true
|
||||
|
||||
getRoomList = -> JSON.parse JSON.stringify roomList
|
||||
|
||||
The following code handles attachment uploads
|
||||
|
||||
Enable attachment code if `WCF.Attachment.Upload` is defined
|
||||
@ -1293,8 +1314,8 @@ Return a copy of the object containing the IDs of the marked messages
|
||||
|
||||
getMarkedMessages: -> JSON.parse JSON.stringify markedMessages
|
||||
getUserList: -> JSON.parse JSON.stringify userList
|
||||
getRoomList: -> JSON.parse JSON.stringify roomList
|
||||
|
||||
getRoomList: getRoomList
|
||||
|
||||
refreshRoomList: refreshRoomList
|
||||
insertText: insertText
|
||||
freeTheFish: freeTheFish
|
||||
|
54
file/lib/data/user/UserAction.class.php
Normal file
54
file/lib/data/user/UserAction.class.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?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 {
|
||||
protected $className = 'wcf\data\user\UserEditor';
|
||||
|
||||
public function validatePrepareInvite() {
|
||||
// Todo: Proper validation
|
||||
}
|
||||
|
||||
public function prepareInvite() {
|
||||
$followingList = new \wcf\data\user\follow\UserFollowingList();
|
||||
$followingList->getConditionBuilder()->add('user_follow.userID = ?', array(WCF::getUser()->userID));
|
||||
$followingList->readObjects();
|
||||
$users = $followingList->getObjects();
|
||||
|
||||
WCF::getTPL()->assign(array(
|
||||
'users' => $users
|
||||
));
|
||||
|
||||
return array(
|
||||
'template' => WCF::getTPL()->fetch('userInviteDialog', 'chat')
|
||||
);
|
||||
}
|
||||
|
||||
public function validateInvite() {
|
||||
$this->recipients = (isset($_POST['recipients'])) ? $_POST['recipients'] : null;
|
||||
|
||||
if (!$this->recipients) {
|
||||
throw new \wcf\system\exception\UserInputException("recipients");
|
||||
}
|
||||
|
||||
if (WCF::getUser()->chatRoomID) {
|
||||
$this->room = \chat\data\room\RoomCache::getInstance()->getRoom(WCF::getUser()->chatRoomID);
|
||||
}
|
||||
else {
|
||||
throw new \wcf\system\exception\UserInputException("roomID");
|
||||
}
|
||||
}
|
||||
|
||||
public function invite() {
|
||||
\wcf\system\user\notification\UserNotificationHandler::getInstance()->fireEvent('invited', 'be.bastelstu.chat.room', new \chat\system\user\notification\object\RoomUserNotificationObject($this->room), $this->recipients, [ 'userID' => WCF::getUser()->userID ]);
|
||||
}
|
||||
}
|
@ -161,6 +161,9 @@ Probieren Sie, den Chat neu zu laden<!-- , bei Risiken und Nebenwirkungen fragen
|
||||
<item name="chat.global.rooms"><![CDATA[Chaträume]]></item>
|
||||
<item name="chat.global.users"><![CDATA[Nutzer]]></item>
|
||||
|
||||
<item name="chat.global.invite"><![CDATA[Benutzer einladen]]></item>
|
||||
<item name="chat.global.invite.noFollowing"><![CDATA[Keine Benutzer gefunden, verwenden Sie bitte die Suche.]]></item>
|
||||
|
||||
<item name="chat.global.copyright"><![CDATA[<a href="http://tims.bastelstu.be"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}><strong>Tims Chat{if SHOW_VERSION_NUMBER} {PACKAGE_VERSION}{/if}</strong>, entwickelt in <strong>Tims Bastelstu.be</strong></a>]]></item>
|
||||
<item name="chat.global.copyright.leader"><![CDATA[Projektleiter]]></item>
|
||||
<item name="chat.global.copyright.developer"><![CDATA[Entwickler]]></item>
|
||||
@ -251,5 +254,6 @@ Probieren Sie, den Chat neu zu laden<!-- , bei Risiken und Nebenwirkungen fragen
|
||||
|
||||
<category name="chat.user">
|
||||
<item name="chat.user.usersOnline.location.ChatPage"><![CDATA[<a href="{link controller='Chat' application='chat' object=$room}{/link}">Chatraum „{$room}“</a>]]></item>
|
||||
<item name="chat.user.search"><![CDATA[Benutzer suchen]]></item>
|
||||
</category>
|
||||
</language>
|
||||
|
@ -161,6 +161,9 @@ Please try to reload the chat.]]></item>
|
||||
<item name="chat.global.rooms"><![CDATA[Chatrooms]]></item>
|
||||
<item name="chat.global.users"><![CDATA[Users]]></item>
|
||||
|
||||
<item name="chat.global.invite"><![CDATA[Invite users]]></item>
|
||||
<item name="chat.global.invite.noFollowing"><![CDATA[No users found, please use the search function instead.]]></item>
|
||||
|
||||
<item name="chat.global.copyright"><![CDATA[<a href="http://tims.bastelstu.be"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}><strong>Tim’s Chat{if SHOW_VERSION_NUMBER} {PACKAGE_VERSION}{/if}</strong>, developed in <strong>Tim’s Bastelstu.be</strong></a>]]></item>
|
||||
<item name="chat.global.copyright.leader"><![CDATA[Project Lead]]></item>
|
||||
<item name="chat.global.copyright.developer"><![CDATA[Developers]]></item>
|
||||
@ -251,5 +254,6 @@ Please try to reload the chat.]]></item>
|
||||
|
||||
<category name="chat.user">
|
||||
<item name="chat.user.usersOnline.location.ChatPage"><![CDATA[<a href="{link controller='Chat' application='chat' object=$room}{/link}">Chatroom “{$room}”</a>]]></item>
|
||||
<item name="chat.user.search"><![CDATA[Search for users]]></item>
|
||||
</category>
|
||||
</language>
|
||||
|
@ -21,6 +21,7 @@
|
||||
'chat.global.query': '{lang}chat.global.query{/lang}',
|
||||
'chat.global.smilies': '{lang}chat.global.smilies{/lang}',
|
||||
'chat.global.whisper': '{lang}chat.global.whisper{/lang}',
|
||||
'chat.global.invite': '{lang}chat.global.invite{/lang}',
|
||||
'chat.error.duplicateTab': '{lang}chat.error.duplicateTab{/lang}',
|
||||
'chat.error.join': '{lang}chat.error.join{/lang}',
|
||||
'chat.error.onMessageLoad': '{@"chat.error.onMessageLoad"|language|encodeJS}',
|
||||
@ -189,6 +190,13 @@
|
||||
</li>
|
||||
{/if}
|
||||
|
||||
<li>
|
||||
<a id="timsChatInvite" class="button jsTooltip" title="{lang}chat.global.invite{/lang}">
|
||||
<span class="icon icon16 icon-user"></span>
|
||||
<span class="invisible">{lang}chat.global.invite{/lang}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a id="timsChatClear" class="button jsTooltip" title="{lang}chat.global.clear{/lang}">
|
||||
<span class="icon icon16 icon-remove"></span>
|
||||
|
84
template/userInviteDialog.tpl
Normal file
84
template/userInviteDialog.tpl
Normal file
@ -0,0 +1,84 @@
|
||||
<div id="userInviteDialogContainer">
|
||||
<fieldset>
|
||||
<legend>{lang}wcf.user.access.following{/lang}</legend>
|
||||
|
||||
{if $users|count === 0}
|
||||
<p class="noFollowing">{lang}chat.global.invite.noFollowing{/lang}</p>
|
||||
{/if}
|
||||
|
||||
<div id="userInviteDialogUserlist">
|
||||
<dl>
|
||||
{foreach from=$users item=$user}
|
||||
<dt></dt>
|
||||
<dd><label><input type="checkbox" id="userInviteDialogUserID-{$user->userID}" data-user-id="{$user->userID}" /> {$user->username}</label></dd>
|
||||
{/foreach}
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="formSubmit">
|
||||
<input id="userInviteDialogFormSubmit" type="submit" value="{lang}wcf.global.button.submit{/lang}" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>{lang}chat.user.search{/lang}</legend>
|
||||
|
||||
<dl>
|
||||
<dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
|
||||
<dd>
|
||||
<span>
|
||||
<input autocomplete="off" id="userInviteDialogUsernameInput" name="username" class="medium" value="" type="text" />
|
||||
</span>
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
new WCF.Search.User('#userInviteDialogUsernameInput', function(user) {
|
||||
if (!$.wcfIsset('userInviteDialogUserID-' + user.objectID)) {
|
||||
$('.noFollowing').hide();
|
||||
|
||||
$('#userInviteDialogUserlist').append('<dl>\
|
||||
<dt></dt>\
|
||||
<dd>\
|
||||
<label>\
|
||||
<input type="checkbox" id="userInviteDialogUserID-' + user.objectID + '" data-user-id="' + user.objectID + '" checked="checked" /> ' + user.label + '\
|
||||
</label>\
|
||||
</dd>\
|
||||
</dl>');
|
||||
}
|
||||
else {
|
||||
$('#userInviteDialogUserID-' + user.objectID).prop('checked', true);
|
||||
}
|
||||
|
||||
$('#userInviteDialogUsernameInput').val('');
|
||||
}, false, ['{$__wcf->getUser()->username|encodeJS}'], false);
|
||||
|
||||
$('#userInviteDialogFormSubmit').on('click', function(event) {
|
||||
var checked = $('#userInviteDialogUserlist input[type=checkbox]:checked');
|
||||
var userList = [];
|
||||
|
||||
checked.each(function(k, v) {
|
||||
userList.push($(v).data('userID'));
|
||||
});
|
||||
|
||||
if (userList.length) {
|
||||
new WCF.Action.Proxy({
|
||||
autoSend: true,
|
||||
data: {
|
||||
actionName: 'invite',
|
||||
className: 'chat\\data\\user\\UserAction',
|
||||
recipients: userList
|
||||
},
|
||||
success: function (data) {
|
||||
new WCF.System.Notification('{lang}wcf.global.success{/lang}').show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#timsChatInviteDialog').wcfDialog('close');
|
||||
});
|
||||
})();
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user