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

Configure Feed

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

Update getProfile.ts

+32 -6
+32 -6
services/appview/src/routes/actor/getProfile.ts
··· 49 49 profile.authorDid, 50 50 ) 51 51 52 - // Get follower count 53 - const followersCount = await ctx.db.models.Follow.countDocuments({ 52 + // Get Spark follower count 53 + const sparkFollowersCount = await ctx.db.models.Follow.countDocuments({ 54 54 subject: actorDid, 55 55 }) 56 56 57 - // Get follows count 58 - const followsCount = await ctx.db.models.Follow.countDocuments({ 57 + // Get Spark follows count 58 + const sparkFollowsCount = await ctx.db.models.Follow.countDocuments({ 59 59 authorDid: actorDid, 60 60 }) 61 61 62 - // Get posts count 63 - const postsCount = await ctx.db.models.Post.countDocuments({ 62 + // Get Spark posts count 63 + const sparkPostsCount = await ctx.db.models.Post.countDocuments({ 64 64 authorDid: actorDid, 65 65 }) 66 + 67 + // Get Bluesky profile and stats 68 + let blueskyFollowersCount = 0 69 + let blueskyFollowsCount = 0 70 + let blueskyPostsCount = 0 71 + 72 + try { 73 + // Get the Bluesky profile using the DID 74 + const didDoc = await ctx.didResolver.resolveAtprotoData(actorDid) 75 + if (didDoc?.pds) { 76 + const response = await fetch(`${didDoc.pds}/xrpc/app.bsky.actor.getProfile?actor=${actorDid}`) 77 + if (response.ok) { 78 + const data = await response.json() 79 + blueskyFollowersCount = data.followersCount || 0 80 + blueskyFollowsCount = data.followsCount || 0 81 + blueskyPostsCount = data.postsCount || 0 82 + } 83 + } 84 + } catch (err) { 85 + // Ignore errors from Bluesky fetch, we'll just use Spark stats 86 + } 87 + 88 + // Combine stats, ensuring we don't count duplicates 89 + const followersCount = Math.max(sparkFollowersCount, blueskyFollowersCount) 90 + const followsCount = Math.max(sparkFollowsCount, blueskyFollowsCount) 91 + const postsCount = Math.max(sparkPostsCount, blueskyPostsCount) 66 92 67 93 // Build viewer state if a user is authenticated 68 94 const viewer: SoSprkActorDefs.ViewerState = {}