mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +01:00
Integration with Talk. You can save a message as a note to remind yourself.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
build
|
||||
js/templates.js
|
||||
js/quicknotes-dashboard.js*
|
||||
js/quicknotes-talk.js*
|
||||
node_modules
|
||||
vendor
|
||||
translationfiles/
|
||||
|
||||
1
Makefile
1
Makefile
@@ -121,6 +121,7 @@ appstore: distclean build
|
||||
--exclude=templates/fake.php \
|
||||
--exclude=translation* \
|
||||
--exclude=webpack*.js \
|
||||
--exclude=*.js.map \
|
||||
--exclude=psalm.xml \
|
||||
$(project_dir) $(sign_dir)
|
||||
@echo "Signing…"
|
||||
|
||||
@@ -34,6 +34,7 @@ use OCP\IURLGenerator;
|
||||
use OCP\IServerContainer;
|
||||
|
||||
use OCA\QuickNotes\Search\NoteSearchProvider;
|
||||
use OCA\QuickNotes\Listeners\BeforeTemplateRenderedListener;
|
||||
|
||||
class Application extends App implements IBootstrap {
|
||||
|
||||
|
||||
@@ -2,16 +2,23 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\QuickNotes\AppInfo;
|
||||
namespace OCA\QuickNotes\Listeners;
|
||||
|
||||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\IRequest;
|
||||
use OCP\Util;
|
||||
|
||||
class BeforeTemplateRenderedListener implements IEventListener {
|
||||
|
||||
public function handle(Event $event): void {
|
||||
private $request;
|
||||
|
||||
public function __construct(IRequest $request) {
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof BeforeTemplateRenderedEvent)) {
|
||||
return;
|
||||
}
|
||||
@@ -20,7 +27,12 @@ class BeforeTemplateRenderedListener implements IEventListener {
|
||||
return;
|
||||
}
|
||||
|
||||
\OCP\Util::addStyle('quicknotes', 'global');
|
||||
Util::addStyle('quicknotes', 'global');
|
||||
|
||||
$pathInfo = $this->request->getPathInfo();
|
||||
if (strpos($pathInfo, '/call/') === 0 || strpos($pathInfo, '/apps/spreed') === 0) {
|
||||
Util::addScript('quicknotes', 'quicknotes-talk');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,23 @@ export const getDashboardData = () => {
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
showError(t('notes', 'Fetching notes for dashboard has failed.'))
|
||||
showError(t('quicknotes', 'There was an error fetching your notes for the dashboard'))
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
export const postNewNote = (title, content) => {
|
||||
return axios
|
||||
.post(url('/notes'), {
|
||||
title: title,
|
||||
content: content,
|
||||
})
|
||||
.then(response => {
|
||||
return response.data
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
showError(t('quicknotes', 'There was an error saving the note'))
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
60
src/talk.js
Normal file
60
src/talk.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import { showError, showSuccess } from '@nextcloud/dialogs'
|
||||
|
||||
import { postNewNote } from './NotesService.js'
|
||||
|
||||
Vue.prototype.t = t
|
||||
Vue.prototype.n = n
|
||||
Vue.prototype.OC = OC
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
if (!window.OCA?.Talk?.registerMessageAction) {
|
||||
return
|
||||
}
|
||||
|
||||
window.OCA.Talk.registerMessageAction({
|
||||
label: t('quicknotes', 'Save as a note'),
|
||||
icon: 'icon-quicknotes',
|
||||
async callback({message: { message, id: messageId, messageParameters, actorDisplayName }, metadata: { name: conversationName, token: conversationToken }}) {
|
||||
const parsedMessage = message.replace(/{[a-z0-9-_]+}/gi, function(parameter) {
|
||||
const parameterName = parameter.substr(1, parameter.length - 2)
|
||||
if (messageParameters[parameterName]) {
|
||||
if (messageParameters[parameterName].type === 'file' && messageParameters[parameterName].path) {
|
||||
return messageParameters[parameterName].path
|
||||
}
|
||||
if (messageParameters[parameterName].type === 'user' || messageParameters[parameterName].type === 'call') {
|
||||
return '@' + messageParameters[parameterName].name
|
||||
}
|
||||
if (messageParameters[parameterName].name) {
|
||||
return messageParameters[parameterName].name
|
||||
}
|
||||
}
|
||||
// Do not replace so insert with curly braces again
|
||||
return parameter
|
||||
})
|
||||
|
||||
const title = t('quicknotes', 'Message from {author} in the call {conversationName}', {
|
||||
author: actorDisplayName,
|
||||
conversationName,
|
||||
})
|
||||
|
||||
const callLink = window.location.origin + generateUrl('/call/{conversationToken}#message_{messageId}', { conversationToken, messageId })
|
||||
|
||||
let content = '<p>' + parsedMessage + '</p>'
|
||||
content += '<p><br></p>'
|
||||
content += '<p><a href="' + callLink + '" rel="noopener noreferrer" target="_blank">' + callLink + '</a></p>'
|
||||
|
||||
postNewNote(title, content).then(data => {
|
||||
const noteUrl = generateUrl('apps/quicknotes/?n={noteId}', {noteId: data.id})
|
||||
showSuccess(t('quicknotes', 'Message saved as a new note. <a target="_blank" rel="noreferrer noopener" href="{link}" >See that. ↗</a>', {
|
||||
link: noteUrl,
|
||||
}), {
|
||||
isHTML: true,
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -2,7 +2,8 @@ const path = require('path')
|
||||
const webpackConfig = require('@nextcloud/webpack-vue-config')
|
||||
|
||||
webpackConfig.entry = {
|
||||
dashboard: { import: path.join(__dirname, 'src', 'dashboard.js') }
|
||||
dashboard: { import: path.join(__dirname, 'src', 'dashboard.js') },
|
||||
talk: { import: path.join(__dirname, 'src', 'talk.js') }
|
||||
}
|
||||
|
||||
module.exports = webpackConfig
|
||||
|
||||
Reference in New Issue
Block a user