[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
atproto deno hono lexicon
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: thread depth util

+37 -19
+8 -9
api/so/sprk/feed/getCrosspostThread.ts
··· 23 23 import { 24 24 ATPROTO_REPO_REV, 25 25 createHydrateCtxFromAuth, 26 + getThreadDepth, 26 27 resHeaders, 27 28 } from "../../../util.ts"; 28 29 ··· 75 76 const result = await ctx.dataplane.crosspostThread.getThread( 76 77 anchor, 77 78 params.parentHeight, 78 - getDepth(ctx, anchor, params), 79 + getThreadDepth({ 80 + anchor, 81 + depth: params.depth, 82 + maxThreadDepth: ctx.cfg.maxThreadDepth, 83 + bigThreadUris: ctx.cfg.bigThreadUris, 84 + bigThreadDepth: ctx.cfg.bigThreadDepth, 85 + }), 79 86 params.sort, 80 87 ); 81 88 const visibleItems = params.hydrateCtx.includeTakedowns ··· 211 218 indexedAt: item.indexedAt, 212 219 }, 213 220 }; 214 - }; 215 - 216 - const getDepth = (ctx: Context, anchor: string, params: Params) => { 217 - let maxDepth = ctx.cfg.maxThreadDepth; 218 - if (ctx.cfg.bigThreadUris.has(anchor) && ctx.cfg.bigThreadDepth) { 219 - maxDepth = ctx.cfg.bigThreadDepth; 220 - } 221 - return maxDepth ? Math.min(maxDepth, params.depth) : params.depth; 222 221 }; 223 222 224 223 const parseThreadCursor = (cursor?: string): number => {
+15 -10
api/so/sprk/feed/getPostThread.ts
··· 20 20 import { 21 21 ATPROTO_REPO_REV, 22 22 createHydrateCtxFromAuth, 23 + getThreadDepth, 23 24 resHeaders, 24 25 } from "../../../util.ts"; 25 26 ··· 70 71 const res = await ctx.dataplane.threads.getThread( 71 72 anchor, 72 73 params.parentHeight, 73 - getDepth(ctx, anchor, params), 74 + getThreadDepth({ 75 + anchor, 76 + depth: params.depth, 77 + maxThreadDepth: ctx.cfg.maxThreadDepth, 78 + bigThreadUris: ctx.cfg.bigThreadUris, 79 + bigThreadDepth: ctx.cfg.bigThreadDepth, 80 + }), 74 81 ); 75 82 return { 76 83 anchor, ··· 103 110 ) => { 104 111 const { ctx, params, skeleton, hydration } = inputs; 105 112 const thread = ctx.views.thread(skeleton, hydration, { 106 - depth: getDepth(ctx, skeleton.anchor, params), 113 + depth: getThreadDepth({ 114 + anchor: skeleton.anchor, 115 + depth: params.depth, 116 + maxThreadDepth: ctx.cfg.maxThreadDepth, 117 + bigThreadUris: ctx.cfg.bigThreadUris, 118 + bigThreadDepth: ctx.cfg.bigThreadDepth, 119 + }), 107 120 }); 108 121 if (isNotFoundPost(thread)) { 109 122 // @TODO technically this could be returned as a NotFoundPost based on lexicon ··· 128 141 anchor: string; 129 142 uris: string[]; 130 143 }; 131 - 132 - const getDepth = (ctx: Context, anchor: string, params: Params) => { 133 - let maxDepth = ctx.cfg.maxThreadDepth; 134 - if (ctx.cfg.bigThreadUris.has(anchor) && ctx.cfg.bigThreadDepth) { 135 - maxDepth = ctx.cfg.bigThreadDepth; 136 - } 137 - return maxDepth ? Math.min(maxDepth, params.depth) : params.depth; 138 - };
+14
api/util.ts
··· 56 56 ...overrides, 57 57 }); 58 58 }; 59 + 60 + export const getThreadDepth = (opts: { 61 + anchor: string; 62 + depth: number; 63 + maxThreadDepth?: number; 64 + bigThreadUris: Set<string>; 65 + bigThreadDepth?: number; 66 + }): number => { 67 + let max = opts.maxThreadDepth; 68 + if (opts.bigThreadUris.has(opts.anchor) && opts.bigThreadDepth) { 69 + max = opts.bigThreadDepth; 70 + } 71 + return max ? Math.min(max, opts.depth) : opts.depth; 72 + };