mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Integration with Talk. You can save a message as a note to remind yourself.
This commit is contained in:
@@ -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,
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user