From 6a2ac027d5c6e0e545f14dbcd293b6de81f8be76 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 29 Jun 2026 10:05:44 +0100 Subject: [PATCH] appview/home: correctly attribute reposts in homepage in the homepage, we have a list of bsky posts from the tangled-org account. some of these posts are reposts. reposts need to be attributed to the original authors and links now point back to the original authors' post (instead of being broken). Signed-off-by: oppiliappan --- appview/db/bsky.go | 11 +++++++---- appview/db/db.go | 7 +++++++ appview/models/bsky.go | 11 +++++++++-- appview/pages/templates/timeline/home.html | 9 +++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/appview/db/bsky.go b/appview/db/bsky.go index 32b87cda..9ed333ed 100644 --- a/appview/db/bsky.go +++ b/appview/db/bsky.go @@ -14,8 +14,8 @@ func InsertBlueskyPosts(e Execer, posts []models.BskyPost) error { } stmt, err := e.Prepare(` - insert or replace into bluesky_posts (rkey, text, created_at, langs, facets, embed, like_count, reply_count, repost_count, quote_count) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + insert or replace into bluesky_posts (rkey, text, created_at, langs, facets, embed, like_count, reply_count, repost_count, quote_count, author_did) + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `) if err != nil { return err @@ -46,6 +46,7 @@ func InsertBlueskyPosts(e Execer, posts []models.BskyPost) error { post.ReplyCount, post.RepostCount, post.QuoteCount, + post.AuthorDid, ) if err != nil { return err @@ -64,7 +65,7 @@ func nullString(b []byte) any { func GetBlueskyPosts(e Execer, limit int) ([]models.BskyPost, error) { query := ` - select rkey, text, created_at, langs, facets, embed, like_count, reply_count, repost_count, quote_count + select rkey, text, created_at, langs, facets, embed, like_count, reply_count, repost_count, quote_count, author_did from bluesky_posts order by created_at desc limit ? @@ -81,8 +82,9 @@ func GetBlueskyPosts(e Execer, limit int) ([]models.BskyPost, error) { var rkey, text, createdAt string var langs, facets, embed sql.Null[string] var likeCount, replyCount, repostCount, quoteCount int64 + var authorDid string - err := rows.Scan(&rkey, &text, &createdAt, &langs, &facets, &embed, &likeCount, &replyCount, &repostCount, "eCount) + err := rows.Scan(&rkey, &text, &createdAt, &langs, &facets, &embed, &likeCount, &replyCount, &repostCount, "eCount, &authorDid) if err != nil { return nil, err } @@ -94,6 +96,7 @@ func GetBlueskyPosts(e Execer, limit int) ([]models.BskyPost, error) { ReplyCount: replyCount, RepostCount: repostCount, QuoteCount: quoteCount, + AuthorDid: authorDid, } if t, err := time.Parse(time.RFC3339, createdAt); err == nil { diff --git a/appview/db/db.go b/appview/db/db.go index f98efb6f..18fdca1d 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -2365,6 +2365,13 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { return nil }) + orm.RunMigration(conn, logger, "add-author-to-bluesky-posts", func(tx *sql.Tx) error { + _, err := tx.Exec(` + alter table bluesky_posts add column author_did text not null default ''; + `) + return err + }) + return &DB{ db, logger, diff --git a/appview/models/bsky.go b/appview/models/bsky.go index b3ed577d..ed6fe74e 100644 --- a/appview/models/bsky.go +++ b/appview/models/bsky.go @@ -8,6 +8,7 @@ import ( ) type BskyPost struct { + AuthorDid string Rkey string Text string CreatedAt time.Time @@ -54,7 +55,7 @@ func NewBskyPostFromView(postView *apibsky.FeedDefs_PostView) (*BskyPost, error) quoteCount = *postView.QuoteCount } - return &BskyPost{ + post := &BskyPost{ Rkey: atUri.RecordKey().String(), Text: feedPost.Text, CreatedAt: createdAt, @@ -68,5 +69,11 @@ func NewBskyPostFromView(postView *apibsky.FeedDefs_PostView) (*BskyPost, error) ReplyCount: replyCount, RepostCount: repostCount, QuoteCount: quoteCount, - }, nil + } + + if author := postView.Author; author != nil { + post.AuthorDid = author.Did + } + + return post, nil } diff --git a/appview/pages/templates/timeline/home.html b/appview/pages/templates/timeline/home.html index 76f669d7..74367068 100644 --- a/appview/pages/templates/timeline/home.html +++ b/appview/pages/templates/timeline/home.html @@ -446,11 +446,12 @@ {{ end }} {{ define "post" }} + {{ $author := or .AuthorDid "tangled.org" }}
- - {{ template "user/fragments/picHandle" "tangled.org" }} - + + {{ template "user/fragments/picHandle" $author }} + {{ template "repo/fragments/shortTimeAgo" .CreatedAt }}

{{ .Text }}

@@ -480,7 +481,7 @@ {{ end }} {{ end }} - -- 2.51.2