Skip to content

Commit 0f66806

Browse files
committed
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 <louis@chmn.me>
1 parent aad8b30 commit 0f66806

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

apps/comments/src/components/Comment.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
:auto-complete="autoComplete"
7070
:contenteditable="!loading"
7171
:value="localMessage"
72+
:user-data="userData"
7273
@update:value="updateLocalMessage"
7374
@submit="onSubmit" />
7475
<NcButton class="comment__submit"

apps/comments/src/views/Comments.vue

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<!-- Editor -->
2727
<Comment v-bind="editorData"
2828
:auto-complete="autoComplete"
29+
:user-data="userData"
2930
:editor="true"
3031
:ressource-id="ressourceId"
3132
class="comments__writer"
@@ -91,9 +92,9 @@ import RefreshIcon from 'vue-material-design-icons/Refresh'
9192
import MessageReplyTextIcon from 'vue-material-design-icons/MessageReplyText'
9293
import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline'
9394
94-
import Comment from '../components/Comment'
95-
import getComments, { DEFAULT_LIMIT } from '../services/GetComments'
96-
import cancelableRequest from '../utils/cancelableRequest'
95+
import Comment from '../components/Comment.vue'
96+
import getComments, { DEFAULT_LIMIT } from '../services/GetComments.js'
97+
import cancelableRequest from '../utils/cancelableRequest.js'
9798
9899
Vue.use(VTooltip)
99100
@@ -129,6 +130,7 @@ export default {
129130
},
130131
131132
Comment,
133+
userData: {},
132134
}
133135
},
134136
@@ -173,21 +175,22 @@ export default {
173175
* Make sure we have all mentions as Array of objects
174176
*
175177
* @param {Array} mentions the mentions list
176-
* @return {object[]}
178+
* @return {Object<string, object>}
177179
*/
178180
genMentionsData(mentions) {
179-
const list = Object.values(mentions).flat()
180-
return list.reduce((mentions, mention) => {
181-
mentions[mention.mentionId] = {
182-
// TODO: support groups
183-
icon: 'icon-user',
184-
id: mention.mentionId,
185-
label: mention.mentionDisplayName,
186-
source: 'users',
187-
primary: getCurrentUser().uid === mention.mentionId,
188-
}
189-
return mentions
190-
}, {})
181+
Object.values(mentions)
182+
.flat()
183+
.forEach(mention => {
184+
this.userData[mention.mentionId] = {
185+
// TODO: support groups
186+
icon: 'icon-user',
187+
id: mention.mentionId,
188+
label: mention.mentionDisplayName,
189+
source: 'users',
190+
primary: getCurrentUser().uid === mention.mentionId,
191+
}
192+
})
193+
return this.userData
191194
},
192195
193196
/**
@@ -251,7 +254,9 @@ export default {
251254
limit: loadState('comments', 'maxAutoCompleteResults'),
252255
},
253256
})
254-
return callback(results.data.ocs.data)
257+
// Save user data so it can be used by the editor to replace mentions
258+
results.data.ocs.data.forEach(user => { this.userData[user.id] = user })
259+
return callback(Object.values(this.userData))
255260
},
256261
257262
/**

dist/comments-comments-app.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/comments-comments-app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)