Skip to content

Commit

Permalink
Merge pull request #35187 from nextcloud/artonge/fix/mention_in_comme…
Browse files Browse the repository at this point in the history
…nt_editor

Fix mentions rendering in comment editor
  • Loading branch information
artonge authored Nov 21, 2022
2 parents fab2776 + 0f66806 commit e644205
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions apps/comments/src/components/Comment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
:auto-complete="autoComplete"
:contenteditable="!loading"
:value="localMessage"
:user-data="userData"
@update:value="updateLocalMessage"
@submit="onSubmit" />
<NcButton class="comment__submit"
Expand Down
39 changes: 22 additions & 17 deletions apps/comments/src/views/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<!-- Editor -->
<Comment v-bind="editorData"
:auto-complete="autoComplete"
:user-data="userData"
:editor="true"
:ressource-id="ressourceId"
class="comments__writer"
Expand Down Expand Up @@ -91,9 +92,9 @@ import RefreshIcon from 'vue-material-design-icons/Refresh'
import MessageReplyTextIcon from 'vue-material-design-icons/MessageReplyText'
import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline'
import Comment from '../components/Comment'
import getComments, { DEFAULT_LIMIT } from '../services/GetComments'
import cancelableRequest from '../utils/cancelableRequest'
import Comment from '../components/Comment.vue'
import getComments, { DEFAULT_LIMIT } from '../services/GetComments.js'
import cancelableRequest from '../utils/cancelableRequest.js'
Vue.use(VTooltip)
Expand Down Expand Up @@ -129,6 +130,7 @@ export default {
},
Comment,
userData: {},
}
},
Expand Down Expand Up @@ -173,21 +175,22 @@ export default {
* Make sure we have all mentions as Array of objects
*
* @param {Array} mentions the mentions list
* @return {object[]}
* @return {Object<string, object>}
*/
genMentionsData(mentions) {
const list = Object.values(mentions).flat()
return list.reduce((mentions, mention) => {
mentions[mention.mentionId] = {
// TODO: support groups
icon: 'icon-user',
id: mention.mentionId,
label: mention.mentionDisplayName,
source: 'users',
primary: getCurrentUser().uid === mention.mentionId,
}
return mentions
}, {})
Object.values(mentions)
.flat()
.forEach(mention => {
this.userData[mention.mentionId] = {
// TODO: support groups
icon: 'icon-user',
id: mention.mentionId,
label: mention.mentionDisplayName,
source: 'users',
primary: getCurrentUser().uid === mention.mentionId,
}
})
return this.userData
},
/**
Expand Down Expand Up @@ -251,7 +254,9 @@ export default {
limit: loadState('comments', 'maxAutoCompleteResults'),
},
})
return callback(results.data.ocs.data)
// Save user data so it can be used by the editor to replace mentions
results.data.ocs.data.forEach(user => { this.userData[user.id] = user })
return callback(Object.values(this.userData))
},
/**
Expand Down
4 changes: 2 additions & 2 deletions dist/comments-comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/comments-comments-app.js.map

Large diffs are not rendered by default.

0 comments on commit e644205

Please sign in to comment.