Pass nicknames instead of ids to user links from mod log

This commit is contained in:
Angelina Filippova 2020-12-02 23:42:44 +03:00
parent c2e80fb063
commit 7cac1c7159
2 changed files with 9 additions and 27 deletions

View file

@ -38,28 +38,16 @@ export default {
} }
}, },
computed: { computed: {
// logEntryMessage() {
// if (!this.actor.nickname) {
// return this.message
// } else {
// return this.message.split(this.actor.nickname).length > 2
// ? this.message.split(this.actor.nickname)[1].concat(this.actor.nickname)
// : this.message.split(this.actor.nickname)[1]
// }
// },
// logEntryMessageWithoutId() { // logEntryMessageWithoutId() {
// return this.logEntryMessage.split(`#${this.subject.id}`) // return this.logEntryMessage.split(`#${this.subject.id}`)
// }, // },
processedHtml() { processedHtml() {
const html = this.message.replace(/\@[\S]+/g, `<user-link :actor="actor"/>`) const html = [...this.message.matchAll(/\@(?<nickname>([\w-]+))/g)].map(res => res.groups.nickname)
.reduce((acc, nickname) => {
return acc.replace(`@${nickname}`, `<user-link actor="${nickname}"/>`)
}, this.message)
return { return {
template: '<div>' + html + '</div>', template: '<div>' + html + '</div>'
props: {
actor: {
type: null,
default: () => { return this.actor }
}
}
} }
} }
} }

View file

@ -1,10 +1,9 @@
<template> <template>
<router-link <router-link
v-if="propertyExists(actor, 'id')" :to="{ name: 'UsersShow', params: { id: actor }}"
:to="{ name: 'UsersShow', params: { id: actor.id }}"
class="router-link"> class="router-link">
<span v-if="propertyExists(actor, 'nickname')" style="font-weight: 600"> <span style="font-weight: 600;margin-right: -3px;">
@{{ actor.nickname }} @{{ actor }}
</span> </span>
</router-link> </router-link>
</template> </template>
@ -15,14 +14,9 @@ export default {
name: 'UserLink', name: 'UserLink',
props: { props: {
actor: { actor: {
type: Object, type: String,
required: true required: true
} }
},
methods: {
propertyExists(account, property) {
return account[property]
}
} }
} }
</script> </script>