A locally focused bluesky appview

fixup author did grabbing

Changed files
+29 -38
hydration
+29 -38
hydration/post.go
··· 9 9 10 10 "github.com/bluesky-social/indigo/api/bsky" 11 11 "github.com/bluesky-social/indigo/lex/util" 12 + "github.com/whyrusleeping/market/models" 12 13 "go.opentelemetry.io/otel" 13 14 ) 14 15 ··· 39 40 defer span.End() 40 41 41 42 // Query post from database 42 - var dbPost struct { 43 - ID uint 44 - Cid string 45 - Raw []byte 46 - NotFound bool 47 - ReplyTo uint 48 - ReplyToUsr uint 49 - InThread uint 50 - AuthorID uint 51 - } 52 - 53 - err := h.db.Raw(` 54 - SELECT p.id, p.cid, p.raw, p.not_found, p.reply_to, p.reply_to_usr, p.in_thread, p.author as author_id 55 - FROM posts p 56 - WHERE p.id = ( 57 - SELECT id FROM posts 43 + var dbPost models.Post 44 + err := h.db.Raw(`SELECT * FROM posts 58 45 WHERE author = (SELECT id FROM repos WHERE did = ?) 59 46 AND rkey = ? 60 - ) 61 47 `, extractDIDFromURI(uri), extractRkeyFromURI(uri)).Scan(&dbPost).Error 62 48 63 49 if err != nil { ··· 77 63 var wg sync.WaitGroup 78 64 79 65 // Get author DID 80 - var authorDID string 81 - var likes, reposts, replies int 82 66 83 - wg.Go(func() { 84 - h.db.Raw("SELECT did FROM repos WHERE id = ?", dbPost.AuthorID).Scan(&authorDID) 85 - }) 67 + authorDID := extractDIDFromURI(uri) 86 68 87 69 // Get engagement counts 70 + var likes, reposts, replies int 88 71 wg.Go(func() { 89 72 h.db.Raw("SELECT COUNT(*) FROM likes WHERE subject = ?", dbPost.ID).Scan(&likes) 90 73 }) ··· 95 78 h.db.Raw("SELECT COUNT(*) FROM posts WHERE reply_to = ?", dbPost.ID).Scan(&replies) 96 79 }) 97 80 81 + // Check if viewer liked this post 82 + var likeRkey string 83 + if viewerDID != "" { 84 + wg.Go(func() { 85 + h.db.Raw(` 86 + SELECT l.rkey FROM likes l 87 + WHERE l.subject = ? 88 + AND l.author = (SELECT id FROM repos WHERE did = ?) 89 + `, dbPost.ID, viewerDID).Scan(&likeRkey) 90 + }) 91 + } 92 + 93 + var ei *bsky.FeedDefs_PostView_Embed 94 + if feedPost.Embed != nil { 95 + wg.Go(func() { 96 + ei = h.formatEmbed(ctx, feedPost.Embed, authorDID, viewerDID) 97 + }) 98 + } 99 + 98 100 wg.Wait() 99 101 100 102 info := &PostInfo{ ··· 108 110 LikeCount: likes, 109 111 RepostCount: reposts, 110 112 ReplyCount: replies, 113 + EmbedInfo: ei, 114 + } 115 + 116 + if likeRkey != "" { 117 + info.ViewerLike = fmt.Sprintf("at://%s/app.bsky.feed.like/%s", viewerDID, likeRkey) 111 118 } 112 119 113 120 if info.Cid == "" { ··· 115 122 info.Cid = fakeCid 116 123 } 117 124 118 - // Check if viewer liked this post 119 - if viewerDID != "" { 120 - var likeRkey string 121 - h.db.Raw(` 122 - SELECT l.rkey FROM likes l 123 - WHERE l.subject = ? 124 - AND l.author = (SELECT id FROM repos WHERE did = ?) 125 - `, dbPost.ID, viewerDID).Scan(&likeRkey) 126 - if likeRkey != "" { 127 - info.ViewerLike = fmt.Sprintf("at://%s/app.bsky.feed.like/%s", viewerDID, likeRkey) 128 - } 129 - } 130 - 131 125 // Hydrate embed 132 - if feedPost.Embed != nil { 133 - info.EmbedInfo = h.formatEmbed(ctx, feedPost.Embed, authorDID, viewerDID) 134 - } 135 126 136 127 return info, nil 137 128 }