Skip to content

Commit

Permalink
✨ Add fallback for takendown accounts too
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Jan 10, 2025
1 parent 0c9c904 commit edcac2d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/actions/ModActionPanel/QuickAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ function Form(
<div className="max-w-xl">
<PreviewCard
subject={subject}
isAuthorDeactivated={!!record?.repo?.deactivatedAt}
isAuthorDeactivated={!!record?.repo.deactivatedAt}
isAuthorTakendown={
!!record?.repo.moderation.subjectStatus?.takendown
}
className="border-2 border-dashed border-gray-300"
>
{!isSubjectDid && record?.repo && (
Expand Down
8 changes: 7 additions & 1 deletion components/common/PreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export function PreviewCard({
children,
className,
isAuthorDeactivated,
isAuthorTakendown,
}: {
subject: string
isAuthorDeactivated?: boolean
isAuthorTakendown?: boolean
title?: string | ReactNode
children?: ReactNode
className?: string
Expand All @@ -43,7 +45,11 @@ export function PreviewCard({
<p className="text-sm font-medium text-gray-500 dark:text-gray-50 mb-3">
{displayTitle}
</p>
<RecordCard uri={subject} isAuthorDeactivated={isAuthorDeactivated} />
<RecordCard
uri={subject}
isAuthorDeactivated={isAuthorDeactivated}
isAuthorTakendown={isAuthorTakendown}
/>
{children}
</div>
)
Expand Down
12 changes: 11 additions & 1 deletion components/common/RecordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ export function RecordCard(props: {
uri: string
showLabels?: boolean
isAuthorDeactivated?: boolean
isAuthorTakendown?: boolean
}) {
const { uri, showLabels = false, isAuthorDeactivated } = props
const {
uri,
showLabels = false,
isAuthorDeactivated,
isAuthorTakendown,
} = props
const parsed = parseAtUri(uri)
if (!parsed) {
return null
Expand All @@ -32,6 +38,7 @@ export function RecordCard(props: {
<PostCard
uri={uri}
showLabels={showLabels}
isAuthorTakendown={isAuthorTakendown}
isAuthorDeactivated={isAuthorDeactivated}
/>
)
Expand Down Expand Up @@ -66,10 +73,12 @@ export function RecordCard(props: {
function PostCard({
uri,
showLabels,
isAuthorTakendown,
isAuthorDeactivated,
}: {
uri: string
showLabels?: boolean
isAuthorTakendown?: boolean
isAuthorDeactivated?: boolean
}) {
const labelerAgent = useLabelerAgent()
Expand Down Expand Up @@ -136,6 +145,7 @@ function PostCard({
dense
showLabels={showLabels}
item={{ post: data.thread.post }}
isAuthorTakendown={isAuthorTakendown}
isAuthorDeactivated={isAuthorDeactivated}
controls={['like', 'repost', 'workspace']}
/>
Expand Down
12 changes: 11 additions & 1 deletion components/common/posts/PostsFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ export function PostAsCard({
className = '',
showLabels = true,
isAuthorDeactivated,
isAuthorTakendown,
controls = [...PostControlOptions],
}: {
item: AppBskyFeedDefs.FeedViewPost
dense?: boolean
isAuthorDeactivated?: boolean
isAuthorTakendown?: boolean
controls?: PostControl[]
onReport?: (uri: string) => void
className?: string
Expand All @@ -103,7 +105,11 @@ export function PostAsCard({
<div className={`bg-white dark:bg-slate-800 ${className}`}>
<PostHeader item={item} dense={dense} />
<PostContent item={item} dense={dense} />
<PostEmbeds item={item} isAuthorDeactivated={isAuthorDeactivated} />
<PostEmbeds
item={item}
isAuthorTakendown={isAuthorTakendown}
isAuthorDeactivated={isAuthorDeactivated}
/>
{showLabels && <PostLabels item={item} dense={dense} />}
{!!controls?.length && (
<PostControls item={item} onReport={onReport} controls={controls} />
Expand Down Expand Up @@ -242,8 +248,10 @@ const getImageSizeClass = (imageCount: number) =>

export function PostEmbeds({
item,
isAuthorTakendown,
isAuthorDeactivated,
}: {
isAuthorTakendown?: boolean
isAuthorDeactivated?: boolean
item: AppBskyFeedDefs.FeedViewPost
}) {
Expand All @@ -265,10 +273,12 @@ export function PostEmbeds({
const captions = item.post.record?.['embed']?.['captions']
const sourceUrl = getVideoUrlWithFallback(embed.playlist, {
isAuthorDeactivated,
isAuthorTakendown,
})
const thumbnailUrl = embed.thumbnail
? getVideoUrlWithFallback(embed.thumbnail, {
isAuthorDeactivated,
isAuthorTakendown,
})
: undefined
return (
Expand Down
4 changes: 2 additions & 2 deletions components/common/video/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { FALLBACK_VIDEO_URL } from '@/lib/constants'

export const getVideoUrlWithFallback = (
originalUri: string,
opts?: { isAuthorDeactivated?: boolean },
opts?: { isAuthorDeactivated?: boolean; isAuthorTakendown?: boolean },
): string => {
const [find, replace] = FALLBACK_VIDEO_URL
if (!find || !replace) {
return originalUri
}

if (!opts?.isAuthorDeactivated) {
if (!opts?.isAuthorDeactivated && !opts?.isAuthorTakendown) {
return originalUri
}

Expand Down

0 comments on commit edcac2d

Please sign in to comment.