Skip to content

Commit

Permalink
Add matrix share
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorunome committed Jul 8, 2021
1 parent f65be0b commit d78a618
Show file tree
Hide file tree
Showing 43 changed files with 2,230 additions and 106 deletions.
16 changes: 11 additions & 5 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>riotchat</id>
<name>Element for Nextcloud</name>
<summary>Element Web integrated into Nextcloud</summary>
<name>Matrix Nextcloud Integration</name>
<summary>Integrate Matrix into your Nextcloud</summary>
<description><![CDATA[Element for Nextcloud allows you to install Element Web easily through Nextcloud and join the Matrix decentralized communication network.
This app does not include a Matrix server, only the client. You will have to either set up your own Matrix homeserver, rent one, or use a public one.
Expand All @@ -16,6 +16,7 @@ The upstream project can be found at [https://github.com/vector-im/element-web](
<version>0.7.13</version>
<licence>agpl</licence>
<author mail="gary@garykim.dev" homepage="https://garykim.dev">Gary Kim</author>
<author mail="mail@sorunome.de" homepage="https://sorunome.de">Sorunome</author>
<namespace>RiotChat</namespace>
<category>social</category>
<category>integration</category>
Expand All @@ -28,13 +29,18 @@ The upstream project can be found at [https://github.com/vector-im/element-web](
<nextcloud min-version="19" max-version="22"/>
</dependencies>
<settings>
<admin>OCA\RiotChat\Settings\Admin</admin>
<admin-section>OCA\RiotChat\Settings\AdminSection</admin-section>
<admin>OCA\RiotChat\Settings\ElementAdmin</admin>
<admin>OCA\RiotChat\Settings\ShareAdmin</admin>
<admin-section>OCA\RiotChat\Settings\ElementAdminSection</admin-section>
<personal>OCA\RiotChat\Settings\Personal</personal>
</settings>
<background-jobs>
<job>OCA\RiotChat\Cron\RoomSyncTask</job>
</background-jobs>
<navigations>
<navigation>
<name>Element</name>
<route>riotchat.app.index</route>
<route>riotchat.element.index</route>
<icon>app.svg</icon>
</navigation>
</navigations>
Expand Down
64 changes: 60 additions & 4 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,69 @@
* 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/>.
*/
return [

use OC\Route\Router;
use OCA\RiotChat\RouteConfig;
use OCA\RiotChat\AppInfo\Application;

$application = \OC::$server->get(Application::class);
$router = $this;


// by using a modified RouteConfig to register the routes we can bypass the root url restrictions placed on most apps
$routeConfig = new RouteConfig($application->getContainer(), $router, [
'routes' => [
['name' => 'app#index', 'url' => '/', 'verb' => 'GET'],
// elementweb routes
['name' => 'element#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'static#index', 'url' => '/riot/', 'verb' => 'GET'],
['name' => 'config#config', 'url' => '/riot/config.json', 'verb' => 'GET'],
['name' => 'element#config', 'url' => '/riot/config.json', 'verb' => 'GET'],
['name' => 'static#usercontent', 'url' => '/riot/bundles/{version}/usercontent.js', 'verb' => 'GET'],
['name' => 'static#riot', 'url' => '/riot/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+']],
['name' => 'settings#setSetting', 'url' => '/settings/{key}', 'verb' => 'PUT'],
// general personal matrix routes
[
'name' => 'matrix#whoami',
'url' => '/whoami',
'verb' => 'GET',
],
[
'name' => 'matrix#login',
'url' => '/login',
'verb' => 'POST',
],
[
'name' => 'matrix#logout',
'url' => '/logout',
'verb' => 'POST',
],
[
'name' => 'matrix#roomSummary',
'url' => '/room_summary',
'verb' => 'GET',
],
// file sharing routes
[
'name' => 'fileShare#matrixDownload',
'url' => '/_matrix/media/r0/download/{mxc}',
'verb' => 'GET',
'requirements' => ['mxc' => '.+'],
'root' => '',
],
[
'name' => 'fileShare#matrixThumbnail',
'url' => '/_matrix/media/r0/thumbnail/{mxc}',
'verb' => 'GET',
'requirements' => ['mxc' => '.+'],
'root' => '',
],
[
'name' => 'fileShare#matrixEvent',
'url' => '/_matrix/media/r0/event/{mxc}',
'verb' => 'GET',
'requirements' => ['mxc' => '.+'],
'root' => '',
],

]
];
]);
$routeConfig->register();
3 changes: 3 additions & 0 deletions css/settings-personal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#matrixSettings {
display: grid;
}
9 changes: 9 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.icon-matrix {
background-image: url('../img/matrix.svg');
}

#matrix-integration-room-picker {
position: absolute;
top: 0;
left: 0;
}
14 changes: 14 additions & 0 deletions img/matrix.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions js-old/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
window.addEventListener('DOMContentLoaded', () => {
var appName = 'matrix_integration';
function url(path) {
return OC.generateUrl('/apps/' + appName + path);
}
function roomPicker(title, callback) {
var $el = $('<div id="matrix-integration-room-picker" class="popover">');
$el.append($('<img class="loading icon-loading">'));
$('body').append($el);

console.log('WAAAAAAAAAAAAAA');
console.log(url('/room_summary'));
$.getJSON(url('/room_summary'), function(data) {
var rooms = [];
for (var d of data) {
rooms.push($('<li>').text(d.display_name));
}
$el.empty().append(
$('<div class="popover__wrapper">').append(
$('<div class="popover__inner">').append(
$('<h4>').text(title),
$('<ul>').append(rooms),
),
),
);
});
}

if (OCA.Sharing && OCA.Sharing.ExternalLinkActions) {
OCA.Sharing.ExternalLinkActions.registerAction({
url: link => `matrixshare:${link}`,
name: t('socialsharing_matrix', 'Share to Matrix'),
icon: 'icon-matrix'
});
$(document).on('click', 'a[href^="matrixshare:"]', function (e) {
e.preventDefault();
e.stopPropagation();
var shareUrl = $(this).attr('href').substr('matrixshare:'.length);
roomPicker('Select a room to share into', function(roomId) {
alert(roomId);
alert('matrix share ' + shareUrl);
});
});
}
});
27 changes: 27 additions & 0 deletions js-old/settings-personal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
window.addEventListener('DOMContentLoaded', function() {
var appName = $('#matrixSettings').data('appname');
function url(path) {
return OC.generateUrl('/apps/' + appName + path);
}
function proccessWhoami(data) {
$('#matrixSettingsLoginForm').hide();
$('#matrixSettingsLogoutForm').hide();
if (!data.logged_in) {
$('#matrixSettingsLoginForm').show();
} else {
$('#matrixSettingsUserId').text(data.user_id);
$('#matrixSettingsLogoutForm').show();
}
}
$.getJSON(url('/whoami'), proccessWhoami);
$('#matrixSettingsLoginButton').click(function(e) {
e.preventDefault();
var username = $('#matrixSettingsLoginUsername').val();
var password = $('#matrixSettingsLoginPassword').val();
$.post(url('/login'), { username, password }, proccessWhoami);
});
$('#matrixSettingsLogoutButton').click(function(e) {
e.preventDefault();
$.post(url('/logout'), {}, proccessWhoami);
});
});
8 changes: 8 additions & 0 deletions js-old/settings-share-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
window.addEventListener('DOMContentLoaded', function() {
var appName = $('#matrixSharingSettings').data('appname');

$('#matrixSharingSettings input').change(function() {
OCP.AppConfig.setValue(appName, $(this).attr('name'), this.value);
});

});
14 changes: 14 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

namespace OCA\RiotChat\AppInfo;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;
use OCP\IConfig;

class Application extends App {
public const APP_ID = 'riotchat';
Expand All @@ -43,10 +47,20 @@ class Application extends App {
'show_labs_settings' => 'true',
'set_custom_permalink' => 'false',
'sso_immediate_redirect' => 'false',
'share_domain' => '',
'share_prefix' => '',
'share_suffix' => '',
];

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);

/** @var IEventDispatcher $eventDispatcher */
$dispatcher = $this->getContainer()->query(IEventDispatcher::class);
$dispatcher->addListener(LoadAdditionalScriptsEvent::class, function(LoadAdditionalScriptsEvent $event) {
Util::addScript(self::APP_ID, 'common');
Util::addStyle(self::APP_ID, 'style');
});
}

public static function AvailableLabs() {
Expand Down
77 changes: 0 additions & 77 deletions lib/Controller/AppController.php

This file was deleted.

Loading

0 comments on commit d78a618

Please sign in to comment.