diff --git a/src/init-talk.js b/src/init-talk.js index 3720d092d..3998a4a88 100644 --- a/src/init-talk.js +++ b/src/init-talk.js @@ -44,14 +44,33 @@ window.addEventListener('DOMContentLoaded', () => { window.OCA.Talk.registerMessageAction({ label: t('deck', 'Create a card'), icon: 'icon-deck', - async callback({ message: { message, actorDisplayName }, metadata: { name: conversationName, token: conversationToken } }) { - const shortenedMessageCandidate = message.replace(/^(.{255}[^\s]*).*/, '$1') - const shortenedMessage = shortenedMessageCandidate === '' ? message.substr(0, 255) : shortenedMessageCandidate + async callback({ message: { message, 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 shortenedMessageCandidate = parsedMessage.replace(/^(.{255}[^\s]*).*/, '$1') + const shortenedMessage = shortenedMessageCandidate === '' ? parsedMessage.substr(0, 255) : shortenedMessageCandidate try { await buildSelector(CardCreateDialog, { props: { title: shortenedMessage, - description: message + '\n\n' + '[' + description: parsedMessage + '\n\n' + '[' + t('deck', 'Message from {author} in {conversationName}', { author: actorDisplayName, conversationName,