Integrate with Nextcloud Talk: Allow bookmarking mentioned links

fixes #1068

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2022-02-24 16:53:22 +01:00
parent 2c84a67685
commit 861bbb415e
6 changed files with 104 additions and 0 deletions

View File

@ -16,6 +16,7 @@ use OCA\Bookmarks\Events\CreateEvent;
use OCA\Bookmarks\Events\MoveEvent;
use OCA\Bookmarks\Events\UpdateEvent;
use OCA\Bookmarks\Flow\CreateBookmark;
use OCA\Bookmarks\Hooks\BeforeTemplateRenderedListener;
use OCA\Bookmarks\Hooks\UserGroupListener;
use OCA\Bookmarks\Middleware\ExceptionMiddleware;
use OCA\Bookmarks\Search\Provider;
@ -24,6 +25,7 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
@ -69,6 +71,9 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(BeforeUserDeletedEvent::class, UserGroupListener::class);
$context->registerEventListener(UserAddedEvent::class, UserGroupListener::class);
$context->registerEventListener(UserRemovedEvent::class, UserGroupListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$context->registerMiddleware(ExceptionMiddleware::class);
}

View File

@ -0,0 +1,33 @@
<?php
/*
* Copyright (c) 2022. The Nextcloud Bookmarks contributors.
*
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
namespace OCA\Bookmarks\Hooks;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IRequest;
use OCP\Util;
class BeforeTemplateRenderedListener implements IEventListener {
private $request;
public function __construct(IRequest $request) {
$this->request = $request;
}
public function handle(Event $event): void {
if (!($event instanceof BeforeTemplateRenderedEvent)) {
return;
}
if (!$event->isLoggedIn()) {
return;
}
if (strpos($this->request->getPathInfo(), '/call/') === 0) {
Util::addScript('bookmarks', 'bookmarks-talk');
}
}
}

27
package-lock.json generated
View File

@ -21,6 +21,7 @@
"clone-deep": "^4.0.1",
"copy-text-to-clipboard": "^3.0.1",
"humanize-duration": "^3.27.1",
"linkify-it": "^3.0.3",
"lodash": "^4.17.21",
"sanitize-html": "^2.7.0",
"vue": "^2.6.14",
@ -8297,6 +8298,14 @@
"dev": true,
"peer": true
},
"node_modules/linkify-it": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz",
"integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==",
"dependencies": {
"uc.micro": "^1.0.1"
}
},
"node_modules/linkifyjs": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-2.1.9.tgz",
@ -12872,6 +12881,11 @@
"node": ">= 0.6"
}
},
"node_modules/uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
"integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
},
"node_modules/unbox-primitive": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz",
@ -20737,6 +20751,14 @@
"dev": true,
"peer": true
},
"linkify-it": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz",
"integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==",
"requires": {
"uc.micro": "^1.0.1"
}
},
"linkifyjs": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-2.1.9.tgz",
@ -24274,6 +24296,11 @@
"mime-types": "~2.1.24"
}
},
"uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
"integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
},
"unbox-primitive": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz",

View File

@ -33,6 +33,7 @@
"clone-deep": "^4.0.1",
"copy-text-to-clipboard": "^3.0.1",
"humanize-duration": "^3.27.1",
"linkify-it": "^3.0.3",
"lodash": "^4.17.21",
"sanitize-html": "^2.7.0",
"vue": "^2.6.14",

37
src/talk.js Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2020. The Nextcloud Bookmarks contributors.
*
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import linkify from 'linkify-it'
const Linkify = linkify()
window.addEventListener('DOMContentLoaded', () => {
if (!window.OCA?.Talk?.registerMessageAction) {
return
}
window.OCA.Talk.registerMessageAction({
label: t('bookmarks', 'Create bookmarks for mentioned links'),
icon: 'icon-favorite',
async callback({ message: { message, actorDisplayName }, metadata: { name: conversationName, token: conversationToken } }) {
try {
const urls = Linkify.match(message)
if (!urls || !urls.length) {
showError(t('bookmarks', 'No links found in this message'))
return
}
const bookmarkletUrl = window.location.origin + generateUrl('/apps/bookmarks/bookmarklet')
urls.forEach((url) => {
window.open(`${bookmarkletUrl}?url=` + encodeURIComponent(url.text), 'bkmk_popup', 'left=' + ((window.screenX || window.screenLeft) + 10) + ',top=' + ((window.screenY || window.screenTop) + 10) + ',height=650px,width=550px,resizable=1,alwaysRaised=1')
})
} catch (e) {
console.debug('Bookmark creation dialog was canceled')
}
},
})
})

View File

@ -7,3 +7,4 @@ webpackConfig.entry.admin = path.join(__dirname, 'src', 'admin.js')
webpackConfig.entry['service-worker'] = path.join(__dirname, 'src', 'service-worker.js')
webpackConfig.entry.flow = path.join(__dirname, 'src', 'flow.js')
webpackConfig.entry.dashboard = path.join(__dirname, 'src', 'dashboard.js')
webpackConfig.entry.talk = path.join(__dirname, 'src', 'talk.js')