feat: add preference to hide emojis in usernames (#1612)
This commit is contained in:
parent
0258894484
commit
e92d1c6adf
8 changed files with 91 additions and 6 deletions
|
@ -10,6 +10,14 @@ import ContentCode from '~/components/content/ContentCode.vue'
|
|||
import ContentMentionGroup from '~/components/content/ContentMentionGroup.vue'
|
||||
import AccountHoverWrapper from '~/components/account/AccountHoverWrapper.vue'
|
||||
|
||||
function getTexualAstComponents(astChildren: Node[]): string {
|
||||
return astChildren
|
||||
.filter(({ type }) => type === TEXT_NODE)
|
||||
.map(({ value }) => value)
|
||||
.reduce((accumulator, current) => accumulator + current, '')
|
||||
.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw HTML to VNodes
|
||||
*/
|
||||
|
@ -17,7 +25,14 @@ export function contentToVNode(
|
|||
content: string,
|
||||
options?: ContentParseOptions,
|
||||
): VNode {
|
||||
const tree = parseMastodonHTML(content, options)
|
||||
let tree = parseMastodonHTML(content, options)
|
||||
|
||||
const textContents = getTexualAstComponents(tree.children)
|
||||
|
||||
// if the username only contains emojis, we should probably show the emojis anyway to avoid a blank name
|
||||
if (!options?.showEmojis && textContents.length === 0)
|
||||
tree = parseMastodonHTML(content, { ...options, showEmojis: true })
|
||||
|
||||
return h(Fragment, (tree.children as Node[] || []).map(n => treeToVNode(n)))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue