forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
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: 'convoMessage',
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 (AppBskyActorDefs.isStatusView(subject)) {
37 if (!subject.uri || !subject.cid) return
38 return {
39 type: 'status',
40 uri: subject.uri,
41 cid: subject.cid,
42 nsid: 'app.bsky.actor.status',
43 }
44 } else if (AppBskyGraphDefs.isListView(subject)) {
45 return {
46 type: 'list',
47 uri: subject.uri,
48 cid: subject.cid,
49 nsid: 'app.bsky.graph.list',
50 }
51 } else if (AppBskyFeedDefs.isGeneratorView(subject)) {
52 return {
53 type: 'feed',
54 uri: subject.uri,
55 cid: subject.cid,
56 nsid: 'app.bsky.feed.generator',
57 }
58 } else if (AppBskyGraphDefs.isStarterPackView(subject)) {
59 return {
60 type: 'starterPack',
61 uri: subject.uri,
62 cid: subject.cid,
63 nsid: 'app.bsky.graph.starterPack',
64 }
65 } else if (AppBskyFeedDefs.isPostView(subject)) {
66 const record = subject.record
67 const embed = bsky.post.parseEmbed(subject.embed)
68 if (
69 bsky.dangerousIsType<AppBskyFeedPost.Record>(
70 record,
71 AppBskyFeedPost.isRecord,
72 )
73 ) {
74 return {
75 type: 'post',
76 uri: subject.uri,
77 cid: subject.cid,
78 nsid: 'app.bsky.feed.post',
79 attributes: {
80 reply: !!record.reply,
81 image:
82 embed.type === 'images' ||
83 (embed.type === 'post_with_media' && embed.media.type === 'images'),
84 video:
85 embed.type === 'video' ||
86 (embed.type === 'post_with_media' && embed.media.type === 'video'),
87 link:
88 embed.type === 'link' ||
89 (embed.type === 'post_with_media' && embed.media.type === 'link'),
90 quote:
91 embed.type === 'post' ||
92 (embed.type === 'post_with_media' &&
93 (embed.view.type === 'post' ||
94 embed.view.type === 'post_with_media')),
95 },
96 }
97 }
98 }
99}