Bluesky app fork with some witchin' additions 馃挮 witchsky.app
bluesky fork client
119
fork

Configure Feed

Select the types of activity you want to include in your feed.

at a876aae44ea07494ebea9727350aa060b81f317b 149 lines 3.3 kB view raw
1import { 2 type $Typed, 3 AppBskyEmbedExternal, 4 AppBskyEmbedImages, 5 AppBskyEmbedRecord, 6 AppBskyEmbedRecordWithMedia, 7 AppBskyEmbedVideo, 8 AppBskyFeedDefs, 9 AppBskyGraphDefs, 10 AppBskyLabelerDefs, 11} from '@atproto/api' 12 13export type Embed = 14 | { 15 type: 'post' 16 view: $Typed<AppBskyEmbedRecord.ViewRecord> 17 } 18 | { 19 type: 'post_not_found' 20 view: $Typed<AppBskyEmbedRecord.ViewNotFound> 21 } 22 | { 23 type: 'post_blocked' 24 view: $Typed<AppBskyEmbedRecord.ViewBlocked> 25 } 26 | { 27 type: 'post_detached' 28 view: $Typed<AppBskyEmbedRecord.ViewDetached> 29 } 30 | { 31 type: 'feed' 32 view: $Typed<AppBskyFeedDefs.GeneratorView> 33 } 34 | { 35 type: 'list' 36 view: $Typed<AppBskyGraphDefs.ListView> 37 } 38 | { 39 type: 'labeler' 40 view: $Typed<AppBskyLabelerDefs.LabelerView> 41 } 42 | { 43 type: 'starter_pack' 44 view: $Typed<AppBskyGraphDefs.StarterPackViewBasic> 45 } 46 | { 47 type: 'images' 48 view: $Typed<AppBskyEmbedImages.View> 49 } 50 | { 51 type: 'link' 52 view: $Typed<AppBskyEmbedExternal.View> 53 } 54 | { 55 type: 'video' 56 view: $Typed<AppBskyEmbedVideo.View> 57 } 58 | { 59 type: 'post_with_media' 60 view: Embed 61 media: Embed 62 } 63 | { 64 type: 'unknown' 65 view: null 66 } 67 68export type EmbedType<T extends Embed['type']> = Extract<Embed, {type: T}> 69 70export function parseEmbedRecordView({record}: AppBskyEmbedRecord.View): Embed { 71 if (AppBskyEmbedRecord.isViewRecord(record)) { 72 return { 73 type: 'post', 74 view: record, 75 } 76 } else if (AppBskyEmbedRecord.isViewNotFound(record)) { 77 return { 78 type: 'post_not_found', 79 view: record, 80 } 81 } else if (AppBskyEmbedRecord.isViewBlocked(record)) { 82 return { 83 type: 'post_blocked', 84 view: record, 85 } 86 } else if (AppBskyEmbedRecord.isViewDetached(record)) { 87 return { 88 type: 'post_detached', 89 view: record, 90 } 91 } else if (AppBskyFeedDefs.isGeneratorView(record)) { 92 return { 93 type: 'feed', 94 view: record, 95 } 96 } else if (AppBskyGraphDefs.isListView(record)) { 97 return { 98 type: 'list', 99 view: record, 100 } 101 } else if (AppBskyLabelerDefs.isLabelerView(record)) { 102 return { 103 type: 'labeler', 104 view: record, 105 } 106 } else if (AppBskyGraphDefs.isStarterPackViewBasic(record)) { 107 return { 108 type: 'starter_pack', 109 view: record, 110 } 111 } else { 112 return { 113 type: 'unknown', 114 view: null, 115 } 116 } 117} 118 119export function parseEmbed(embed: AppBskyFeedDefs.PostView['embed']): Embed { 120 if (AppBskyEmbedImages.isView(embed)) { 121 return { 122 type: 'images', 123 view: embed, 124 } 125 } else if (AppBskyEmbedExternal.isView(embed)) { 126 return { 127 type: 'link', 128 view: embed, 129 } 130 } else if (AppBskyEmbedVideo.isView(embed)) { 131 return { 132 type: 'video', 133 view: embed, 134 } 135 } else if (AppBskyEmbedRecord.isView(embed)) { 136 return parseEmbedRecordView(embed) 137 } else if (AppBskyEmbedRecordWithMedia.isView(embed)) { 138 return { 139 type: 'post_with_media', 140 view: parseEmbedRecordView(embed.record), 141 media: parseEmbed(embed.media), 142 } 143 } else { 144 return { 145 type: 'unknown', 146 view: null, 147 } 148 } 149}