Toot toooooooot (Bluesky-Mastodon cross-poster)

expand shortened URLs from link facets

Changed files
+23 -1
app
+23 -1
app/tootify.rb
··· 56 56 57 57 def post_to_mastodon(record) 58 58 p record 59 - p @mastodon.post_status(record['text']) 59 + 60 + text = expand_facets(record) 61 + p @mastodon.post_status(text) 62 + end 63 + 64 + def expand_facets(record) 65 + bytes = record['text'].bytes 66 + offset = 0 67 + 68 + if facets = record['facets'] 69 + facets.sort_by { |f| f['index']['byteStart'] }.each do |f| 70 + if link = f['features'].detect { |ft| ft['$type'] == 'app.bsky.richtext.facet#link' } 71 + left = f['index']['byteStart'] 72 + right = f['index']['byteEnd'] 73 + content = link['uri'].bytes 74 + 75 + bytes[(left + offset) ... (right + offset)] = content 76 + offset += content.length - (right - left) 77 + end 78 + end 79 + end 80 + 81 + bytes.pack('C*').force_encoding('UTF-8') 60 82 end 61 83 end