From 47a84a9d7f7ec30556284962d4f7ced533f49be7 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 9 Dec 2014 23:57:25 +0100 Subject: [PATCH] Implement invitations in frontend --- file/js/be.bastelstu.Chat.litcoffee | 37 ++++++++--- file/lib/data/user/UserAction.class.php | 54 ++++++++++++++++ language/de.xml | 4 ++ language/en.xml | 4 ++ template/chat.tpl | 8 +++ template/userInviteDialog.tpl | 84 +++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 8 deletions(-) create mode 100644 file/lib/data/user/UserAction.class.php create mode 100644 template/userInviteDialog.tpl diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 871d64e..27368ab 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -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) -> + $('
').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 $("""#{WCF.String.formatNumeric room.userCount}""").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 diff --git a/file/lib/data/user/UserAction.class.php b/file/lib/data/user/UserAction.class.php new file mode 100644 index 0000000..9d9b87c --- /dev/null +++ b/file/lib/data/user/UserAction.class.php @@ -0,0 +1,54 @@ + + * @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 ]); + } +} diff --git a/language/de.xml b/language/de.xml index a7d9439..af66711 100644 --- a/language/de.xml +++ b/language/de.xml @@ -161,6 +161,9 @@ Probieren Sie, den Chat neu zu laden