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

add getActorLikes #1440

Merged
merged 18 commits into from
Aug 22, 2023
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
37 changes: 37 additions & 0 deletions lexicons/app/bsky/feed/getActorLikes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"lexicon": 1,
"id": "app.bsky.feed.getActorLikes",
"defs": {
"main": {
"type": "query",
"description": "A view of the posts liked by an actor.",
"parameters": {
"type": "params",
"required": ["actor"],
"properties": {
"actor": {"type": "string", "format": "at-identifier"},
"limit": {"type": "integer", "minimum": 1, "maximum": 100, "default": 50},
"cursor": {"type": "string"}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["feed"],
"properties": {
"cursor": {"type": "string"},
"feed": {
"type": "array",
"items": {"type": "ref", "ref": "app.bsky.feed.defs#feedViewPost"}
}
}
}
},
"errors": [
{"name": "BlockedActor"},
{"name": "BlockedByActor"}
]
}
}
}
3 changes: 3 additions & 0 deletions packages/api/src/bsky-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class BskyAgent extends AtpAgent {
getAuthorFeed: typeof this.api.app.bsky.feed.getAuthorFeed = (params, opts) =>
this.api.app.bsky.feed.getAuthorFeed(params, opts)

getActorLikes: typeof this.api.app.bsky.feed.getActorLikes = (params, opts) =>
this.api.app.bsky.feed.getActorLikes(params, opts)

getPostThread: typeof this.api.app.bsky.feed.getPostThread = (params, opts) =>
this.api.app.bsky.feed.getPostThread(params, opts)

Expand Down
13 changes: 13 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import * as AppBskyFeedDefs from './types/app/bsky/feed/defs'
import * as AppBskyFeedDescribeFeedGenerator from './types/app/bsky/feed/describeFeedGenerator'
import * as AppBskyFeedGenerator from './types/app/bsky/feed/generator'
import * as AppBskyFeedGetActorFeeds from './types/app/bsky/feed/getActorFeeds'
import * as AppBskyFeedGetActorLikes from './types/app/bsky/feed/getActorLikes'
import * as AppBskyFeedGetAuthorFeed from './types/app/bsky/feed/getAuthorFeed'
import * as AppBskyFeedGetFeed from './types/app/bsky/feed/getFeed'
import * as AppBskyFeedGetFeedGenerator from './types/app/bsky/feed/getFeedGenerator'
Expand Down Expand Up @@ -209,6 +210,7 @@ export * as AppBskyFeedDefs from './types/app/bsky/feed/defs'
export * as AppBskyFeedDescribeFeedGenerator from './types/app/bsky/feed/describeFeedGenerator'
export * as AppBskyFeedGenerator from './types/app/bsky/feed/generator'
export * as AppBskyFeedGetActorFeeds from './types/app/bsky/feed/getActorFeeds'
export * as AppBskyFeedGetActorLikes from './types/app/bsky/feed/getActorLikes'
export * as AppBskyFeedGetAuthorFeed from './types/app/bsky/feed/getAuthorFeed'
export * as AppBskyFeedGetFeed from './types/app/bsky/feed/getFeed'
export * as AppBskyFeedGetFeedGenerator from './types/app/bsky/feed/getFeedGenerator'
Expand Down Expand Up @@ -1246,6 +1248,17 @@ export class FeedNS {
})
}

getActorLikes(
params?: AppBskyFeedGetActorLikes.QueryParams,
opts?: AppBskyFeedGetActorLikes.CallOptions,
): Promise<AppBskyFeedGetActorLikes.Response> {
return this._service.xrpc
.call('app.bsky.feed.getActorLikes', params, undefined, opts)
.catch((e) => {
throw AppBskyFeedGetActorLikes.toKnownErr(e)
})
}

getAuthorFeed(
params?: AppBskyFeedGetAuthorFeed.QueryParams,
opts?: AppBskyFeedGetAuthorFeed.CallOptions,
Expand Down
57 changes: 57 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4816,6 +4816,62 @@ export const schemaDict = {
},
},
},
AppBskyFeedGetActorLikes: {
lexicon: 1,
id: 'app.bsky.feed.getActorLikes',
defs: {
main: {
type: 'query',
description: 'A view of the posts liked by an actor.',
parameters: {
type: 'params',
required: ['actor'],
properties: {
actor: {
type: 'string',
format: 'at-identifier',
},
limit: {
type: 'integer',
minimum: 1,
maximum: 100,
default: 50,
},
cursor: {
type: 'string',
},
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['feed'],
properties: {
cursor: {
type: 'string',
},
feed: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#feedViewPost',
},
},
},
},
},
errors: [
{
name: 'BlockedActor',
},
{
name: 'BlockedByActor',
},
],
},
},
},
AppBskyFeedGetAuthorFeed: {
lexicon: 1,
id: 'app.bsky.feed.getAuthorFeed',
Expand Down Expand Up @@ -6657,6 +6713,7 @@ export const ids = {
AppBskyFeedDescribeFeedGenerator: 'app.bsky.feed.describeFeedGenerator',
AppBskyFeedGenerator: 'app.bsky.feed.generator',
AppBskyFeedGetActorFeeds: 'app.bsky.feed.getActorFeeds',
AppBskyFeedGetActorLikes: 'app.bsky.feed.getActorLikes',
AppBskyFeedGetAuthorFeed: 'app.bsky.feed.getAuthorFeed',
AppBskyFeedGetFeed: 'app.bsky.feed.getFeed',
AppBskyFeedGetFeedGenerator: 'app.bsky.feed.getFeedGenerator',
Expand Down
53 changes: 53 additions & 0 deletions packages/api/src/client/types/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'
import * as AppBskyFeedDefs from './defs'

export interface QueryParams {
actor: string
limit?: number
cursor?: string
}

export type InputSchema = undefined

export interface OutputSchema {
cursor?: string
feed: AppBskyFeedDefs.FeedViewPost[]
[k: string]: unknown
}

export interface CallOptions {
headers?: Headers
}

export interface Response {
success: boolean
headers: Headers
data: OutputSchema
}

export class BlockedActorError extends XRPCError {
constructor(src: XRPCError) {
super(src.status, src.error, src.message, src.headers)
}
}

export class BlockedByActorError extends XRPCError {
constructor(src: XRPCError) {
super(src.status, src.error, src.message, src.headers)
}
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
if (e.error === 'BlockedActor') return new BlockedActorError(e)
if (e.error === 'BlockedByActor') return new BlockedByActorError(e)
}
return e
}
71 changes: 71 additions & 0 deletions packages/bsky/src/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Server } from '../../../../lexicon'
import { FeedKeyset } from '../util/feed'
import { paginate } from '../../../../db/pagination'
import AppContext from '../../../../context'
import { InvalidRequestError } from '@atproto/xrpc-server'
import { setRepoRev } from '../../../util'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.feed.getActorLikes({
auth: ctx.authOptionalVerifier,
handler: async ({ params, auth, res }) => {
const { actor, limit, cursor } = params
const viewer = auth.credentials.did
const db = ctx.db.getReplica()
const { ref } = db.db.dynamic

const actorService = ctx.services.actor(db)
const feedService = ctx.services.feed(db)
const graphService = ctx.services.graph(db)

// maybe resolve did first
const actorRes = await actorService.getActor(actor)
if (!actorRes) {
throw new InvalidRequestError('Profile not found')
}
const actorDid = actorRes.did

if (!viewer || viewer !== actorDid) {
throw new InvalidRequestError('Profile not found')
}

let feedItemsQb = feedService
.selectFeedItemQb()
.innerJoin('like', 'like.subject', 'feed_item.uri')
.where('like.creator', '=', actorDid)

if (viewer !== null) {
feedItemsQb = feedItemsQb.whereNotExists(
graphService.blockQb(viewer, [ref('post.creator')]),
)
}

const keyset = new FeedKeyset(
ref('feed_item.sortAt'),
ref('feed_item.cid'),
)

feedItemsQb = paginate(feedItemsQb, {
limit,
cursor,
keyset,
})

const [feedItems, repoRev] = await Promise.all([
feedItemsQb.execute(),
actorService.getRepoRev(viewer),
])
setRepoRev(res, repoRev)

const feed = await feedService.hydrateFeed(feedItems, viewer)
estrattonbailey marked this conversation as resolved.
Show resolved Hide resolved

return {
encoding: 'application/json',
body: {
feed,
cursor: keyset.packFromResult(feedItems),
},
}
},
})
}
2 changes: 2 additions & 0 deletions packages/bsky/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import getFeedSkeleton from './app/bsky/feed/getFeedSkeleton'
import getLikes from './app/bsky/feed/getLikes'
import getPostThread from './app/bsky/feed/getPostThread'
import getPosts from './app/bsky/feed/getPosts'
import getActorLikes from './app/bsky/feed/getActorLikes'
import getProfile from './app/bsky/actor/getProfile'
import getProfiles from './app/bsky/actor/getProfiles'
import getRepostedBy from './app/bsky/feed/getRepostedBy'
Expand Down Expand Up @@ -64,6 +65,7 @@ export default function (server: Server, ctx: AppContext) {
getLikes(server, ctx)
getPostThread(server, ctx)
getPosts(server, ctx)
getActorLikes(server, ctx)
getProfile(server, ctx)
getProfiles(server, ctx)
getRepostedBy(server, ctx)
Expand Down
12 changes: 12 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import * as AppBskyActorSearchActors from './types/app/bsky/actor/searchActors'
import * as AppBskyActorSearchActorsTypeahead from './types/app/bsky/actor/searchActorsTypeahead'
import * as AppBskyFeedDescribeFeedGenerator from './types/app/bsky/feed/describeFeedGenerator'
import * as AppBskyFeedGetActorFeeds from './types/app/bsky/feed/getActorFeeds'
import * as AppBskyFeedGetActorLikes from './types/app/bsky/feed/getActorLikes'
import * as AppBskyFeedGetAuthorFeed from './types/app/bsky/feed/getAuthorFeed'
import * as AppBskyFeedGetFeed from './types/app/bsky/feed/getFeed'
import * as AppBskyFeedGetFeedGenerator from './types/app/bsky/feed/getFeedGenerator'
Expand Down Expand Up @@ -1043,6 +1044,17 @@ export class FeedNS {
return this._server.xrpc.method(nsid, cfg)
}

getActorLikes<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
AppBskyFeedGetActorLikes.Handler<ExtractAuth<AV>>,
AppBskyFeedGetActorLikes.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'app.bsky.feed.getActorLikes' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

getAuthorFeed<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
57 changes: 57 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4816,6 +4816,62 @@ export const schemaDict = {
},
},
},
AppBskyFeedGetActorLikes: {
lexicon: 1,
id: 'app.bsky.feed.getActorLikes',
defs: {
main: {
type: 'query',
description: 'A view of the posts liked by an actor.',
parameters: {
type: 'params',
required: ['actor'],
properties: {
actor: {
type: 'string',
format: 'at-identifier',
},
limit: {
type: 'integer',
minimum: 1,
maximum: 100,
default: 50,
},
cursor: {
type: 'string',
},
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['feed'],
properties: {
cursor: {
type: 'string',
},
feed: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#feedViewPost',
},
},
},
},
},
errors: [
{
name: 'BlockedActor',
},
{
name: 'BlockedByActor',
},
],
},
},
},
AppBskyFeedGetAuthorFeed: {
lexicon: 1,
id: 'app.bsky.feed.getAuthorFeed',
Expand Down Expand Up @@ -6657,6 +6713,7 @@ export const ids = {
AppBskyFeedDescribeFeedGenerator: 'app.bsky.feed.describeFeedGenerator',
AppBskyFeedGenerator: 'app.bsky.feed.generator',
AppBskyFeedGetActorFeeds: 'app.bsky.feed.getActorFeeds',
AppBskyFeedGetActorLikes: 'app.bsky.feed.getActorLikes',
AppBskyFeedGetAuthorFeed: 'app.bsky.feed.getAuthorFeed',
AppBskyFeedGetFeed: 'app.bsky.feed.getFeed',
AppBskyFeedGetFeedGenerator: 'app.bsky.feed.getFeedGenerator',
Expand Down
Loading