Compare commits

...

40 commits

Author SHA1 Message Date
Ayo
8fc435c60e Merge branch 'main' of github.com:elk-zone/elk into feature/remove-link-if-matches-preview-URL 2023-03-14 19:28:33 +01:00
Ayo
354914fc8d Merge branch 'main' into feature/remove-link-if-matches-preview-URL 2023-02-05 19:25:11 +01:00
Ayo Ayco
b8f492a255
Update components/status/StatusPreviewCardNormal.vue
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
2023-01-29 18:07:52 +01:00
Ayo
ba4f6e9e1a feat: remove url protocol 2023-01-29 10:00:38 +01:00
Ayo
f99d88a9e3 feat: logic to append preview url to provider name 2023-01-29 09:49:59 +01:00
Ayo
c36b900cdd fix: wrong type 2023-01-29 00:55:14 +01:00
Ayo
ed06ad8074 Merge branch 'feat/totally-hide-strict-filters' into feature/remove-link-if-matches-preview-URL 2023-01-29 00:45:18 +01:00
Ayo
299d33c7cb refactor: remove unused changes 2023-01-29 00:45:06 +01:00
Ayo
445891299f Merge branch 'main' into feature/remove-link-if-matches-preview-URL 2023-01-29 00:43:51 +01:00
Ayo
ed23c47ff2 fix: explicit any 2023-01-29 00:43:28 +01:00
Ayo
075a9d115b feat: clean shared link in the parsed html if conditions are met 2023-01-29 00:39:03 +01:00
Ayo
0b3d32e821 Merge branch 'main' into feat/totally-hide-strict-filters 2023-01-28 21:18:44 +01:00
Ayo
eac0590af9 Merge branch 'main' into feat/totally-hide-strict-filters 2023-01-23 20:28:17 +01:00
Ayo
aa6b603eca refactor: add return type 2023-01-21 23:44:19 +01:00
Ayo
979c97306b refactor: use single filter logic 2023-01-21 23:41:46 +01:00
Ayo
d3a567ddb8 Merge branch 'main' into feat/totally-hide-strict-filters 2023-01-21 23:19:44 +01:00
Ayo
084b5806bf refactor: bring back deleted code 2023-01-21 23:09:37 +01:00
Ayo
b64a4784ab fix: make context default to public 2023-01-21 22:58:31 +01:00
Ayo
28c011ac2e feat: filter notifications and conversations 2023-01-21 22:53:02 +01:00
Ayo
501d422931 style: filtered direct message spoiler 2023-01-21 21:49:29 +01:00
Ayo
255c950dff refactor: remove unused logic 2023-01-21 21:49:08 +01:00
Ayo
b2e43bb11c refactor: remove new line 2023-01-21 21:06:12 +01:00
Ayo
9bf4a6e21e refactor: remove unused import 2023-01-21 21:05:39 +01:00
Ayo
1044c8fcbc feat: reorder and filter account timeline 2023-01-21 21:03:41 +01:00
Ayo
73a6678cb3 feat: reorder and filter account timeline 2023-01-21 21:03:13 +01:00
Ayo
ff211ea77e feat: remove notifications filtering 2023-01-21 20:46:05 +01:00
Ayo
50e0832310 feat: filter the notification statuses 2023-01-21 20:35:52 +01:00
Ayo
a5c779aa2e refactor: removeFilteredItems function 2023-01-21 20:34:50 +01:00
Ayo
853c65c056 feat: reorder and filter public timeline 2023-01-21 20:34:23 +01:00
Ayo
c4de97636d refactor: reorder and filter home timeline 2023-01-21 20:07:21 +01:00
Ayo
6c114c6f14 refactor: don't pass down context 2023-01-21 20:00:48 +01:00
Ayo
6e5ef04bb6 Merge branch 'main' into feat/totally-hide-strict-filters 2023-01-21 10:02:28 +01:00
Ayo
e7f9e08192 Merge branch 'main' into feat/totally-hide-strict-filters 2023-01-19 17:35:13 +01:00
Ayo
9f85275791 refactor: check last children 2023-01-11 18:57:22 +01:00
Ayo
9bdfd71b0a feat: remove from content if matches preview URL 2023-01-11 17:44:40 +01:00
Ayo
a2a76651a5 feat: implement paginator context 2023-01-10 20:08:36 +01:00
Ayo
1cd6448bc5 refactor: test variables and mock IDs 2023-01-10 18:35:34 +01:00
Ayo
5de275b505 test: reorderedTimeline filter scenarios 2023-01-10 17:58:23 +01:00
Ayo
3f2227ef4c feat: filter stream items if filterAction is 'hide' 2023-01-10 17:57:58 +01:00
Ayo
1cac81ad57 feat: totally hide strict filters 2023-01-10 16:23:47 +01:00
5 changed files with 53 additions and 6 deletions

View file

@ -5,15 +5,18 @@ const {
status,
newer,
withAction = true,
cleanSharedLink,
} = defineProps<{
status: mastodon.v1.Status | mastodon.v1.StatusEdit
newer?: mastodon.v1.Status
withAction?: boolean
cleanSharedLink?: string | false
}>()
const { translation } = useTranslation(status, getLanguageCode())
const emojisObject = useEmojisFallback(() => status.emojis)
const vnode = $computed(() => {
if (!status.content)
return null
@ -24,7 +27,9 @@ const vnode = $computed(() => {
collapseMentionLink: !!('inReplyToId' in status && status.inReplyToId),
status: 'id' in status ? status : undefined,
inReplyToStatus: newer,
cleanSharedLink,
})
return vnode
})
</script>

View file

@ -21,6 +21,10 @@ const isFiltered = $computed(() => status.account.id !== currentUser.value?.acco
// check spoiler text or media attachment
// needed to handle accounts that mark all their posts as sensitive
const hasSpoilerOrSensitiveMedia = $computed(() => !!status.spoilerText || (status.sensitive && !!status.mediaAttachments.length))
const cleanSharedLink = !status.poll
&& !status.mediaAttachments.length
&& status.card?.url
</script>
<template>
@ -39,7 +43,7 @@ const hasSpoilerOrSensitiveMedia = $computed(() => !!status.spoilerText || (stat
<template v-else-if="filterPhrase" #spoiler>
<p>{{ `${$t('status.filter_hidden_phrase')}: ${filterPhrase}` }}</p>
</template>
<StatusBody v-if="!status.sensitive || status.spoilerText" :status="status" :newer="newer" :with-action="!isDetails" :class="isDetails ? 'text-xl' : ''" />
<StatusBody v-if="!status.sensitive || status.spoilerText" :clean-shared-link="cleanSharedLink" :status="status" :newer="newer" :with-action="!isDetails" :class="isDetails ? 'text-xl' : ''" />
<StatusTranslation :status="status" />
<StatusPoll v-if="status.poll" :status="status" />
<StatusMedia
@ -51,6 +55,7 @@ const hasSpoilerOrSensitiveMedia = $computed(() => !!status.spoilerText || (stat
v-if="status.card"
:card="status.card"
:small-picture-only="status.mediaAttachments?.length > 0"
:clean-shared-link="cleanSharedLink"
/>
<StatusCard
v-if="status.reblog"

View file

@ -7,15 +7,16 @@ const props = defineProps<{
smallPictureOnly?: boolean
/** When it is root card in the list, not appear as a child card */
root?: boolean
/** Defined when the preview card URL matches the last shared link href attribute */
cleanSharedLink?: string | false
}>()
const providerName = props.card.providerName
const providerName = $computed(() => props.card.providerName ? props.card.providerName : new URL(props.card.url).hostname)
const gitHubCards = $(usePreferences('experimentalGitHubCards'))
</script>
<template>
<LazyStatusPreviewGitHub v-if="gitHubCards && providerName === 'GitHub'" :card="card" />
<LazyStatusPreviewStackBlitz v-else-if="gitHubCards && providerName === 'StackBlitz'" :card="card" :small-picture-only="smallPictureOnly" :root="root" />
<StatusPreviewCardNormal v-else :card="card" :small-picture-only="smallPictureOnly" :root="root" />
<StatusPreviewCardNormal v-else :card="card" :clean-shared-link="cleanSharedLink" :small-picture-only="smallPictureOnly" :root="root" />
</template>

View file

@ -7,6 +7,8 @@ const props = defineProps<{
smallPictureOnly?: boolean
/** When it is root card in the list, not appear as a child card */
root?: boolean
/** Defined when the preview card URL matches the last shared link href attribute */
cleanSharedLink?: string | false
}>()
// mastodon's default max og image width
@ -19,7 +21,17 @@ const isSquare = $computed(() => (
|| Number(props.card.width || 0) < ogImageWidth
|| Number(props.card.height || 0) < ogImageWidth / 2
))
const providerName = $computed(() => props.card.providerName ? props.card.providerName : new URL(props.card.url).hostname)
const providerName = $computed(() => {
let finalProviderName = new URL(props.card.url).hostname
if (props.card.providerName) {
finalProviderName = props.card.providerName
if (props.cleanSharedLink && finalProviderName !== props.cleanSharedLink)
finalProviderName = `${props.card.providerName} · ${props.cleanSharedLink.replace(/^https?:\/\//, '')}`
}
return finalProviderName
})
// TODO: handle card.type: 'photo' | 'video' | 'rich';
const cardTypeIconMap: Record<mastodon.v1.PreviewCardType, string> = {

View file

@ -17,6 +17,7 @@ export interface ContentParseOptions {
collapseMentionLink?: boolean
status?: mastodon.v1.Status
inReplyToStatus?: mastodon.v1.Status
cleanSharedLink?: string | false // this is defined when conditions for cleaning the link are met
}
const sanitizerBasicClasses = filterClasses(/^(h-\S*|p-\S*|u-\S*|dt-\S*|e-\S*|mention|hashtag|ellipsis|invisible)$/u)
@ -86,6 +87,7 @@ export function parseMastodonHTML(
mentions,
status,
inReplyToStatus,
cleanSharedLink,
} = options
if (markdown) {
@ -135,7 +137,29 @@ export function parseMastodonHTML(
if (collapseMentionLink)
transforms.push(transformCollapseMentions(status, inReplyToStatus))
return transformSync(parse(html), transforms)
const node = parse(html) as Node
if (cleanSharedLink) {
// filter out invisible spans
const filteredNode = node.children.filter((child: Node) => !!child.children)
const matchedIndex = lastChildLinkMatchesPreviewUrl(filteredNode, cleanSharedLink)
if (matchedIndex)
filteredNode[filteredNode.length - 1].children.splice(matchedIndex, 1)
}
return transformSync(node, transforms)
}
/**
* Returns the index of the last link node if it matches the previewUrl
*/
export function lastChildLinkMatchesPreviewUrl(filteredNode: Node, previewUrl: string) {
const filteredLength = filteredNode.length
const length = filteredNode[filteredLength - 1].children.length
const lastChild = filteredNode[filteredLength - 1].children[length - 1]
const sharedHref = lastChild.attributes?.href
return sharedHref === previewUrl ? length - 1 : null
}
/**