Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK@next migration #7335

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
803dbc4
Bump SDK
estrattonbailey Jan 2, 2025
c2f9d7c
Use consistent type in profile query
estrattonbailey Jan 2, 2025
b1f1098
Omit from constraint for profile shadow
estrattonbailey Jan 2, 2025
f0c6224
Replace isRecord with isValidRecord in QuoteEmbed
estrattonbailey Jan 2, 2025
363e700
Omit type from constraint for old ProfileCard
estrattonbailey Jan 2, 2025
8f62efc
Omit type from constraint in profile queries where appropriate
estrattonbailey Jan 2, 2025
069609e
Use correct type for update profile mutation
estrattonbailey Jan 2, 2025
87ce8bd
Conslidate and fix check for isValidRecord in Post.tsx
estrattonbailey Jan 2, 2025
11227f0
Replace isRecord with isValidRecord in PostThreadItem
estrattonbailey Jan 2, 2025
48ef08a
Remove redundant cast in PostThreadFollowBtn
estrattonbailey Jan 2, 2025
30de00c
Ignore errors in DebugMod screen
estrattonbailey Jan 2, 2025
0334813
Use matching type in ProfileFollows screen
estrattonbailey Jan 2, 2025
164d534
Use matching type in ProfileFollowers screen
estrattonbailey Jan 2, 2025
2009ea3
Migrate to isValidRecord in PostFeedItem
estrattonbailey Jan 2, 2025
fdfdeb5
Use matching type if PostRepostedBy
estrattonbailey Jan 2, 2025
44e2460
Omit type from constraint in avatar props
estrattonbailey Jan 2, 2025
a1d4c1e
Use matching types in NotificationFeedItem
estrattonbailey Jan 2, 2025
1dbeff9
Todo
estrattonbailey Jan 2, 2025
1cf4f44
Use isValidRecord in NotfyFeedItem
estrattonbailey Jan 2, 2025
517543f
Improve MediaPreview types
estrattonbailey Jan 2, 2025
45171ab
Migrate another isValidRecord in NotificationFeedItem
estrattonbailey Jan 2, 2025
19cb6aa
Migrate to isValidView in queries/util
estrattonbailey Jan 2, 2025
df51b48
Migrate to isValidRecord in threadgate/util
estrattonbailey Jan 2, 2025
69b9b14
Fix types in threadgates
estrattonbailey Jan 2, 2025
0399e59
Fix up types in starter-packs queries
estrattonbailey Jan 2, 2025
bf08a3a
Todo
estrattonbailey Jan 2, 2025
288ecbd
Specify exact types in search-posts
estrattonbailey Jan 2, 2025
fa5d130
Use internal type util to align types
estrattonbailey Jan 2, 2025
13b89ea
Ditto last
estrattonbailey Jan 2, 2025
62e4751
Migrate postgate/index
estrattonbailey Jan 3, 2025
2cd8dd5
Specify exact types in post-thread
estrattonbailey Jan 3, 2025
220ff2f
Use correct type in post-quotes
estrattonbailey Jan 3, 2025
8a61a42
FIX potential bug in post-thread
estrattonbailey Jan 3, 2025
50fc2d1
Use correct type in post-feed
estrattonbailey Jan 3, 2025
75fd73b
Add correct type guards to notifications/feed
estrattonbailey Jan 3, 2025
dace2a2
Migrate a guard in notifications/util
estrattonbailey Jan 3, 2025
1f5830f
Migrate guard in Wizard/State
estrattonbailey Jan 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"icons:optimize": "svgo -f ./assets/icons"
},
"dependencies": {
"@atproto/api": "^0.13.21",
"@atproto/api": "0.14.0-next.1",
"@braintree/sanitize-url": "^6.0.2",
"@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet",
"@emoji-mart/react": "^1.1.1",
Expand Down
14 changes: 5 additions & 9 deletions src/components/MediaPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AppBskyEmbedImages,
AppBskyEmbedRecordWithMedia,
AppBskyEmbedVideo,
AppBskyFeedDefs,
} from '@atproto/api'
import {Trans} from '@lingui/macro'

Expand All @@ -22,17 +23,12 @@ export function Embed({
embed,
style,
}: {
embed?:
| AppBskyEmbedImages.View
| AppBskyEmbedRecordWithMedia.View
| AppBskyEmbedExternal.View
| AppBskyEmbedVideo.View
| {[k: string]: unknown}
embed?: AppBskyFeedDefs.PostView['embed']
style?: StyleProp<ViewStyle>
}) {
let media = AppBskyEmbedRecordWithMedia.isView(embed) ? embed.media : embed

if (AppBskyEmbedImages.isView(media)) {
if (AppBskyEmbedImages.isValidView(media)) {
return (
<Outer style={style}>
{media.images.map(image => (
Expand All @@ -44,7 +40,7 @@ export function Embed({
))}
</Outer>
)
} else if (AppBskyEmbedExternal.isView(media) && media.external.thumb) {
} else if (AppBskyEmbedExternal.isValidView(media) && media.external.thumb) {
let url: URL | undefined
try {
url = new URL(media.external.uri)
Expand All @@ -62,7 +58,7 @@ export function Embed({
)
}
}
} else if (AppBskyEmbedVideo.isView(media)) {
} else if (AppBskyEmbedVideo.isValidView(media)) {
return (
<Outer style={style}>
<VideoItem thumbnail={media.thumbnail} alt={media.alt} />
Expand Down
5 changes: 4 additions & 1 deletion src/screens/StarterPack/Wizard/State.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export function Provider({
const {currentAccount} = useSession()

const createInitialState = (): State => {
if (starterPack && AppBskyGraphStarterpack.isRecord(starterPack.record)) {
if (
starterPack &&
AppBskyGraphStarterpack.isValidRecord(starterPack.record)
) {
return {
canNext: true,
currentStep: 'Details',
Expand Down
2 changes: 1 addition & 1 deletion src/state/cache/profile-shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const shadows: WeakMap<
const emitter = new EventEmitter()

export function useProfileShadow<
TProfileView extends AppBskyActorDefs.ProfileView,
TProfileView extends Omit<AppBskyActorDefs.ProfileView, '$type'>,
>(profile: TProfileView): Shadow<TProfileView> {
const [shadow, setShadow] = useState(() => shadows.get(profile))
const [prevPost, setPrevPost] = useState(profile)
Expand Down
18 changes: 11 additions & 7 deletions src/state/queries/notifications/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ export function* findAllPostsInQueryData(
}
}

const quotedPost = getEmbeddedPost(item.subject?.embed)
if (quotedPost && didOrHandleUriMatches(atUri, quotedPost)) {
yield embedViewRecordToPostView(quotedPost!)
if (AppBskyFeedDefs.isPostView(item.subject)) {
const quotedPost = getEmbeddedPost(item.subject?.embed)
if (quotedPost && didOrHandleUriMatches(atUri, quotedPost)) {
yield embedViewRecordToPostView(quotedPost!)
}
}
}
}
Expand All @@ -307,7 +309,7 @@ export function* findAllPostsInQueryData(
export function* findAllProfilesInQueryData(
queryClient: QueryClient,
did: string,
): Generator<AppBskyActorDefs.ProfileView, void> {
): Generator<AppBskyActorDefs.ProfileViewBasic, void> {
const queryDatas = queryClient.getQueriesData<InfiniteData<FeedPage>>({
queryKey: [RQKEY_ROOT],
})
Expand All @@ -323,9 +325,11 @@ export function* findAllProfilesInQueryData(
) {
yield item.subject.author
}
const quotedPost = getEmbeddedPost(item.subject?.embed)
if (quotedPost?.author.did === did) {
yield quotedPost.author
if (AppBskyFeedDefs.isPostView(item.subject)) {
const quotedPost = getEmbeddedPost(item.subject?.embed)
if (quotedPost?.author.did === did) {
yield quotedPost.author
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/state/queries/notifications/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ function getSubjectUri(
return notif.uri
} else if (type === 'post-like' || type === 'repost') {
if (
AppBskyFeedRepost.isRecord(notif.record) ||
AppBskyFeedLike.isRecord(notif.record)
AppBskyFeedRepost.isValidRecord(notif.record) ||
AppBskyFeedLike.isValidRecord(notif.record)
) {
return typeof notif.record.subject?.uri === 'string'
? notif.record.subject?.uri
Expand Down
2 changes: 1 addition & 1 deletion src/state/queries/post-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export function* findAllPostsInQueryData(
export function* findAllProfilesInQueryData(
queryClient: QueryClient,
did: string,
): Generator<AppBskyActorDefs.ProfileView, undefined> {
): Generator<AppBskyActorDefs.ProfileViewBasic, undefined> {
const queryDatas = queryClient.getQueriesData<
InfiniteData<FeedPageUnselected>
>({
Expand Down
2 changes: 1 addition & 1 deletion src/state/queries/post-quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function usePostQuotesQuery(resolvedUri: string | undefined) {
export function* findAllProfilesInQueryData(
queryClient: QueryClient,
did: string,
): Generator<AppBskyActorDefs.ProfileView, void> {
): Generator<AppBskyActorDefs.ProfileViewBasic, void> {
const queryDatas = queryClient.getQueriesData<
InfiniteData<AppBskyFeedGetQuotes.OutputSchema>
>({
Expand Down
10 changes: 6 additions & 4 deletions src/state/queries/post-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ function responseToThreadNodes(
): ThreadNode {
if (
AppBskyFeedDefs.isThreadViewPost(node) &&
AppBskyFeedPost.isRecord(node.post.record) &&
AppBskyFeedPost.validateRecord(node.post.record).success
AppBskyFeedPost.isValidRecord(node.post.record)
) {
const post = node.post
// These should normally be present. They're missing only for
Expand Down Expand Up @@ -360,7 +359,7 @@ function responseToThreadNodes(
depth,
isHighlightedPost: depth === 0,
hasMore:
direction === 'down' && !node.replies?.length && !!node.replyCount,
direction === 'down' && !node.replies?.length && !!post.replyCount,
isSelfThread: false, // populated `annotateSelfThread`
hasMoreSelfThread: false, // populated in `annotateSelfThread`
},
Expand Down Expand Up @@ -493,7 +492,10 @@ export function* findAllPostsInQueryData(
export function* findAllProfilesInQueryData(
queryClient: QueryClient,
did: string,
): Generator<AppBskyActorDefs.ProfileView, void> {
): Generator<
AppBskyActorDefs.ProfileView | AppBskyActorDefs.ProfileViewBasic,
void
> {
const queryDatas = queryClient.getQueriesData<PostThreadQueryData>({
queryKey: [RQKEY_ROOT],
})
Expand Down
2 changes: 1 addition & 1 deletion src/state/queries/postgate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function getPostgateRecord({
}),
)

if (data.value && AppBskyFeedPostgate.isRecord(data.value)) {
if (data.value && AppBskyFeedPostgate.isValidRecord(data.value)) {
return data.value
} else {
return undefined
Expand Down
11 changes: 8 additions & 3 deletions src/state/queries/postgate/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AppBskyFeedPostgate,
AtUri,
} from '@atproto/api'
import {$Typed} from '@atproto/api/dist/client/util'

export const POSTGATE_COLLECTION = 'app.bsky.feed.postgate'

Expand Down Expand Up @@ -45,8 +46,12 @@ export function mergePostgateRecords(
})
}

export function createEmbedViewDetachedRecord({uri}: {uri: string}) {
const record: AppBskyEmbedRecord.ViewDetached = {
export function createEmbedViewDetachedRecord({
uri,
}: {
uri: string
}): $Typed<AppBskyEmbedRecord.View> {
const record: $Typed<AppBskyEmbedRecord.ViewDetached> = {
$type: 'app.bsky.embed.record#viewDetached',
uri,
detached: true,
Expand Down Expand Up @@ -95,7 +100,7 @@ export function createMaybeDetachedQuoteEmbed({

export function createEmbedViewRecordFromPost(
post: AppBskyFeedDefs.PostView,
): AppBskyEmbedRecord.ViewRecord {
): $Typed<AppBskyEmbedRecord.ViewRecord> {
return {
$type: 'app.bsky.embed.record#viewRecord',
uri: post.uri,
Expand Down
12 changes: 6 additions & 6 deletions src/state/queries/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function useProfileQuery({
placeholderData: () => {
if (!did) return

return queryClient.getQueryData<AppBskyActorDefs.ProfileViewBasic>(
return queryClient.getQueryData<AppBskyActorDefs.ProfileViewDetailed>(
profileBasicQueryKey(did),
)
},
Expand Down Expand Up @@ -113,7 +113,7 @@ export function usePrefetchProfileQuery() {
}

interface ProfileUpdateParams {
profile: AppBskyActorDefs.ProfileView
profile: AppBskyActorDefs.ProfileViewDetailed
updates:
| AppBskyActorProfile.Record
| ((existing: AppBskyActorProfile.Record) => AppBskyActorProfile.Record)
Expand Down Expand Up @@ -220,7 +220,7 @@ export function useProfileUpdateMutation() {
}

export function useProfileFollowMutationQueue(
profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>,
profile: Shadow<Omit<AppBskyActorDefs.ProfileViewDetailed, '$type'>>,
logContext: LogEvents['profile:follow']['logContext'] &
LogEvents['profile:follow']['logContext'],
) {
Expand Down Expand Up @@ -294,7 +294,7 @@ export function useProfileFollowMutationQueue(

function useProfileFollowMutation(
logContext: LogEvents['profile:follow']['logContext'],
profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>,
profile: Shadow<Omit<AppBskyActorDefs.ProfileViewDetailed, '$type'>>,
) {
const {currentAccount} = useSession()
const agent = useAgent()
Expand Down Expand Up @@ -334,7 +334,7 @@ function useProfileUnfollowMutation(
}

export function useProfileMuteMutationQueue(
profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>,
profile: Shadow<Omit<AppBskyActorDefs.ProfileViewDetailed, '$type'>>,
) {
const queryClient = useQueryClient()
const did = profile.did
Expand Down Expand Up @@ -409,7 +409,7 @@ function useProfileUnmuteMutation() {
}

export function useProfileBlockMutationQueue(
profile: Shadow<AppBskyActorDefs.ProfileViewBasic>,
profile: Shadow<Omit<AppBskyActorDefs.ProfileViewBasic, '$type'>>,
) {
const queryClient = useQueryClient()
const did = profile.did
Expand Down
5 changes: 4 additions & 1 deletion src/state/queries/search-posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ export function* findAllPostsInQueryData(
export function* findAllProfilesInQueryData(
queryClient: QueryClient,
did: string,
): Generator<AppBskyActorDefs.ProfileView, undefined> {
): Generator<
AppBskyActorDefs.ProfileView | AppBskyActorDefs.ProfileViewBasic,
undefined
> {
const queryDatas = queryClient.getQueriesData<
InfiniteData<AppBskyFeedSearchPosts.OutputSchema>
>({
Expand Down
1 change: 1 addition & 0 deletions src/state/queries/service-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function useServiceConfigQuery() {
const {data} = await agent.api.app.bsky.unspecced.getConfig()
return {
checkEmailConfirmed: Boolean(data.checkEmailConfirmed),
// @ts-expect-error TODO migrate once updated
topicsEnabled: Boolean(data.topicsEnabled),
}
} catch (e) {
Expand Down
7 changes: 5 additions & 2 deletions src/state/queries/starter-packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function useCreateStarterPackMutation({

return await agent.app.bsky.graph.starterpack.create(
{
repo: agent.session?.did,
repo: agent.session?.did!,
},
{
name,
Expand Down Expand Up @@ -366,7 +366,10 @@ export async function precacheStarterPack(
let starterPackView: AppBskyGraphDefs.StarterPackView | undefined
if (AppBskyGraphDefs.isStarterPackView(starterPack)) {
starterPackView = starterPack
} else if (AppBskyGraphDefs.isStarterPackViewBasic(starterPack)) {
} else if (
AppBskyGraphDefs.isStarterPackViewBasic(starterPack) &&
AppBskyGraphStarterpack.isValidRecord(starterPack.record)
) {
const listView: AppBskyGraphDefs.ListViewBasic = {
uri: starterPack.record.list,
// This will be populated once the data from server is fetched
Expand Down
2 changes: 1 addition & 1 deletion src/state/queries/threadgate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function getThreadgateRecord({
}),
)

if (data.value && AppBskyFeedThreadgate.isRecord(data.value)) {
if (data.value && AppBskyFeedThreadgate.isValidRecord(data.value)) {
return data.value
} else {
return null
Expand Down
2 changes: 1 addition & 1 deletion src/state/queries/threadgate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export type ThreadgateAllowUISetting =
| {type: 'nobody'}
| {type: 'mention'}
| {type: 'following'}
| {type: 'list'; list: unknown}
| {type: 'list'; list: string}
16 changes: 5 additions & 11 deletions src/state/queries/threadgate/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export function threadgateViewToAllowUISetting(
threadgateView: AppBskyFeedDefs.ThreadgateView | undefined,
): ThreadgateAllowUISetting[] {
const threadgate =
threadgateView &&
AppBskyFeedThreadgate.isRecord(threadgateView.record) &&
AppBskyFeedThreadgate.validateRecord(threadgateView.record).success
threadgateView && AppBskyFeedThreadgate.isValidRecord(threadgateView.record)
? threadgateView.record
: undefined
return threadgateRecordToAllowUISetting(threadgate)
Expand Down Expand Up @@ -39,11 +37,11 @@ export function threadgateRecordToAllowUISetting(
const settings: ThreadgateAllowUISetting[] = threadgate.allow
.map(allow => {
let setting: ThreadgateAllowUISetting | undefined
if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') {
if (AppBskyFeedThreadgate.isValidMentionRule(allow)) {
setting = {type: 'mention'}
} else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') {
} else if (AppBskyFeedThreadgate.isValidFollowingRule(allow)) {
setting = {type: 'following'}
} else if (allow.$type === 'app.bsky.feed.threadgate#listRule') {
} else if (AppBskyFeedThreadgate.isValidListRule(allow)) {
setting = {type: 'list', list: allow.list}
}
return setting
Expand All @@ -67,11 +65,7 @@ export function threadgateAllowUISettingToAllowRecordValue(
return undefined
}

let allow: (
| AppBskyFeedThreadgate.MentionRule
| AppBskyFeedThreadgate.FollowingRule
| AppBskyFeedThreadgate.ListRule
)[] = []
let allow: Exclude<AppBskyFeedThreadgate.Record['allow'], undefined> = []

if (!threadgate.find(v => v.type === 'nobody')) {
for (const rule of threadgate) {
Expand Down
4 changes: 2 additions & 2 deletions src/state/queries/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export function didOrHandleUriMatches(
export function getEmbeddedPost(
v: unknown,
): AppBskyEmbedRecord.ViewRecord | undefined {
if (AppBskyEmbedRecord.isView(v)) {
if (AppBskyEmbedRecord.isValidView(v)) {
if (
AppBskyEmbedRecord.isViewRecord(v.record) &&
AppBskyFeedPost.isRecord(v.record.value)
) {
return v.record
}
}
if (AppBskyEmbedRecordWithMedia.isView(v)) {
if (AppBskyEmbedRecordWithMedia.isValidView(v)) {
if (
AppBskyEmbedRecord.isViewRecord(v.record.record) &&
AppBskyFeedPost.isRecord(v.record.record.value)
Expand Down
Loading
Loading