Skip to content

Commit e4ff935

Browse files
artongedanxuliu
authored andcommitted
Fix mentions rendering in comment editor
NcRichContentEditable needs an index of users to properly display them. This commit adds a caching logic and provides it to NcRichContentEditable. Signed-off-by: Louis Chemineau <[email protected]>
1 parent 799838a commit e4ff935

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

apps/comments/src/components/Comment.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
:auto-complete="autoComplete"
7272
:contenteditable="!loading"
7373
:value="localMessage"
74+
:user-data="userData"
7475
@update:value="updateLocalMessage"
7576
@submit="onSubmit" />
7677
<input v-tooltip="t('comments', 'Post comment')"

apps/comments/src/views/Comments.vue

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<!-- Editor -->
2626
<Comment v-bind="editorData"
2727
:auto-complete="autoComplete"
28+
:user-data="userData"
2829
:editor="true"
2930
:ressource-id="ressourceId"
3031
class="comments__writer"
@@ -77,9 +78,9 @@ import Vue from 'vue'
7778
7879
import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent'
7980
80-
import Comment from '../components/Comment'
81-
import getComments, { DEFAULT_LIMIT } from '../services/GetComments'
82-
import cancelableRequest from '../utils/cancelableRequest'
81+
import Comment from '../components/Comment.vue'
82+
import getComments, { DEFAULT_LIMIT } from '../services/GetComments.js'
83+
import cancelableRequest from '../utils/cancelableRequest.js'
8384
8485
Vue.use(VTooltip)
8586
@@ -111,6 +112,7 @@ export default {
111112
},
112113
113114
Comment,
115+
userData: {},
114116
}
115117
},
116118
@@ -153,21 +155,22 @@ export default {
153155
/**
154156
* Make sure we have all mentions as Array of objects
155157
* @param {Array} mentions the mentions list
156-
* @returns {Object[]}
158+
* @return {Object<string, object>}
157159
*/
158160
genMentionsData(mentions) {
159-
const list = Object.values(mentions).flat()
160-
return list.reduce((mentions, mention) => {
161-
mentions[mention.mentionId] = {
162-
// TODO: support groups
163-
icon: 'icon-user',
164-
id: mention.mentionId,
165-
label: mention.mentionDisplayName,
166-
source: 'users',
167-
primary: getCurrentUser().uid === mention.mentionId,
168-
}
169-
return mentions
170-
}, {})
161+
Object.values(mentions)
162+
.flat()
163+
.forEach(mention => {
164+
this.userData[mention.mentionId] = {
165+
// TODO: support groups
166+
icon: 'icon-user',
167+
id: mention.mentionId,
168+
label: mention.mentionDisplayName,
169+
source: 'users',
170+
primary: getCurrentUser().uid === mention.mentionId,
171+
}
172+
})
173+
return this.userData
171174
},
172175
173176
/**
@@ -230,7 +233,9 @@ export default {
230233
limit: loadState('comments', 'maxAutoCompleteResults'),
231234
},
232235
})
233-
return callback(results.data.ocs.data)
236+
// Save user data so it can be used by the editor to replace mentions
237+
results.data.ocs.data.forEach(user => { this.userData[user.id] = user })
238+
return callback(Object.values(this.userData))
234239
},
235240
236241
/**

0 commit comments

Comments
 (0)