Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-07-13 09:56:20 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-08-08 11:24:49 +0300
commit7190c2086f85c46522db4e2bfa75e6127e0c277c (patch)
tree29c48e71258fcb3156b04c52b32ed57a6b482036
parentefc9d95b22795d043d3b0848eb297172ac1dab47 (diff)
Load additional scripts in public share auth page when needed
Before the public share auth page is rendered an event is dispatched that can be used by apps to load additional scripts. This event is now used to load the scripts that, when run on the browser, will inject the Talk UI as needed in the page generated by the server. The scripts will be loaded only when the share has the "send password by Talk" option enabled; they add a button to the page that, when pressed, creates a new public share auth room with the sharer and shows, in a sidebar, the Talk UI for that room. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--css/publicshareauth.scss132
-rw-r--r--js/publicshareauth.js125
-rw-r--r--lib/AppInfo/Application.php14
-rw-r--r--lib/PublicShareAuth/TemplateLoader.php92
4 files changed, 363 insertions, 0 deletions
diff --git a/css/publicshareauth.scss b/css/publicshareauth.scss
new file mode 100644
index 000000000..218e385be
--- /dev/null
+++ b/css/publicshareauth.scss
@@ -0,0 +1,132 @@
+/* Request password button has the appearance of the log in button */
+.request-password-wrapper {
+ position: relative;
+ width: 280px;
+ margin: 16px auto;
+}
+
+.request-password-wrapper .icon {
+ position: absolute;
+ top: 23px;
+ right: 23px;
+ pointer-events: none;
+}
+
+input#request-password-button {
+ width: 269px;
+ padding: 10px 10px;
+}
+
+input#request-password-button:disabled ~ .icon {
+ opacity: 0.5;
+}
+
+
+
+/* Special layout to include the Talk sidebar */
+/* The original style of the body is kept until the layout has been adjusted to
+ * include the Talk sidebar. If only "#body-login" was used, immediately after
+ * load and before the sidebar was injected the original elements would be using
+ * the style for the adjusted layout, which is not the proper one for them, and
+ * this would cause the elements to "jump" to their final position once the
+ * layout was adjusted. */
+#body-login.talk-sidebar-enabled {
+ flex-direction: row;
+ align-items: stretch;
+}
+
+/* #body-login should be used to override the #content rules set in server. */
+#body-login #content {
+ flex-grow: 1;
+
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+
+ height: auto;
+
+ overflow-x: hidden;
+
+ /* Override "padding-top: 50px" set in server. */
+ padding-top: 0;
+}
+
+/* Properties based on the app-sidebar */
+#talk-sidebar {
+ position: relative;
+ flex-shrink: 0;
+ width: 27vw;
+ min-width: 300px;
+ height: 100vh;
+
+ background: var(--color-main-background);
+ border-left: 1px solid var(--color-border);
+
+ overflow-x: hidden;
+ overflow-y: auto;
+ z-index: 500;
+
+ transition: 300ms width ease-in-out,
+ 300ms min-width ease-in-out;
+}
+
+#talk-sidebar.disappear {
+ width: 0;
+ min-width: 0;
+ border-left-width: 0;
+}
+
+#talk-sidebar #commentsTabView ~ #emptycontent {
+ display: none !important;
+}
+
+
+
+/**
+ * Cascade parent element height to the chat view in the sidebar to limit the
+ * vertical scroll bar only to the list of messages. Otherwise, the vertical
+ * scroll bar would be shown for the whole sidebar and everything would be
+ * moved when scrolling to see overflown messages.
+ *
+ * The list of messages should stretch to fill the available space at the bottom
+ * of the right sidebar, so the height is cascaded using flex boxes.
+ */
+#talk-sidebar {
+ display: flex;
+ flex-direction: column;
+}
+
+#talk-sidebar #commentsTabView {
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+
+ flex-grow: 1;
+}
+
+#talk-sidebar .comments {
+ overflow-y: auto;
+
+ /* Needed for proper calculation of comment positions in the scrolling
+ container (as otherwise the comment position is calculated with respect
+ to the closest ancestor with a relative position) */
+ position: relative;
+}
+
+#talk-sidebar #commentsTabView .newCommentRow,
+#talk-sidebar #commentsTabView .comments {
+ padding-left: 15px;
+ padding-right: 15px;
+}
+
+
+
+/* Unset conflicting rules from guest.css for the sidebar */
+#talk-sidebar {
+ text-align: left;
+}
+
+#talk-sidebar form {
+ width: unset;
+ margin: 0;
+}
diff --git a/js/publicshareauth.js b/js/publicshareauth.js
new file mode 100644
index 000000000..50b8f2483
--- /dev/null
+++ b/js/publicshareauth.js
@@ -0,0 +1,125 @@
+/**
+ *
+ * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+(function(OCA) {
+ 'use strict';
+
+ OCA.Talk = OCA.Talk || {};
+ OCA.Talk.PublicShareAuth = {
+
+ init: function() {
+ var self = this;
+
+ this.setupRequestPasswordButton();
+ this.setupLayoutForTalkSidebar();
+
+ $('#request-password-button').click(function() {
+ $('.request-password-wrapper + .error-message').hide();
+
+ $('#request-password-button').prop('disabled', 'true');
+
+ $('.request-password-wrapper .icon')
+ .removeClass('icon-confirm-white')
+ .addClass('icon-loading-small-dark');
+
+ self.requestPassword();
+ });
+ },
+
+ setupRequestPasswordButton: function() {
+ // "submit-wrapper" is used to mimic the login button and thus get
+ // automatic colouring of the confirm icon by the Theming app
+ $('main').append('<div id="submit-wrapper" class="request-password-wrapper">' +
+ ' <input id="request-password-button" class="primary" type="button" value="' + t('spreed', 'Request password') + '" >' +
+ ' <div class="icon icon-confirm-white"></div>' +
+ '</div>');
+ },
+
+ setupLayoutForTalkSidebar: function() {
+ $('body').append('<div id="content"></div>');
+ $('#content').append($('.wrapper'));
+ $('#content').append($('footer'));
+
+ $('body').append('<div id="talk-sidebar" class="disappear"></div>');
+ $('#talk-sidebar').append('<div id="emptycontent"><div id="emptycontent-icon" class="icon-loading"></div><h2></h2><p></p></div>');
+
+ $('body').addClass('talk-sidebar-enabled');
+ },
+
+ requestPassword: function() {
+ var self = this;
+
+ var shareToken = $('#sharingToken').val();
+
+ $.ajax({
+ url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'publicshareauth',
+ type: 'POST',
+ data: {
+ shareToken: shareToken,
+ },
+ beforeSend: function(request) {
+ request.setRequestHeader('Accept', 'application/json');
+ },
+ success: function(ocsResponse) {
+ self.setupRoom(ocsResponse.ocs.data.token);
+ },
+ error: function() {
+ $('.request-password-wrapper .icon')
+ .removeClass('icon-loading-small-dark')
+ .addClass('icon-confirm-white');
+ $('#request-password-button').prop('disabled', '');
+
+ var errorMessage = $('.request-password-wrapper + .error-message');
+ if (errorMessage.length > 0) {
+ errorMessage.show();
+ } else {
+ $('.request-password-wrapper').after('<p class="warning error-message hidden">' + t('spreed', 'Error requesting the password.') + '</p>');
+ }
+ }
+ });
+ },
+
+ setupRoom: function(token) {
+ var self = this;
+
+ OCA.SpreedMe.app.activeRoom = new OCA.SpreedMe.Models.Room({token: token});
+ OCA.SpreedMe.app.signaling.setRoom(OCA.SpreedMe.app.activeRoom);
+
+ OCA.SpreedMe.app.connection.joinRoom(token);
+
+ OCA.SpreedMe.app._chatView.$el.prependTo('#talk-sidebar');
+ OCA.SpreedMe.app._chatView.setTooltipContainer($('body'));
+
+ OCA.SpreedMe.app.signaling.on('joinRoom', function() {
+ self.showTalkSidebar();
+ });
+ },
+
+ showTalkSidebar: function() {
+ $('#talk-sidebar').removeClass('disappear');
+ },
+ };
+
+ OCA.SpreedMe.app = new OCA.Talk.Application();
+ OCA.SpreedMe.app.start();
+
+ OCA.Talk.PublicShareAuth.init();
+})(OCA);
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index f82414172..dd2ce85c0 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -36,6 +36,7 @@ use OCA\Spreed\Signaling\Messages;
use OCP\AppFramework\App;
use OCP\IServerContainer;
use OCP\Settings\IManager;
+use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
@@ -77,6 +78,7 @@ class Application extends App {
$systemMessageListener->register();
$this->registerPublicShareAuthHooks($dispatcher);
+ $this->registerLoadAdditionalScriptsHooks($dispatcher);
}
protected function registerNotifier(IServerContainer $server) {
@@ -350,4 +352,16 @@ class Application extends App {
$dispatcher->addListener(Room::class . '::postUserDisconnectRoom', $listener);
$dispatcher->addListener(Room::class . '::postCleanGuests', $listener);
}
+
+ protected function registerLoadAdditionalScriptsHooks(EventDispatcherInterface $dispatcher) {
+ $listener = function(GenericEvent $event) {
+ /** @var IShare $share */
+ $share = $event->getArgument('share');
+
+ /** @var \OCA\Spreed\PublicShareAuth\TemplateLoader $templateLoader */
+ $templateLoader = $this->getContainer()->query(\OCA\Spreed\PublicShareAuth\TemplateLoader::class);
+ $templateLoader->loadRequestPasswordByTalkUi($share);
+ };
+ $dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $listener);
+ }
}
diff --git a/lib/PublicShareAuth/TemplateLoader.php b/lib/PublicShareAuth/TemplateLoader.php
new file mode 100644
index 000000000..0aff24355
--- /dev/null
+++ b/lib/PublicShareAuth/TemplateLoader.php
@@ -0,0 +1,92 @@
+<?php
+declare(strict_types=1);
+
+/**
+ *
+ * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Spreed\PublicShareAuth;
+
+use OCP\Share\IShare;
+use OCP\Util;
+
+/**
+ * Helper class to extend the "publicshareauth" template from the server.
+ *
+ * The "loadRequestPasswordByTalkUi" method loads additional scripts that, when
+ * run on the browser, adjust the page generated by the server to inject the
+ * Talk UI as needed.
+ */
+class TemplateLoader {
+
+ /**
+ * Load the "Request password by Talk" UI in the public share authentication
+ * page for the given share.
+ *
+ * If the "Send Password by Talk" option is not set in the share then no UI
+ * to request the password is provided.
+ *
+ * This method should be called when loading additional scripts for the
+ * public share authentication page of the server.
+ *
+ * @param IShare $share
+ */
+ public function loadRequestPasswordByTalkUi(IShare $share) {
+ if (!$share->getSendPasswordByTalk()) {
+ return;
+ }
+
+ Util::addStyle('spreed', 'publicshareauth');
+ Util::addStyle('spreed', 'style');
+ Util::addStyle('spreed', 'comments');
+ Util::addStyle('spreed', 'autocomplete');
+
+ Util::addScript('spreed', 'vendor/backbone/backbone-min');
+ Util::addScript('spreed', 'vendor/backbone.radio/build/backbone.radio.min');
+ Util::addScript('spreed', 'vendor/backbone.marionette/lib/backbone.marionette.min');
+ Util::addScript('spreed', 'vendor/jshashes/hashes.min');
+ Util::addScript('spreed', 'vendor/Caret.js/dist/jquery.caret.min');
+ Util::addScript('spreed', 'vendor/At.js/dist/js/jquery.atwho.min');
+ Util::addScript('spreed', 'models/chatmessage');
+ Util::addScript('spreed', 'models/chatmessagecollection');
+ Util::addScript('spreed', 'models/localstoragemodel');
+ Util::addScript('spreed', 'models/room');
+ Util::addScript('spreed', 'models/roomcollection');
+ Util::addScript('spreed', 'models/participant');
+ Util::addScript('spreed', 'models/participantcollection');
+ Util::addScript('spreed', 'views/callinfoview');
+ Util::addScript('spreed', 'views/chatview');
+ Util::addScript('spreed', 'views/editabletextlabel');
+ Util::addScript('spreed', 'views/participantlistview');
+ Util::addScript('spreed', 'views/participantview');
+ Util::addScript('spreed', 'views/roomlistview');
+ Util::addScript('spreed', 'views/sidebarview');
+ Util::addScript('spreed', 'views/tabview');
+ Util::addScript('spreed', 'richobjectstringparser');
+ Util::addScript('spreed', 'simplewebrtc');
+ Util::addScript('spreed', 'webrtc');
+ Util::addScript('spreed', 'signaling');
+ Util::addScript('spreed', 'connection');
+ Util::addScript('spreed', 'app');
+ Util::addScript('spreed', 'init');
+ Util::addScript('spreed', 'publicshareauth');
+ }
+
+}