Skip to content

Commit

Permalink
Merge pull request #3741 from nextcloud/backport/stable23/3683
Browse files Browse the repository at this point in the history
[stable23] Fix paramter replacements when creating deck cards from talk messages
  • Loading branch information
juliusknorr authored Apr 21, 2022
2 parents 7a3fb00 + afbd6ce commit 983247b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/init-talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 983247b

Please sign in to comment.