-
Notifications
You must be signed in to change notification settings - Fork 554
/
unspecced.ts
82 lines (74 loc) · 2.54 KB
/
unspecced.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Server } from '../../../../lexicon'
import { FeedKeyset, composeFeed } from './util/feed'
import { paginate } from '../../../../db/pagination'
import AppContext from '../../../../context'
import { FeedRow } from '../../../services/feed'
import { FeedViewPost } from '../../../../lexicon/types/app/bsky/feed/defs'
import { countAll } from '../../../../db/util'
// 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 requester = auth.credentials.did
const db = ctx.db.db
const { ref } = db.dynamic
const feedService = ctx.services.appView.feed(ctx.db)
const labelService = ctx.services.appView.label(ctx.db)
const postsQb = feedService
.selectPostQb()
.leftJoin('repost', (join) =>
// this works well for one curating user. reassess if adding more
join
.on('repost.creator', '=', 'did:plc:ea2eqamjmtuo6f4rvhl3g6ne')
.onRef('repost.subject', '=', 'post.uri'),
)
.where((clause) =>
clause
.where('repost.creator', 'is not', null)
.orWhere(
(qb) =>
qb
.selectFrom('like')
.whereRef('like.subject', '=', 'post.uri')
.select(countAll.as('count')),
'>=',
8,
),
)
.whereNotExists(
db
.selectFrom('mute')
.selectAll()
.where('mutedByDid', '=', requester)
.whereRef('did', '=', ref('post.creator')),
)
const keyset = new FeedKeyset(ref('sortAt'), ref('cid'))
let feedQb = ctx.db.db.selectFrom(postsQb.as('feed_items')).selectAll()
feedQb = paginate(feedQb, { limit, cursor, keyset })
const feedItems: FeedRow[] = await feedQb.execute()
const feed: FeedViewPost[] = await composeFeed(
feedService,
labelService,
feedItems,
requester,
)
const noRecordEmbeds = feed.map((post) => {
delete post.post.record['embed']
if (post.reply) {
delete post.reply.parent.record['embed']
delete post.reply.root.record['embed']
}
return post
})
return {
encoding: 'application/json',
body: {
feed: noRecordEmbeds,
cursor: keyset.packFromResult(feedItems),
},
}
},
})
}