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

Appview: enable insight into full thread context #2651

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/build-and-push-bsky-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- divy/appview-getrecord-nohost
- divy/mod-full-thread
env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
Expand Down
5 changes: 3 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import { AtUri } from '@atproto/syntax'
import { Server } from '../../../../lexicon'
import { isNotFoundPost } from '../../../../lexicon/types/app/bsky/feed/defs'
import {
Expand Down Expand Up @@ -29,12 +28,14 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.feed.getPostThread({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ params, auth, req, res }) => {
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const { viewer, includeTakedowns, include3pBlocks } =
ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = await ctx.hydrator.createContext({
labelers,
viewer,
includeTakedowns,
include3pBlocks,
})

let result: OutputSchema
Expand Down
5 changes: 3 additions & 2 deletions packages/bsky/src/auth-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class AuthVerifier {
) {
const viewer =
creds.credentials.type === 'standard' ? creds.credentials.iss : null
const includeTakedowns =
const includeTakedownsAnd3pBlocks =
(creds.credentials.type === 'role' && creds.credentials.admin) ||
creds.credentials.type === 'mod_service' ||
(creds.credentials.type === 'standard' &&
Expand All @@ -284,7 +284,8 @@ export class AuthVerifier {

return {
viewer,
includeTakedowns,
includeTakedowns: includeTakedownsAnd3pBlocks,
include3pBlocks: includeTakedownsAnd3pBlocks,
canPerformTakedown,
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/bsky/src/hydration/hydrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ import {
FeedItem,
} from './feed'
import { ParsedLabelers } from '../util'
import starterPack from '../data-plane/server/indexing/plugins/starter-pack'

export class HydrateCtx {
labelers = this.vals.labelers
viewer = this.vals.viewer !== null ? serviceRefToDid(this.vals.viewer) : null
includeTakedowns = this.vals.includeTakedowns
include3pBlocks = this.vals.include3pBlocks
constructor(private vals: HydrateCtxVals) {}
copy<V extends Partial<HydrateCtxVals>>(vals?: V): HydrateCtx & V {
return new HydrateCtx({ ...this.vals, ...vals }) as HydrateCtx & V
Expand All @@ -75,6 +75,7 @@ export type HydrateCtxVals = {
labelers: ParsedLabelers
viewer: string | null
includeTakedowns?: boolean
include3pBlocks?: boolean
}

export type HydrationState = {
Expand Down Expand Up @@ -914,6 +915,7 @@ export class Hydrator {
labelers: availableLabelers,
viewer: vals.viewer,
includeTakedowns: vals.includeTakedowns,
include3pBlocks: vals.include3pBlocks,
})
}

Expand Down
12 changes: 8 additions & 4 deletions packages/bsky/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,11 @@ export class Views {
if (!postRecord?.reply) return
let root = this.maybePost(postRecord.reply.root.uri, state)
let parent = this.maybePost(postRecord.reply.parent.uri, state)
if (state.postBlocks?.get(uri)?.reply && isPostView(parent)) {
if (
!state.ctx?.include3pBlocks &&
state.postBlocks?.get(uri)?.reply &&
isPostView(parent)
) {
parent = this.blockedPost(parent.uri, parent.author.did, state)
// in a reply to the root of a thread, parent and root are the same post.
if (root.uri === parent.uri) {
Expand Down Expand Up @@ -751,7 +755,7 @@ export class Views {
if (height < 1) return undefined
const parentUri = state.posts?.get(childUri)?.record.reply?.parent.uri
if (!parentUri) return undefined
if (state.postBlocks?.get(childUri)?.reply) {
if (!state.ctx?.include3pBlocks && state.postBlocks?.get(childUri)?.reply) {
return this.blockedPost(parentUri, creatorFromUri(parentUri), state)
}
const post = this.post(parentUri, state)
Expand Down Expand Up @@ -782,7 +786,7 @@ export class Views {
if (postInfo?.violatesThreadGate) {
return undefined
}
if (state.postBlocks?.get(uri)?.reply) {
if (!state.ctx?.include3pBlocks && state.postBlocks?.get(uri)?.reply) {
return undefined
}
const post = this.post(uri, state)
Expand Down Expand Up @@ -935,7 +939,7 @@ export class Views {
const parsedUri = new AtUri(uri)
if (
this.viewerBlockExists(parsedUri.hostname, state) ||
state.postBlocks?.get(postUri)?.embed
(!state.ctx?.include3pBlocks && state.postBlocks?.get(postUri)?.embed)
) {
return this.embedBlocked(uri, state)
}
Expand Down
Loading