Toot toooooooot (Bluesky-Mastodon cross-poster)

for quote posts, attach URL to the quoted post at the end

Changed files
+32 -4
app
+32 -4
app/tootify.rb
··· 40 40 like_uri = r['uri'] 41 41 post_uri = r['value']['subject']['uri'] 42 42 repo, collection, rkey = post_uri.split('/')[2..4] 43 - 43 + 44 44 next unless repo == @bluesky.did && collection == 'app.bsky.feed.post' 45 45 46 46 begin ··· 70 70 text = expand_facets(record) 71 71 72 72 if link = link_embed(record) 73 - if !text.include?(link) 74 - text += ' ' unless text.end_with?(' ') 75 - text += link 73 + append_link(text, link) unless text.include?(link) 74 + end 75 + 76 + if quote_uri = quoted_post(record) 77 + repo, collection, rkey = quote_uri.split('/')[2..4] 78 + 79 + if collection == 'app.bsky.feed.post' 80 + bsky_url = bsky_post_link(repo, rkey) 81 + append_link(text, bsky_url) unless text.include?(bsky_url) 76 82 end 77 83 end 78 84 ··· 101 107 102 108 def link_embed(record) 103 109 record['embed'] && record['embed']['external'] && record['embed']['external']['uri'] 110 + end 111 + 112 + def quoted_post(record) 113 + if embed = record['embed'] 114 + case embed['$type'] 115 + when 'app.bsky.embed.record' 116 + embed['record']['uri'] 117 + when 'app.bsky.embed.recordWithMedia' 118 + embed['record']['record']['uri'] 119 + else 120 + nil 121 + end 122 + end 123 + end 124 + 125 + def append_link(text, link) 126 + text << ' ' unless text.end_with?(' ') 127 + text << link 128 + end 129 + 130 + def bsky_post_link(repo, rkey) 131 + "https://bsky.app/profile/#{repo}/post/#{rkey}" 104 132 end 105 133 end