feat: add preference to hide emojis in usernames (#1612)

This commit is contained in:
Tuur Martens 2023-02-04 18:02:05 +01:00 committed by GitHub
parent 0258894484
commit e92d1c6adf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 6 deletions

View file

@ -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)))
}