feat: adjust hide username emojis pref to only hide in timeline (#1631)

This commit is contained in:
Tuur Martens 2023-02-05 14:00:25 +01:00 committed by GitHub
parent 7dfe91bb9d
commit a1b2da3d5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 20 deletions

View file

@ -8,7 +8,7 @@ import { emojiRegEx, getEmojiAttributes } from '../config/emojis'
export interface ContentParseOptions {
emojis?: Record<string, mastodon.v1.CustomEmoji>
showEmojis?: boolean
hideEmojis?: boolean
mentions?: mastodon.v1.StatusMention[]
markdown?: boolean
replaceUnicodeEmoji?: boolean
@ -82,7 +82,7 @@ export function parseMastodonHTML(
replaceUnicodeEmoji = true,
convertMentionLink = false,
collapseMentionLink = false,
showEmojis = true,
hideEmojis = false,
mentions,
status,
inReplyToStatus,
@ -110,16 +110,16 @@ export function parseMastodonHTML(
...options.astTransforms || [],
]
if (showEmojis) {
if (hideEmojis) {
transforms.push(removeUnicodeEmoji)
transforms.push(removeCustomEmoji(options.emojis ?? {}))
}
else {
if (replaceUnicodeEmoji)
transforms.push(transformUnicodeEmoji)
transforms.push(replaceCustomEmoji(options.emojis ?? {}))
}
else {
transforms.push(removeUnicodeEmoji)
transforms.push(removeCustomEmoji(options.emojis ?? {}))
}
if (markdown)
transforms.push(transformMarkdown)

View file

@ -30,8 +30,8 @@ export function contentToVNode(
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 })
if (options?.hideEmojis && textContents.length === 0)
tree = parseMastodonHTML(content, { ...options, hideEmojis: false })
return h(Fragment, (tree.children as Node[] || []).map(n => treeToVNode(n)))
}