mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import { 2 AppBskyActorDefs, 3 AppBskyFeedDefs, 4 AppBskyFeedPost, 5 AppBskyGraphDefs, 6} from '@atproto/api' 7 8import { 9 type ParsedReportSubject, 10 type ReportSubject, 11} from '#/components/moderation/ReportDialog/types' 12import * as bsky from '#/types/bsky' 13 14export function parseReportSubject( 15 subject: ReportSubject, 16): ParsedReportSubject | undefined { 17 if (!subject) return 18 19 if ('convoId' in subject) { 20 return { 21 type: 'chatMessage', 22 ...subject, 23 } 24 } 25 26 if ( 27 AppBskyActorDefs.isProfileViewBasic(subject) || 28 AppBskyActorDefs.isProfileView(subject) || 29 AppBskyActorDefs.isProfileViewDetailed(subject) 30 ) { 31 return { 32 type: 'account', 33 did: subject.did, 34 nsid: 'app.bsky.actor.profile', 35 } 36 } else if (AppBskyGraphDefs.isListView(subject)) { 37 return { 38 type: 'list', 39 uri: subject.uri, 40 cid: subject.cid, 41 nsid: 'app.bsky.graph.list', 42 } 43 } else if (AppBskyFeedDefs.isGeneratorView(subject)) { 44 return { 45 type: 'feed', 46 uri: subject.uri, 47 cid: subject.cid, 48 nsid: 'app.bsky.feed.generator', 49 } 50 } else if (AppBskyGraphDefs.isStarterPackView(subject)) { 51 return { 52 type: 'starterPack', 53 uri: subject.uri, 54 cid: subject.cid, 55 nsid: 'app.bsky.graph.starterPack', 56 } 57 } else if (AppBskyFeedDefs.isPostView(subject)) { 58 const record = subject.record 59 const embed = bsky.post.parseEmbed(subject.embed) 60 if ( 61 bsky.dangerousIsType<AppBskyFeedPost.Record>( 62 record, 63 AppBskyFeedPost.isRecord, 64 ) 65 ) { 66 return { 67 type: 'post', 68 uri: subject.uri, 69 cid: subject.cid, 70 nsid: 'app.bsky.feed.post', 71 attributes: { 72 reply: !!record.reply, 73 image: 74 embed.type === 'images' || 75 (embed.type === 'post_with_media' && embed.media.type === 'images'), 76 video: 77 embed.type === 'video' || 78 (embed.type === 'post_with_media' && embed.media.type === 'video'), 79 link: 80 embed.type === 'link' || 81 (embed.type === 'post_with_media' && embed.media.type === 'link'), 82 quote: 83 embed.type === 'post' || 84 (embed.type === 'post_with_media' && 85 (embed.view.type === 'post' || 86 embed.view.type === 'post_with_media')), 87 }, 88 } 89 } 90 } 91}