Switch to vue-at for comment mentions
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
23
src/helpers/mentions.js
Normal file
23
src/helpers/mentions.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const rawToParsed = (text) => {
|
||||
text = text.replace(/<br>/g, '\n')
|
||||
text = text.replace(/ /g, ' ')
|
||||
|
||||
// Since we used innerHTML to get the content of the div.contenteditable
|
||||
// it is escaped. With this little trick from https://stackoverflow.com/a/7394787
|
||||
// We unescape the code again, so if you write `<strong>` we can display
|
||||
// it again instead of `<strong>`
|
||||
const temp = document.createElement('textarea')
|
||||
temp.innerHTML = text
|
||||
text = temp.value
|
||||
|
||||
// Although the text is fully trimmed, at the very least the last
|
||||
// "\n" occurrence should be always removed, as browsers add a
|
||||
// "<br>" element as soon as some rich text is written in a content
|
||||
// editable div (for example, if a new line is added the div content
|
||||
// will be "<br><br>").
|
||||
return text.trim()
|
||||
}
|
||||
|
||||
export {
|
||||
rawToParsed,
|
||||
}
|
||||
@@ -40,6 +40,11 @@ const parseXml = (xml) => {
|
||||
}
|
||||
|
||||
const commentToObject = (tag) => {
|
||||
let mentions = tag['d:prop']['oc:mentions']['oc:mention'] ?? []
|
||||
if (mentions && !Array.isArray(mentions)) {
|
||||
mentions = [mentions]
|
||||
}
|
||||
|
||||
return {
|
||||
cardId: tag['d:prop']['oc:objectId']['#text'],
|
||||
id: tag['d:prop']['oc:id']['#text'],
|
||||
@@ -47,6 +52,13 @@ const commentToObject = (tag) => {
|
||||
actorDisplayName: tag['d:prop']['oc:actorDisplayName']['#text'],
|
||||
creationDateTime: tag['d:prop']['oc:creationDateTime']['#text'],
|
||||
message: tag['d:prop']['oc:message']['#text'],
|
||||
mentions: mentions.map((mention) => {
|
||||
return {
|
||||
mentionType: mention['oc:mentionType']['#text'],
|
||||
mentionId: mention['oc:mentionId']['#text'],
|
||||
mentionDisplayName: mention['oc:mentionDisplayName']['#text'],
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user