flip the lib type imports and move the xrpc error helpers off the old client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
jest.unmock('multiformats/cid')
|
jest.unmock('multiformats/cid')
|
||||||
jest.unmock('multiformats/hashes/hasher')
|
jest.unmock('multiformats/hashes/hasher')
|
||||||
|
|
||||||
import {BlobRef} from '@atproto/api'
|
|
||||||
import {CID} from 'multiformats/cid'
|
import {CID} from 'multiformats/cid'
|
||||||
|
|
||||||
import {computeCid} from '#/lib/api/computeCid'
|
import {computeCid} from '#/lib/api/computeCid'
|
||||||
@@ -67,8 +66,8 @@ describe('computeCid', () => {
|
|||||||
* `{$type: 'blob', ref, mimeType, size}` with `ref` a parsed CID. The
|
* `{$type: 'blob', ref, mimeType, size}` with `ref` a parsed CID. The
|
||||||
* structural lex-blob guard passes it through `prepareForHashing`
|
* structural lex-blob guard passes it through `prepareForHashing`
|
||||||
* untouched and DAG-CBOR encodes its CID `ref` as a CID link. The golden
|
* untouched and DAG-CBOR encodes its CID `ref` as a CID link. The golden
|
||||||
* CID below is the byte-identical value the pre-migration `BlobRef` class
|
* CID below is the byte-identical value the pre-migration legacy blob
|
||||||
* instance produced via `.ipld()`.
|
* class instance produced via `.ipld()`.
|
||||||
*/
|
*/
|
||||||
const blob = {
|
const blob = {
|
||||||
$type: 'blob' as const,
|
$type: 'blob' as const,
|
||||||
@@ -81,18 +80,6 @@ describe('computeCid', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('case 2b: a legacy BlobRef instance hashes to the same CID', async () => {
|
|
||||||
/*
|
|
||||||
* The video pipeline still yields legacy `BlobRef` class instances, so
|
|
||||||
* `prepareForHashing` keeps its `instanceof` guard. Both branches must
|
|
||||||
* agree: this asserts the SAME golden CID as case 2.
|
|
||||||
*/
|
|
||||||
const blob = new BlobRef(CID.parse(BLOB_CID), 'image/jpeg', 12345)
|
|
||||||
expect(await computeCid(postWithImageBlob(blob))).toBe(
|
|
||||||
'bafyreiem7g6vja66nebr7he4fshfnlyndyldbvle2n265oixscmepjcbii',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('case 3: three-post thread chains reply StrongRef CIDs', async () => {
|
it('case 3: three-post thread chains reply StrongRef CIDs', async () => {
|
||||||
const did = 'did:plc:abc123'
|
const did = 'did:plc:abc123'
|
||||||
const base = new Date('2024-01-01T00:00:00.000Z')
|
const base = new Date('2024-01-01T00:00:00.000Z')
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {BlobRef} from '@atproto/api'
|
|
||||||
import {sha256} from 'js-sha256'
|
import {sha256} from 'js-sha256'
|
||||||
import {CID} from 'multiformats/cid'
|
import {CID} from 'multiformats/cid'
|
||||||
import * as Hasher from 'multiformats/hashes/hasher'
|
import * as Hasher from 'multiformats/hashes/hasher'
|
||||||
@@ -73,17 +72,6 @@ function prepareForHashing(v: any): any {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The video pipeline still reads its blob off the legacy agent
|
|
||||||
* (`app.bsky.video.getJobStatus` in composer `state/video`), which yields a
|
|
||||||
* `BlobRef` class instance. `ipld()` gives the same IPLD shape a lex blob
|
|
||||||
* already has, so both branches hash identically. Drop this guard once the
|
|
||||||
* video client is migrated.
|
|
||||||
*/
|
|
||||||
if (v instanceof BlobRef) {
|
|
||||||
return v.ipld()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk through arrays
|
// Walk through arrays
|
||||||
if (Array.isArray(v)) {
|
if (Array.isArray(v)) {
|
||||||
let pure = true
|
let pure = true
|
||||||
|
|||||||
+41
-45
@@ -1,17 +1,10 @@
|
|||||||
import {
|
import {app} from '#/lexicons'
|
||||||
type AppBskyActorDefs,
|
|
||||||
AppBskyEmbedRecord,
|
|
||||||
AppBskyEmbedRecordWithMedia,
|
|
||||||
AppBskyFeedDefs,
|
|
||||||
AppBskyFeedPost,
|
|
||||||
} from '@atproto/api'
|
|
||||||
|
|
||||||
import * as bsky from '#/types/bsky'
|
import * as bsky from '#/types/bsky'
|
||||||
import {isPostInLanguage} from '../../locale/helpers'
|
import {isPostInLanguage} from '../../locale/helpers'
|
||||||
import {FALLBACK_MARKER_POST} from './feed/home'
|
import {FALLBACK_MARKER_POST} from './feed/home'
|
||||||
import {type ReasonFeedSource} from './feed/types'
|
import {type ReasonFeedSource} from './feed/types'
|
||||||
|
|
||||||
type FeedViewPost = AppBskyFeedDefs.FeedViewPost
|
type FeedViewPost = app.bsky.feed.defs.FeedViewPost
|
||||||
|
|
||||||
export type FeedTunerFn = (
|
export type FeedTunerFn = (
|
||||||
tuner: FeedTuner,
|
tuner: FeedTuner,
|
||||||
@@ -20,18 +13,18 @@ export type FeedTunerFn = (
|
|||||||
) => FeedViewPostsSlice[]
|
) => FeedViewPostsSlice[]
|
||||||
|
|
||||||
type FeedSliceItem = {
|
type FeedSliceItem = {
|
||||||
post: AppBskyFeedDefs.PostView
|
post: app.bsky.feed.defs.PostView
|
||||||
record: AppBskyFeedPost.Record
|
record: app.bsky.feed.post.Main
|
||||||
parentAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
parentAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
isParentBlocked: boolean
|
isParentBlocked: boolean
|
||||||
isParentNotFound: boolean
|
isParentNotFound: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthorContext = {
|
type AuthorContext = {
|
||||||
author: AppBskyActorDefs.ProfileViewBasic
|
author: app.bsky.actor.defs.ProfileViewBasic
|
||||||
parentAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
parentAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
grandparentAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
grandparentAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
rootAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
rootAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FeedViewPostsSlice {
|
export class FeedViewPostsSlice {
|
||||||
@@ -53,7 +46,7 @@ export class FeedViewPostsSlice {
|
|||||||
this.isOrphan = false
|
this.isOrphan = false
|
||||||
this.isThreadMuted = post.viewer?.threadMuted ?? false
|
this.isThreadMuted = post.viewer?.threadMuted ?? false
|
||||||
this.feedPostUri = post.uri
|
this.feedPostUri = post.uri
|
||||||
if (AppBskyFeedDefs.isPostView(reply?.root)) {
|
if (bsky.isType(app.bsky.feed.defs.postView, reply?.root)) {
|
||||||
this.rootUri = reply.root.uri
|
this.rootUri = reply.root.uri
|
||||||
} else {
|
} else {
|
||||||
this.rootUri = post.uri
|
this.rootUri = post.uri
|
||||||
@@ -69,16 +62,19 @@ export class FeedViewPostsSlice {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!AppBskyFeedPost.isRecord(post.record) ||
|
!bsky.isType(app.bsky.feed.post, post.record) ||
|
||||||
!bsky.validate(post.record, AppBskyFeedPost.validateRecord)
|
!bsky.matches(app.bsky.feed.post, post.record)
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const parent = reply?.parent
|
const parent = reply?.parent
|
||||||
const isParentBlocked = AppBskyFeedDefs.isBlockedPost(parent)
|
const isParentBlocked = bsky.isType(app.bsky.feed.defs.blockedPost, parent)
|
||||||
const isParentNotFound = AppBskyFeedDefs.isNotFoundPost(parent)
|
const isParentNotFound = bsky.isType(
|
||||||
let parentAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
app.bsky.feed.defs.notFoundPost,
|
||||||
if (AppBskyFeedDefs.isPostView(parent)) {
|
parent,
|
||||||
|
)
|
||||||
|
let parentAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
|
if (bsky.isType(app.bsky.feed.defs.postView, parent)) {
|
||||||
parentAuthor = parent.author
|
parentAuthor = parent.author
|
||||||
}
|
}
|
||||||
this.items.push({
|
this.items.push({
|
||||||
@@ -100,18 +96,18 @@ export class FeedViewPostsSlice {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!AppBskyFeedDefs.isPostView(parent) ||
|
!bsky.isType(app.bsky.feed.defs.postView, parent) ||
|
||||||
!AppBskyFeedPost.isRecord(parent.record) ||
|
!bsky.isType(app.bsky.feed.post, parent.record) ||
|
||||||
!bsky.validate(parent.record, AppBskyFeedPost.validateRecord)
|
!bsky.matches(app.bsky.feed.post, parent.record)
|
||||||
) {
|
) {
|
||||||
this.isOrphan = true
|
this.isOrphan = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const root = reply.root
|
const root = reply.root
|
||||||
const rootIsView =
|
const rootIsView =
|
||||||
AppBskyFeedDefs.isPostView(root) ||
|
bsky.isType(app.bsky.feed.defs.postView, root) ||
|
||||||
AppBskyFeedDefs.isBlockedPost(root) ||
|
bsky.isType(app.bsky.feed.defs.blockedPost, root) ||
|
||||||
AppBskyFeedDefs.isNotFoundPost(root)
|
bsky.isType(app.bsky.feed.defs.notFoundPost, root)
|
||||||
/*
|
/*
|
||||||
* If the parent is also the root, we just so happen to have the data we
|
* If the parent is also the root, we just so happen to have the data we
|
||||||
* need to compute if the parent's parent (grandparent) is blocked. This
|
* need to compute if the parent's parent (grandparent) is blocked. This
|
||||||
@@ -124,10 +120,10 @@ export class FeedViewPostsSlice {
|
|||||||
: undefined
|
: undefined
|
||||||
const grandparentAuthor = reply.grandparentAuthor
|
const grandparentAuthor = reply.grandparentAuthor
|
||||||
const isGrandparentBlocked = Boolean(
|
const isGrandparentBlocked = Boolean(
|
||||||
grandparent && AppBskyFeedDefs.isBlockedPost(grandparent),
|
grandparent && bsky.isType(app.bsky.feed.defs.blockedPost, grandparent),
|
||||||
)
|
)
|
||||||
const isGrandparentNotFound = Boolean(
|
const isGrandparentNotFound = Boolean(
|
||||||
grandparent && AppBskyFeedDefs.isNotFoundPost(grandparent),
|
grandparent && bsky.isType(app.bsky.feed.defs.notFoundPost, grandparent),
|
||||||
)
|
)
|
||||||
this.items.unshift({
|
this.items.unshift({
|
||||||
post: parent,
|
post: parent,
|
||||||
@@ -142,9 +138,9 @@ export class FeedViewPostsSlice {
|
|||||||
// de-deduping
|
// de-deduping
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!AppBskyFeedDefs.isPostView(root) ||
|
!bsky.isType(app.bsky.feed.defs.postView, root) ||
|
||||||
!AppBskyFeedPost.isRecord(root.record) ||
|
!bsky.isType(app.bsky.feed.post, root.record) ||
|
||||||
!bsky.validate(root.record, AppBskyFeedPost.validateRecord)
|
!bsky.matches(app.bsky.feed.post, root.record)
|
||||||
) {
|
) {
|
||||||
this.isOrphan = true
|
this.isOrphan = true
|
||||||
return
|
return
|
||||||
@@ -167,14 +163,14 @@ export class FeedViewPostsSlice {
|
|||||||
get isQuotePost() {
|
get isQuotePost() {
|
||||||
const embed = this._feedPost.post.embed
|
const embed = this._feedPost.post.embed
|
||||||
return (
|
return (
|
||||||
AppBskyEmbedRecord.isView(embed) ||
|
bsky.isType(app.bsky.embed.record.view, embed) ||
|
||||||
AppBskyEmbedRecordWithMedia.isView(embed)
|
bsky.isType(app.bsky.embed.recordWithMedia.view, embed)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
get isReply() {
|
get isReply() {
|
||||||
return (
|
return (
|
||||||
AppBskyFeedPost.isRecord(this._feedPost.post.record) &&
|
bsky.isType(app.bsky.feed.post, this._feedPost.post.record) &&
|
||||||
!!this._feedPost.post.record.reply
|
!!this._feedPost.post.record.reply
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -195,7 +191,7 @@ export class FeedViewPostsSlice {
|
|||||||
|
|
||||||
get isRepost() {
|
get isRepost() {
|
||||||
const reason = this._feedPost.reason
|
const reason = this._feedPost.reason
|
||||||
return AppBskyFeedDefs.isReasonRepost(reason)
|
return bsky.isType(app.bsky.feed.defs.reasonRepost, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
get likeCount() {
|
get likeCount() {
|
||||||
@@ -208,18 +204,18 @@ export class FeedViewPostsSlice {
|
|||||||
|
|
||||||
getAuthors(): AuthorContext {
|
getAuthors(): AuthorContext {
|
||||||
const feedPost = this._feedPost
|
const feedPost = this._feedPost
|
||||||
let author: AppBskyActorDefs.ProfileViewBasic = feedPost.post.author
|
let author: app.bsky.actor.defs.ProfileViewBasic = feedPost.post.author
|
||||||
let parentAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
let parentAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
let grandparentAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
let grandparentAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
let rootAuthor: AppBskyActorDefs.ProfileViewBasic | undefined
|
let rootAuthor: app.bsky.actor.defs.ProfileViewBasic | undefined
|
||||||
if (feedPost.reply) {
|
if (feedPost.reply) {
|
||||||
if (AppBskyFeedDefs.isPostView(feedPost.reply.parent)) {
|
if (bsky.isType(app.bsky.feed.defs.postView, feedPost.reply.parent)) {
|
||||||
parentAuthor = feedPost.reply.parent.author
|
parentAuthor = feedPost.reply.parent.author
|
||||||
}
|
}
|
||||||
if (feedPost.reply.grandparentAuthor) {
|
if (feedPost.reply.grandparentAuthor) {
|
||||||
grandparentAuthor = feedPost.reply.grandparentAuthor
|
grandparentAuthor = feedPost.reply.grandparentAuthor
|
||||||
}
|
}
|
||||||
if (AppBskyFeedDefs.isPostView(feedPost.reply.root)) {
|
if (bsky.isType(app.bsky.feed.defs.postView, feedPost.reply.root)) {
|
||||||
rootAuthor = feedPost.reply.root.author
|
rootAuthor = feedPost.reply.root.author
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,7 +510,7 @@ function shouldDisplayReplyInFollowing(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isSelfOrFollowing(
|
function isSelfOrFollowing(
|
||||||
profile: AppBskyActorDefs.ProfileViewBasic,
|
profile: app.bsky.actor.defs.ProfileViewBasic,
|
||||||
userDid: string,
|
userDid: string,
|
||||||
) {
|
) {
|
||||||
return Boolean(profile.did === userDid || profile.viewer?.following)
|
return Boolean(profile.did === userDid || profile.viewer?.following)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
||||||
|
|
||||||
|
import * as bsky from '#/types/bsky'
|
||||||
import {app} from '#/lexicons'
|
import {app} from '#/lexicons'
|
||||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ export class AuthorFeedAPI implements FeedAPI {
|
|||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
const data = await this.client.call(app.bsky.feed.getAuthorFeed, {
|
const data = await this.client.call(app.bsky.feed.getAuthorFeed, {
|
||||||
...this.params,
|
...this.params,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
@@ -61,12 +61,15 @@ export class AuthorFeedAPI implements FeedAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_filter(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
_filter(feed: app.bsky.feed.defs.FeedViewPost[]) {
|
||||||
if (this.params.filter === 'posts_and_author_threads') {
|
if (this.params.filter === 'posts_and_author_threads') {
|
||||||
return feed.filter(post => {
|
return feed.filter(post => {
|
||||||
const isReply = post.reply
|
const isReply = post.reply
|
||||||
const isRepost = AppBskyFeedDefs.isReasonRepost(post.reason)
|
const isRepost = bsky.isType(
|
||||||
const isPin = AppBskyFeedDefs.isReasonPin(post.reason)
|
app.bsky.feed.defs.reasonRepost,
|
||||||
|
post.reason,
|
||||||
|
)
|
||||||
|
const isPin = bsky.isType(app.bsky.feed.defs.reasonPin, post.reason)
|
||||||
if (!isReply) return true
|
if (!isReply) return true
|
||||||
if (isRepost || isPin) return true
|
if (isRepost || isPin) return true
|
||||||
return isReply && isAuthorReplyChain(this.params.actor, post, feed)
|
return isReply && isAuthorReplyChain(this.params.actor, post, feed)
|
||||||
@@ -79,15 +82,15 @@ export class AuthorFeedAPI implements FeedAPI {
|
|||||||
|
|
||||||
function isAuthorReplyChain(
|
function isAuthorReplyChain(
|
||||||
actor: string,
|
actor: string,
|
||||||
post: AppBskyFeedDefs.FeedViewPost,
|
post: app.bsky.feed.defs.FeedViewPost,
|
||||||
posts: AppBskyFeedDefs.FeedViewPost[],
|
posts: app.bsky.feed.defs.FeedViewPost[],
|
||||||
): boolean {
|
): boolean {
|
||||||
// current post is by a different user (shouldn't happen)
|
// current post is by a different user (shouldn't happen)
|
||||||
if (post.post.author.did !== actor) return false
|
if (post.post.author.did !== actor) return false
|
||||||
|
|
||||||
const replyParent = post.reply?.parent
|
const replyParent = post.reply?.parent
|
||||||
|
|
||||||
if (AppBskyFeedDefs.isPostView(replyParent)) {
|
if (bsky.isType(app.bsky.feed.defs.postView, replyParent)) {
|
||||||
// reply parent is by a different user
|
// reply parent is by a different user
|
||||||
if (replyParent.author.did !== actor) return false
|
if (replyParent.author.did !== actor) return false
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {type AppBskyFeedDefs, jsonStringToLex} from '@atproto/api'
|
import {Client, lexParse, type XrpcRequestParams} from '@atproto/lex'
|
||||||
import {Client, type XrpcRequestParams} from '@atproto/lex'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getAppLanguageAsContentLanguage,
|
getAppLanguageAsContentLanguage,
|
||||||
@@ -30,7 +29,7 @@ export class CustomFeedAPI implements FeedAPI {
|
|||||||
this.userInterests = userInterests
|
this.userInterests = userInterests
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
const contentLangs = getContentLanguages().join(',')
|
const contentLangs = getContentLanguages().join(',')
|
||||||
const data = await this.client.call(
|
const data = await this.client.call(
|
||||||
app.bsky.feed.getFeed,
|
app.bsky.feed.getFeed,
|
||||||
@@ -140,7 +139,7 @@ async function loggedOutFetch({
|
|||||||
* is asserted here just as the old-world one was.
|
* is asserted here just as the old-world one was.
|
||||||
*/
|
*/
|
||||||
let data = res.ok
|
let data = res.ok
|
||||||
? (jsonStringToLex(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
? (lexParse(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
||||||
: null
|
: null
|
||||||
if (data?.feed?.length) {
|
if (data?.feed?.length) {
|
||||||
return data
|
return data
|
||||||
@@ -154,7 +153,7 @@ async function loggedOutFetch({
|
|||||||
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
|
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
|
||||||
)
|
)
|
||||||
data = res.ok
|
data = res.ok
|
||||||
? (jsonStringToLex(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
? (lexParse(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
||||||
: null
|
: null
|
||||||
if (data?.feed?.length) {
|
if (data?.feed?.length) {
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client} from '@atproto/lex'
|
import {type Client} from '@atproto/lex'
|
||||||
|
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {DEMO_FEED} from '#/lib/demo'
|
import {DEMO_FEED} from '#/lib/demo'
|
||||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export class DemoFeedAPI implements FeedAPI {
|
|||||||
this.client = client
|
this.client = client
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
return DEMO_FEED.feed[0]
|
return DEMO_FEED.feed[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client} from '@atproto/lex'
|
import {type Client} from '@atproto/lex'
|
||||||
|
|
||||||
import {app} from '#/lexicons'
|
import {app} from '#/lexicons'
|
||||||
@@ -11,7 +10,7 @@ export class FollowingFeedAPI implements FeedAPI {
|
|||||||
this.client = client
|
this.client = client
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
const data = await this.client.call(app.bsky.feed.getTimeline, {
|
const data = await this.client.call(app.bsky.feed.getTimeline, {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client} from '@atproto/lex'
|
import {type Client} from '@atproto/lex'
|
||||||
import {type AtUriString} from '@atproto/syntax'
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
|
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
||||||
import {CustomFeedAPI} from './custom'
|
import {CustomFeedAPI} from './custom'
|
||||||
import {FollowingFeedAPI} from './following'
|
import {FollowingFeedAPI} from './following'
|
||||||
@@ -15,7 +15,7 @@ import {type FeedAPI, type FeedAPIResponse} from './types'
|
|||||||
// we use this fallback marker post to drive this instead. see Feed.tsx
|
// we use this fallback marker post to drive this instead. see Feed.tsx
|
||||||
// for the usage.
|
// for the usage.
|
||||||
// -prf
|
// -prf
|
||||||
export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = {
|
export const FALLBACK_MARKER_POST: app.bsky.feed.defs.FeedViewPost = {
|
||||||
post: {
|
post: {
|
||||||
uri: 'fallback-marker-post',
|
uri: 'fallback-marker-post',
|
||||||
cid: 'fake',
|
cid: 'fake',
|
||||||
@@ -63,7 +63,7 @@ export class HomeFeedAPI implements FeedAPI {
|
|||||||
this.itemCursor = 0
|
this.itemCursor = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
if (this.usingDiscover) {
|
if (this.usingDiscover) {
|
||||||
return this.discover.peekLatest()
|
return this.discover.peekLatest()
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ export class HomeFeedAPI implements FeedAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let returnCursor
|
let returnCursor
|
||||||
let posts: AppBskyFeedDefs.FeedViewPost[] = []
|
let posts: app.bsky.feed.defs.FeedViewPost[] = []
|
||||||
|
|
||||||
if (!this.usingDiscover) {
|
if (!this.usingDiscover) {
|
||||||
const res = await this.following.fetch({cursor, limit})
|
const res = await this.following.fetch({cursor, limit})
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
||||||
|
|
||||||
import {app} from '#/lexicons'
|
import {app} from '#/lexicons'
|
||||||
@@ -23,7 +22,7 @@ export class LikesFeedAPI implements FeedAPI {
|
|||||||
this.params = feedParams
|
this.params = feedParams
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
const data = await this.client.call(app.bsky.feed.getActorLikes, {
|
const data = await this.client.call(app.bsky.feed.getActorLikes, {
|
||||||
...this.params,
|
...this.params,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
||||||
|
|
||||||
import {app} from '#/lexicons'
|
import {app} from '#/lexicons'
|
||||||
@@ -23,7 +22,7 @@ export class ListFeedAPI implements FeedAPI {
|
|||||||
this.params = feedParams
|
this.params = feedParams
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
const data = await this.client.call(app.bsky.feed.getListFeed, {
|
const data = await this.client.call(app.bsky.feed.getListFeed, {
|
||||||
...this.params,
|
...this.params,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client} from '@atproto/lex'
|
import {type Client} from '@atproto/lex'
|
||||||
import {type AtUriString} from '@atproto/syntax'
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
import shuffle from 'lodash.shuffle'
|
import shuffle from 'lodash.shuffle'
|
||||||
@@ -28,7 +27,7 @@ const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours
|
|||||||
*/
|
*/
|
||||||
type MergeFeedPage = {
|
type MergeFeedPage = {
|
||||||
cursor?: string
|
cursor?: string
|
||||||
feed: AppBskyFeedDefs.FeedViewPost[]
|
feed: app.bsky.feed.defs.FeedViewPost[]
|
||||||
} | null
|
} | null
|
||||||
|
|
||||||
export class MergeFeedAPI implements FeedAPI {
|
export class MergeFeedAPI implements FeedAPI {
|
||||||
@@ -89,7 +88,7 @@ export class MergeFeedAPI implements FeedAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
const data = await this.client.call(app.bsky.feed.getTimeline, {
|
const data = await this.client.call(app.bsky.feed.getTimeline, {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
@@ -136,7 +135,7 @@ export class MergeFeedAPI implements FeedAPI {
|
|||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
|
|
||||||
// assemble a response by sampling from feeds with content
|
// assemble a response by sampling from feeds with content
|
||||||
const posts: AppBskyFeedDefs.FeedViewPost[] = []
|
const posts: app.bsky.feed.defs.FeedViewPost[] = []
|
||||||
while (posts.length < limit) {
|
while (posts.length < limit) {
|
||||||
let slice = this.sampleItem()
|
let slice = this.sampleItem()
|
||||||
if (slice[0]) {
|
if (slice[0]) {
|
||||||
@@ -188,7 +187,7 @@ class MergeFeedSource {
|
|||||||
feedTuners: FeedTunerFn[]
|
feedTuners: FeedTunerFn[]
|
||||||
sourceInfo: ReasonFeedSource | undefined
|
sourceInfo: ReasonFeedSource | undefined
|
||||||
cursor: string | undefined = undefined
|
cursor: string | undefined = undefined
|
||||||
queue: AppBskyFeedDefs.FeedViewPost[] = []
|
queue: app.bsky.feed.defs.FeedViewPost[] = []
|
||||||
hasMore = true
|
hasMore = true
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
@@ -210,7 +209,7 @@ class MergeFeedSource {
|
|||||||
return this.hasMore && this.queue.length === 0
|
return this.hasMore && this.queue.length === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
take(n: number): AppBskyFeedDefs.FeedViewPost[] {
|
take(n: number): app.bsky.feed.defs.FeedViewPost[] {
|
||||||
return this.queue.splice(0, n)
|
return this.queue.splice(0, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +326,7 @@ class MergeFeedSource_Custom extends MergeFeedSource {
|
|||||||
// some custom feeds fail to enforce the pagination limit
|
// some custom feeds fail to enforce the pagination limit
|
||||||
// so we manually truncate here
|
// so we manually truncate here
|
||||||
// -prf
|
// -prf
|
||||||
let feed: AppBskyFeedDefs.FeedViewPost[] =
|
let feed: app.bsky.feed.defs.FeedViewPost[] =
|
||||||
limit && data.feed.length > limit
|
limit && data.feed.length > limit
|
||||||
? data.feed.slice(0, limit)
|
? data.feed.slice(0, limit)
|
||||||
: data.feed
|
: data.feed
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
@@ -10,7 +9,7 @@ type GetPostsParams = XrpcRequestParams<typeof app.bsky.feed.getPosts.main>
|
|||||||
export class PostListFeedAPI implements FeedAPI {
|
export class PostListFeedAPI implements FeedAPI {
|
||||||
client: Client
|
client: Client
|
||||||
params: GetPostsParams
|
params: GetPostsParams
|
||||||
peek: AppBskyFeedDefs.FeedViewPost | null = null
|
peek: app.bsky.feed.defs.FeedViewPost | null = null
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
client,
|
client,
|
||||||
@@ -30,7 +29,7 @@ export class PostListFeedAPI implements FeedAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||||
if (this.peek) return this.peek
|
if (this.peek) return this.peek
|
||||||
throw new Error('Has not fetched yet')
|
throw new Error('Has not fetched yet')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
import {app} from '#/lexicons'
|
||||||
|
|
||||||
export interface FeedAPIResponse {
|
export interface FeedAPIResponse {
|
||||||
cursor?: string
|
cursor?: string
|
||||||
feed: AppBskyFeedDefs.FeedViewPost[]
|
feed: app.bsky.feed.defs.FeedViewPost[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FeedAPI {
|
export interface FeedAPI {
|
||||||
peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost>
|
peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost>
|
||||||
fetch({
|
fetch({
|
||||||
cursor,
|
cursor,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/syntax'
|
||||||
|
|
||||||
import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants'
|
import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants'
|
||||||
import {type UsePreferencesQueryResponse} from '#/state/queries/preferences'
|
import {type UsePreferencesQueryResponse} from '#/state/queries/preferences'
|
||||||
import {IS_WEB} from '#/env'
|
import {IS_WEB} from '#/env'
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {ChatBskyGroupDefs} from '@atproto/api'
|
|
||||||
import {TID} from '@atproto/common-web'
|
import {TID} from '@atproto/common-web'
|
||||||
import {type $Typed, type Client} from '@atproto/lex'
|
import {type $Typed, type Client} from '@atproto/lex'
|
||||||
import {
|
import {
|
||||||
@@ -29,7 +28,7 @@ import {
|
|||||||
type PostDraft,
|
type PostDraft,
|
||||||
type ThreadDraft,
|
type ThreadDraft,
|
||||||
} from '#/view/com/composer/state/composer'
|
} from '#/view/com/composer/state/composer'
|
||||||
import {app, com} from '#/lexicons'
|
import {app, chat, com} from '#/lexicons'
|
||||||
import * as bsky from '#/types/bsky'
|
import * as bsky from '#/types/bsky'
|
||||||
import {createGIFDescription} from '../gif-alt-text'
|
import {createGIFDescription} from '../gif-alt-text'
|
||||||
import {computeCid} from './computeCid'
|
import {computeCid} from './computeCid'
|
||||||
@@ -483,7 +482,7 @@ async function resolveMedia(
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
resolvedLink.type === 'chat-invite' &&
|
resolvedLink.type === 'chat-invite' &&
|
||||||
ChatBskyGroupDefs.isJoinLinkPreviewView(resolvedLink.view)
|
bsky.isType(chat.bsky.group.defs.joinLinkPreviewView, resolvedLink.view)
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
$type: 'app.bsky.embed.external',
|
$type: 'app.bsky.embed.external',
|
||||||
|
|||||||
+9
-15
@@ -1,11 +1,5 @@
|
|||||||
import {
|
|
||||||
type AppBskyFeedDefs,
|
|
||||||
type AppBskyGraphDefs,
|
|
||||||
type ComAtprotoRepoStrongRef,
|
|
||||||
} from '@atproto/api'
|
|
||||||
import {AtUri} from '@atproto/api'
|
|
||||||
import {type Client} from '@atproto/lex'
|
import {type Client} from '@atproto/lex'
|
||||||
import {type AtUriString, type HandleString} from '@atproto/syntax'
|
import {AtUri, type AtUriString, type HandleString} from '@atproto/syntax'
|
||||||
|
|
||||||
import {IMAGE_SIZE_CONFIG_2K_1MB} from '#/lib/constants'
|
import {IMAGE_SIZE_CONFIG_2K_1MB} from '#/lib/constants'
|
||||||
import {getLinkMeta, type LinkMeta} from '#/lib/link-meta/link-meta'
|
import {getLinkMeta, type LinkMeta} from '#/lib/link-meta/link-meta'
|
||||||
@@ -49,30 +43,30 @@ type ResolvedExternalLink = {
|
|||||||
|
|
||||||
type ResolvedPostRecord = {
|
type ResolvedPostRecord = {
|
||||||
type: 'record'
|
type: 'record'
|
||||||
record: ComAtprotoRepoStrongRef.Main
|
record: com.atproto.repo.strongRef.Main
|
||||||
kind: 'post'
|
kind: 'post'
|
||||||
view: AppBskyFeedDefs.PostView
|
view: app.bsky.feed.defs.PostView
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedFeedRecord = {
|
type ResolvedFeedRecord = {
|
||||||
type: 'record'
|
type: 'record'
|
||||||
record: ComAtprotoRepoStrongRef.Main
|
record: com.atproto.repo.strongRef.Main
|
||||||
kind: 'feed'
|
kind: 'feed'
|
||||||
view: AppBskyFeedDefs.GeneratorView
|
view: app.bsky.feed.defs.GeneratorView
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedListRecord = {
|
type ResolvedListRecord = {
|
||||||
type: 'record'
|
type: 'record'
|
||||||
record: ComAtprotoRepoStrongRef.Main
|
record: com.atproto.repo.strongRef.Main
|
||||||
kind: 'list'
|
kind: 'list'
|
||||||
view: AppBskyGraphDefs.ListView
|
view: app.bsky.graph.defs.ListView
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedStarterPackRecord = {
|
type ResolvedStarterPackRecord = {
|
||||||
type: 'record'
|
type: 'record'
|
||||||
record: ComAtprotoRepoStrongRef.Main
|
record: com.atproto.repo.strongRef.Main
|
||||||
kind: 'starter-pack'
|
kind: 'starter-pack'
|
||||||
view: AppBskyGraphDefs.StarterPackView
|
view: app.bsky.graph.defs.StarterPackView
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedChatInvite = {
|
type ResolvedChatInvite = {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {type Insets, Platform} from 'react-native'
|
import {type Insets, Platform} from 'react-native'
|
||||||
import {type AppBskyActorDefs} from '@atproto/api'
|
|
||||||
import {type Service} from '@atproto/lex'
|
import {type Service} from '@atproto/lex'
|
||||||
import {api} from '@bsky.app/sdk'
|
import {api} from '@bsky.app/sdk'
|
||||||
|
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {BLUESKY_PROXY_DID, CHAT_PROXY_DID, IS_DEV} from '#/env'
|
import {BLUESKY_PROXY_DID, CHAT_PROXY_DID, IS_DEV} from '#/env'
|
||||||
|
|
||||||
export const LOCAL_DEV_SERVICE =
|
export const LOCAL_DEV_SERVICE =
|
||||||
@@ -174,7 +174,7 @@ export const VIDEO_SAVED_FEED = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const RECOMMENDED_SAVED_FEEDS: Pick<
|
export const RECOMMENDED_SAVED_FEEDS: Pick<
|
||||||
AppBskyActorDefs.SavedFeed,
|
app.bsky.actor.defs.SavedFeed,
|
||||||
'type' | 'value' | 'pinned'
|
'type' | 'value' | 'pinned'
|
||||||
>[] = [DISCOVER_SAVED_FEED, TIMELINE_SAVED_FEED]
|
>[] = [DISCOVER_SAVED_FEED, TIMELINE_SAVED_FEED]
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import {type AppBskyFeedGetFeed} from '@atproto/api'
|
|
||||||
import {subDays, subMinutes} from 'date-fns'
|
import {subDays, subMinutes} from 'date-fns'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
|
|
||||||
const DID = `did:plc:z72i7hdynmk6r22z27h6tvur`
|
const DID = `did:plc:z72i7hdynmk6r22z27h6tvur`
|
||||||
const NOW = new Date()
|
const NOW = new Date()
|
||||||
@@ -197,6 +197,6 @@ export const DEMO_FEED = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
} satisfies AppBskyFeedGetFeed.OutputSchema
|
} satisfies app.bsky.feed.getFeed.$OutputBody
|
||||||
|
|
||||||
export const BOTTOM_BAR_AVI = 'https://bsky.social/about/adi/user_avi.jpg'
|
export const BOTTOM_BAR_AVI = 'https://bsky.social/about/adi/user_avi.jpg'
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import {useEffect} from 'react'
|
import {useEffect} from 'react'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
import {AtUri} from '@atproto/api'
|
|
||||||
import {useLingui} from '@lingui/react/macro'
|
import {useLingui} from '@lingui/react/macro'
|
||||||
import {CommonActions, useNavigation} from '@react-navigation/native'
|
import {CommonActions, useNavigation} from '@react-navigation/native'
|
||||||
import {useQueryClient} from '@tanstack/react-query'
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {AtUri} from '@atproto/syntax'
|
||||||
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
|
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
|
||||||
import {logger as notyLogger} from '#/lib/notifications/util'
|
import {logger as notyLogger} from '#/lib/notifications/util'
|
||||||
import {type NavigationProp} from '#/lib/routes/types'
|
import {type NavigationProp} from '#/lib/routes/types'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {useCallback, useRef} from 'react'
|
import {useCallback, useRef} from 'react'
|
||||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
|
||||||
|
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {type Metrics, useAnalytics} from '#/analytics'
|
import {type Metrics, useAnalytics} from '#/analytics'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +17,7 @@ export function usePostViewTracking(
|
|||||||
const seenUrisRef = useRef(new Set<string>())
|
const seenUrisRef = useRef(new Set<string>())
|
||||||
|
|
||||||
const trackPostView = useCallback(
|
const trackPostView = useCallback(
|
||||||
(post: AppBskyFeedDefs.PostView) => {
|
(post: app.bsky.feed.defs.PostView) => {
|
||||||
if (seenUrisRef.current.has(post.uri)) return
|
if (seenUrisRef.current.has(post.uri)) return
|
||||||
seenUrisRef.current.add(post.uri)
|
seenUrisRef.current.add(post.uri)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {type AppBskyEmbedExternal} from '@atproto/api'
|
import {app} from '#/lexicons'
|
||||||
|
|
||||||
import {LINK_META_PROXY} from '#/lib/constants'
|
import {LINK_META_PROXY} from '#/lib/constants'
|
||||||
import {getGiphyMetaUri} from '#/lib/strings/embed-player'
|
import {getGiphyMetaUri} from '#/lib/strings/embed-player'
|
||||||
import {parseStarterPackUri} from '#/lib/strings/starter-pack'
|
import {parseStarterPackUri} from '#/lib/strings/starter-pack'
|
||||||
@@ -26,8 +25,8 @@ export interface LinkMeta {
|
|||||||
* The AT-URI of the Atmosphere record representing this external content, if
|
* The AT-URI of the Atmosphere record representing this external content, if
|
||||||
* it exists. Example: a site.standard.document record.
|
* it exists. Example: a site.standard.document record.
|
||||||
*/
|
*/
|
||||||
associatedRefs?: AppBskyEmbedExternal.External['associatedRefs']
|
associatedRefs?: app.bsky.embed.external.External['associatedRefs']
|
||||||
view?: AppBskyEmbedExternal.View
|
view?: app.bsky.embed.external.View
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLinkMeta(
|
export async function getLinkMeta(
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {useMemo} from 'react'
|
import {useMemo} from 'react'
|
||||||
import {type ComAtprotoLabelDefs} from '@atproto/api'
|
|
||||||
import {Client} from '@atproto/lex'
|
import {Client} from '@atproto/lex'
|
||||||
import {type DidString} from '@atproto/syntax'
|
import {type DidString} from '@atproto/syntax'
|
||||||
import {
|
import {
|
||||||
@@ -13,7 +12,7 @@ import {
|
|||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
import {type AppModerationCause} from '#/components/Pills'
|
import {type AppModerationCause} from '#/components/Pills'
|
||||||
import {type app} from '#/lexicons'
|
import {type app, com} from '#/lexicons'
|
||||||
|
|
||||||
export const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn'] as const
|
export const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn'] as const
|
||||||
export const OTHER_SELF_LABELS = ['graphic-media'] as const
|
export const OTHER_SELF_LABELS = ['graphic-media'] as const
|
||||||
@@ -54,7 +53,7 @@ export function moduiContainsHideableOffense(modui: ModerationUI): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function labelIsHideableOffense(
|
export function labelIsHideableOffense(
|
||||||
label: ComAtprotoLabelDefs.Label,
|
label: com.atproto.label.defs.Label,
|
||||||
): boolean {
|
): boolean {
|
||||||
return ['!hide', '!takedown'].includes(label.val)
|
return ['!hide', '!takedown'].includes(label.val)
|
||||||
}
|
}
|
||||||
@@ -64,9 +63,9 @@ export function labelIsHideableOffense(
|
|||||||
* with `!`) and the user's own "bot" self-label.
|
* with `!`) and the user's own "bot" self-label.
|
||||||
*/
|
*/
|
||||||
export function filterUserFacingLabels(
|
export function filterUserFacingLabels(
|
||||||
labels: ComAtprotoLabelDefs.Label[],
|
labels: com.atproto.label.defs.Label[],
|
||||||
currentAccountDid: string | undefined,
|
currentAccountDid: string | undefined,
|
||||||
): ComAtprotoLabelDefs.Label[] {
|
): com.atproto.label.defs.Label[] {
|
||||||
return labels.filter(
|
return labels.filter(
|
||||||
label =>
|
label =>
|
||||||
!label.val.startsWith('!') &&
|
!label.val.startsWith('!') &&
|
||||||
@@ -135,7 +134,11 @@ export type Subject =
|
|||||||
did: string
|
did: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useLabelSubject({label}: {label: ComAtprotoLabelDefs.Label}): {
|
export function useLabelSubject({
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
label: com.atproto.label.defs.Label
|
||||||
|
}): {
|
||||||
subject: Subject
|
subject: Subject
|
||||||
} {
|
} {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
import {
|
|
||||||
type AppBskyActorDefs,
|
|
||||||
type AppBskyFeedDefs,
|
|
||||||
type AppBskyGraphDefs,
|
|
||||||
type AppBskyNotificationListNotifications,
|
|
||||||
type AppBskyRichtextFacet,
|
|
||||||
type ChatBskyActorDefs,
|
|
||||||
} from '@atproto/api'
|
|
||||||
import {
|
import {
|
||||||
hasMutedWord as sdkHasMutedWord,
|
hasMutedWord as sdkHasMutedWord,
|
||||||
moderateFeedGenerator as sdkModerateFeedGenerator,
|
moderateFeedGenerator as sdkModerateFeedGenerator,
|
||||||
@@ -18,7 +10,7 @@ import {
|
|||||||
type ModerationOpts,
|
type ModerationOpts,
|
||||||
} from '@bsky.app/sdk/moderation'
|
} from '@bsky.app/sdk/moderation'
|
||||||
|
|
||||||
import {type app, type chat} from '#/lexicons'
|
import {app, chat} from '#/lexicons'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TRANSITIONAL. The moderation implementation now comes from
|
* TRANSITIONAL. The moderation implementation now comes from
|
||||||
@@ -43,26 +35,26 @@ type AnyProfileSubject =
|
|||||||
| app.bsky.actor.defs.ProfileView
|
| app.bsky.actor.defs.ProfileView
|
||||||
| app.bsky.actor.defs.ProfileViewDetailed
|
| app.bsky.actor.defs.ProfileViewDetailed
|
||||||
| chat.bsky.actor.defs.ProfileViewBasic
|
| chat.bsky.actor.defs.ProfileViewBasic
|
||||||
| AppBskyActorDefs.ProfileViewBasic
|
| app.bsky.actor.defs.ProfileViewBasic
|
||||||
| AppBskyActorDefs.ProfileView
|
| app.bsky.actor.defs.ProfileView
|
||||||
| AppBskyActorDefs.ProfileViewDetailed
|
| app.bsky.actor.defs.ProfileViewDetailed
|
||||||
| ChatBskyActorDefs.ProfileViewBasic
|
| chat.bsky.actor.defs.ProfileViewBasic
|
||||||
|
|
||||||
type AnyPostSubject = app.bsky.feed.defs.PostView | AppBskyFeedDefs.PostView
|
type AnyPostSubject = app.bsky.feed.defs.PostView | app.bsky.feed.defs.PostView
|
||||||
|
|
||||||
type AnyUserListSubject =
|
type AnyUserListSubject =
|
||||||
| app.bsky.graph.defs.ListViewBasic
|
| app.bsky.graph.defs.ListViewBasic
|
||||||
| app.bsky.graph.defs.ListView
|
| app.bsky.graph.defs.ListView
|
||||||
| AppBskyGraphDefs.ListViewBasic
|
| app.bsky.graph.defs.ListViewBasic
|
||||||
| AppBskyGraphDefs.ListView
|
| app.bsky.graph.defs.ListView
|
||||||
|
|
||||||
type AnyFeedGeneratorSubject =
|
type AnyFeedGeneratorSubject =
|
||||||
| app.bsky.feed.defs.GeneratorView
|
| app.bsky.feed.defs.GeneratorView
|
||||||
| AppBskyFeedDefs.GeneratorView
|
| app.bsky.feed.defs.GeneratorView
|
||||||
|
|
||||||
type AnyNotificationSubject =
|
type AnyNotificationSubject =
|
||||||
| app.bsky.notification.listNotifications.Notification
|
| app.bsky.notification.listNotifications.Notification
|
||||||
| AppBskyNotificationListNotifications.Notification
|
| app.bsky.notification.listNotifications.Notification
|
||||||
|
|
||||||
export function moderateProfile(
|
export function moderateProfile(
|
||||||
subject: AnyProfileSubject,
|
subject: AnyProfileSubject,
|
||||||
@@ -120,7 +112,7 @@ export function moderateNotification(
|
|||||||
export function hasMutedWord(params: {
|
export function hasMutedWord(params: {
|
||||||
mutedWords: app.bsky.actor.defs.MutedWord[]
|
mutedWords: app.bsky.actor.defs.MutedWord[]
|
||||||
text: string
|
text: string
|
||||||
facets?: app.bsky.richtext.facet.Main[] | AppBskyRichtextFacet.Main[]
|
facets?: app.bsky.richtext.facet.Main[] | app.bsky.richtext.facet.Main[]
|
||||||
outlineTags?: string[]
|
outlineTags?: string[]
|
||||||
languages?: string[]
|
languages?: string[]
|
||||||
actor?: AnyProfileSubject
|
actor?: AnyProfileSubject
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type ComAtprotoLabelDefs} from '@atproto/api'
|
|
||||||
import {
|
import {
|
||||||
type InterpretedLabelValueDefinition,
|
type InterpretedLabelValueDefinition,
|
||||||
interpretLabelValueDefinition,
|
interpretLabelValueDefinition,
|
||||||
@@ -12,16 +11,16 @@ import {
|
|||||||
useGlobalLabelStrings,
|
useGlobalLabelStrings,
|
||||||
} from '#/lib/moderation/useGlobalLabelStrings'
|
} from '#/lib/moderation/useGlobalLabelStrings'
|
||||||
import {useLabelDefinitions} from '#/state/preferences'
|
import {useLabelDefinitions} from '#/state/preferences'
|
||||||
import {type app} from '#/lexicons'
|
import {type app, com} from '#/lexicons'
|
||||||
|
|
||||||
export interface LabelInfo {
|
export interface LabelInfo {
|
||||||
label: ComAtprotoLabelDefs.Label
|
label: com.atproto.label.defs.Label
|
||||||
def: InterpretedLabelValueDefinition
|
def: InterpretedLabelValueDefinition
|
||||||
strings: ComAtprotoLabelDefs.LabelValueDefinitionStrings
|
strings: com.atproto.label.defs.LabelValueDefinitionStrings
|
||||||
labeler: app.bsky.labeler.defs.LabelerViewDetailed | undefined
|
labeler: app.bsky.labeler.defs.LabelerViewDetailed | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useLabelInfo(label: ComAtprotoLabelDefs.Label): LabelInfo {
|
export function useLabelInfo(label: com.atproto.label.defs.Label): LabelInfo {
|
||||||
const {i18n} = useLingui()
|
const {i18n} = useLingui()
|
||||||
const {labelDefs, labelers} = useLabelDefinitions()
|
const {labelDefs, labelers} = useLabelDefinitions()
|
||||||
const globalLabelStrings = useGlobalLabelStrings()
|
const globalLabelStrings = useGlobalLabelStrings()
|
||||||
@@ -36,7 +35,7 @@ export function useLabelInfo(label: ComAtprotoLabelDefs.Label): LabelInfo {
|
|||||||
|
|
||||||
export function getDefinition(
|
export function getDefinition(
|
||||||
labelDefs: Record<string, InterpretedLabelValueDefinition[]>,
|
labelDefs: Record<string, InterpretedLabelValueDefinition[]>,
|
||||||
label: ComAtprotoLabelDefs.Label,
|
label: com.atproto.label.defs.Label,
|
||||||
): InterpretedLabelValueDefinition {
|
): InterpretedLabelValueDefinition {
|
||||||
// check local definitions
|
// check local definitions
|
||||||
const customDef =
|
const customDef =
|
||||||
@@ -71,13 +70,13 @@ export function getLabelStrings(
|
|||||||
locale: string,
|
locale: string,
|
||||||
globalLabelStrings: GlobalLabelStrings,
|
globalLabelStrings: GlobalLabelStrings,
|
||||||
def: InterpretedLabelValueDefinition,
|
def: InterpretedLabelValueDefinition,
|
||||||
): ComAtprotoLabelDefs.LabelValueDefinitionStrings {
|
): com.atproto.label.defs.LabelValueDefinitionStrings {
|
||||||
if (!def.definedBy) {
|
if (!def.definedBy) {
|
||||||
// global definition, look up strings
|
// global definition, look up strings
|
||||||
if (def.identifier in globalLabelStrings) {
|
if (def.identifier in globalLabelStrings) {
|
||||||
return globalLabelStrings[
|
return globalLabelStrings[
|
||||||
def.identifier
|
def.identifier
|
||||||
] as ComAtprotoLabelDefs.LabelValueDefinitionStrings
|
] as com.atproto.label.defs.LabelValueDefinitionStrings
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// try to find locale match in the definition's strings
|
// try to find locale match in the definition's strings
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {type AppBskyGraphDefs, AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/syntax'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {isInvalidHandle} from '#/lib/strings/handles'
|
import {isInvalidHandle} from '#/lib/strings/handles'
|
||||||
|
|
||||||
export function makeProfileLink(
|
export function makeProfileLink(
|
||||||
@@ -44,8 +44,8 @@ export function makeSearchLink(props: {query: string; from?: 'me' | string}) {
|
|||||||
|
|
||||||
export function makeStarterPackLink(
|
export function makeStarterPackLink(
|
||||||
starterPackOrName:
|
starterPackOrName:
|
||||||
| AppBskyGraphDefs.StarterPackViewBasic
|
| app.bsky.graph.defs.StarterPackViewBasic
|
||||||
| AppBskyGraphDefs.StarterPackView
|
| app.bsky.graph.defs.StarterPackView
|
||||||
| string,
|
| string,
|
||||||
rkey?: string,
|
rkey?: string,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {XRPCError} from '@atproto/api'
|
|
||||||
import {LexError, XrpcResponseError} from '@atproto/lex'
|
import {LexError, XrpcResponseError} from '@atproto/lex'
|
||||||
import {beforeAll, describe, expect, it} from '@jest/globals'
|
import {beforeAll, describe, expect, it} from '@jest/globals'
|
||||||
import {i18n} from '@lingui/core'
|
import {i18n} from '@lingui/core'
|
||||||
@@ -72,20 +71,10 @@ describe('cleanError', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('matches the upstream-failure branch on a legacy XRPC error', () => {
|
it('matches NotEnoughResources', () => {
|
||||||
const e = new XRPCError(502)
|
|
||||||
expect(cleanError(e)).toBe(
|
|
||||||
'The server appears to be experiencing issues. Please try again in a few moments.',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('matches NotEnoughResources on both error shapes', () => {
|
|
||||||
expect(cleanError(xrpcStatusError(503))).toBe(
|
expect(cleanError(xrpcStatusError(503))).toBe(
|
||||||
'The server appears to be experiencing issues. Please try again in a few moments.',
|
'The server appears to be experiencing issues. Please try again in a few moments.',
|
||||||
)
|
)
|
||||||
expect(cleanError(new XRPCError(503))).toBe(
|
|
||||||
'The server appears to be experiencing issues. Please try again in a few moments.',
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('matches the app-password branch on a lex error message', () => {
|
it('matches the app-password branch on a lex error message', () => {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import {XRPCError} from '@atproto/api'
|
|
||||||
import {LexError} from '@atproto/lex'
|
import {LexError} from '@atproto/lex'
|
||||||
import {t} from '@lingui/core/macro'
|
import {t} from '@lingui/core/macro'
|
||||||
|
|
||||||
|
import {isXrpcError} from '#/lib/xrpc-error'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The text to show the user when no special case applies.
|
* The text to show the user when no special case applies.
|
||||||
*
|
*
|
||||||
@@ -39,7 +40,7 @@ export function cleanError(e: unknown): string {
|
|||||||
return t`Unable to connect. Please check your internet connection and try again.`
|
return t`Unable to connect. Please check your internet connection and try again.`
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* `@atproto/api` names these with spaces ("Upstream Failure"); lexicon error
|
* The legacy client named these with spaces ("Upstream Failure"); lexicon error
|
||||||
* codes are space-free ("UpstreamFailure"). Match both while the app throws
|
* codes are space-free ("UpstreamFailure"). Match both while the app throws
|
||||||
* both shapes.
|
* both shapes.
|
||||||
*/
|
*/
|
||||||
@@ -97,9 +98,20 @@ export function isNetworkError(e: unknown) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PDS answers an app-password-scope rejection with the lexicon code
|
||||||
|
* `InvalidToken` and a message of 'Bad token scope' or 'Bad token method'
|
||||||
|
* (pipethrough), so the typed path matches the code AND the message. The
|
||||||
|
* pre-migration check compared against 'TokenInvalid', which the PDS never
|
||||||
|
* sends - the string fallback was doing all the work.
|
||||||
|
*/
|
||||||
export function isErrorMaybeAppPasswordPermissions(e: unknown) {
|
export function isErrorMaybeAppPasswordPermissions(e: unknown) {
|
||||||
if (e instanceof XRPCError && e.error === 'TokenInvalid') {
|
if (isXrpcError(e)) {
|
||||||
return true
|
return (
|
||||||
|
e.error === 'InvalidToken' &&
|
||||||
|
(e.message.includes('Bad token scope') ||
|
||||||
|
e.message.includes('Bad token method'))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
const str = String(e)
|
const str = String(e)
|
||||||
return str.includes('Bad token scope') || str.includes('Bad token method')
|
return str.includes('Bad token scope') || str.includes('Bad token method')
|
||||||
@@ -124,5 +136,5 @@ export function isRetryableHttpStatus(status: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function shouldRetryError(e: unknown) {
|
export function shouldRetryError(e: unknown) {
|
||||||
return e instanceof XRPCError && isRetryableHttpStatus(e.status)
|
return isXrpcError(e) && e.shouldRetry()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/syntax'
|
||||||
|
|
||||||
import type * as bsky from '#/types/bsky'
|
import type * as bsky from '#/types/bsky'
|
||||||
|
|
||||||
export function createStarterPackLinkFromAndroidReferrer(
|
export function createStarterPackLinkFromAndroidReferrer(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {AtUri} from '@atproto/api'
|
|
||||||
import {parse} from 'psl'
|
import {parse} from 'psl'
|
||||||
import TLDs from 'tlds'
|
import TLDs from 'tlds'
|
||||||
|
|
||||||
|
import {AtUri} from '@atproto/syntax'
|
||||||
import {BSKY_SERVICE} from '#/lib/constants'
|
import {BSKY_SERVICE} from '#/lib/constants'
|
||||||
import {isInvalidHandle} from '#/lib/strings/handles'
|
import {isInvalidHandle} from '#/lib/strings/handles'
|
||||||
import {startUriToStarterPackUri} from '#/lib/strings/starter-pack'
|
import {startUriToStarterPackUri} from '#/lib/strings/starter-pack'
|
||||||
|
|||||||
@@ -4,11 +4,29 @@ import {
|
|||||||
type Main,
|
type Main,
|
||||||
type Procedure,
|
type Procedure,
|
||||||
type Query,
|
type Query,
|
||||||
|
XrpcError,
|
||||||
XrpcResponseError,
|
XrpcResponseError,
|
||||||
} from '@atproto/lex'
|
} from '@atproto/lex'
|
||||||
|
|
||||||
import {com} from '#/lexicons'
|
import {com} from '#/lexicons'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True for an XRPC error from a lex `Client` (`XrpcError` is the abstract base
|
||||||
|
* of `XrpcResponseError`/`XrpcInvalidResponseError`/`XrpcInternalError`).
|
||||||
|
*/
|
||||||
|
export function isXrpcError(e: unknown): e is XrpcError {
|
||||||
|
return e instanceof XrpcError
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP status, or undefined when `e` is not an XRPC error carrying a response.
|
||||||
|
* Only `XrpcResponseError` (a genuine server response) has a status; the
|
||||||
|
* internal/fetch lex errors do not.
|
||||||
|
*/
|
||||||
|
export function getErrorStatus(e: unknown): number | undefined {
|
||||||
|
return e instanceof XrpcResponseError ? e.status : undefined
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same nsid means `e` was thrown for this method schema, so `e` can be
|
* Same nsid means `e` was thrown for this method schema, so `e` can be
|
||||||
* treated as an `XrpcResponseError<M>` - which is what lets the SDK's
|
* treated as an `XrpcResponseError<M>` - which is what lets the SDK's
|
||||||
|
|||||||
Reference in New Issue
Block a user