Skip to content

Commit

Permalink
Include nsfw flag for getPopular (bluesky-social#949)
Browse files Browse the repository at this point in the history
add includeNsfw flag for whats hot
  • Loading branch information
dholms authored May 1, 2023
1 parent bff9654 commit 1e24d3e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions lexicons/app/bsky/unspecced/getPopular.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"parameters": {
"type": "params",
"properties": {
"includeNsfw": {"type": "boolean", "default": false},
"limit": {"type": "integer", "minimum": 1, "maximum": 100, "default": 50},
"cursor": {"type": "string"}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5076,6 +5076,10 @@ export const schemaDict = {
parameters: {
type: 'params',
properties: {
includeNsfw: {
type: 'boolean',
default: false,
},
limit: {
type: 'integer',
minimum: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CID } from 'multiformats/cid'
import * as AppBskyFeedDefs from '../feed/defs'

export interface QueryParams {
includeNsfw?: boolean
limit?: number
cursor?: string
}
Expand Down
12 changes: 8 additions & 4 deletions packages/pds/src/app-view/api/app/bsky/unspecced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import { NotEmptyArray } from '@atproto/common'

const NO_WHATS_HOT_LABELS: NotEmptyArray<string> = [
'!no-promote',
'porn',
'sexual',
'corpse',
'self-harm',
]

const NSFW_LABELS = ['porn', 'sexual']

// THIS IS A TEMPORARY UNSPECCED ROUTE
export default function (server: Server, ctx: AppContext) {
server.app.bsky.unspecced.getPopular({
auth: ctx.accessVerifier,
handler: async ({ params, auth }) => {
const { limit, cursor } = params
const { limit, cursor, includeNsfw } = params
const requester = auth.credentials.did
const db = ctx.db.db
const { ref } = db.dynamic
Expand All @@ -28,6 +28,10 @@ export default function (server: Server, ctx: AppContext) {
const actorService = ctx.services.appView.actor(ctx.db)
const labelService = ctx.services.appView.label(ctx.db)

const labelsToFilter = includeNsfw
? NO_WHATS_HOT_LABELS
: [...NO_WHATS_HOT_LABELS, ...NSFW_LABELS]

const postsQb = feedService
.selectPostQb()
.leftJoin('post_agg', 'post_agg.uri', 'post.uri')
Expand All @@ -36,7 +40,7 @@ export default function (server: Server, ctx: AppContext) {
qb
.selectFrom('label')
.selectAll()
.where('val', 'in', NO_WHATS_HOT_LABELS)
.where('val', 'in', labelsToFilter)
.where((clause) =>
clause
.whereRef('label.uri', '=', ref('post.creator'))
Expand Down
4 changes: 4 additions & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5076,6 +5076,10 @@ export const schemaDict = {
parameters: {
type: 'params',
properties: {
includeNsfw: {
type: 'boolean',
default: false,
},
limit: {
type: 'integer',
minimum: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { HandlerAuth } from '@atproto/xrpc-server'
import * as AppBskyFeedDefs from '../feed/defs'

export interface QueryParams {
includeNsfw: boolean
limit: number
cursor?: string
}
Expand Down

0 comments on commit 1e24d3e

Please sign in to comment.