Module: Tempest::PostView
- Defined in:
- lib/tempest/post_view.rb
Constant Summary collapse
- EMBED_KINDS =
{ "app.bsky.embed.images" => :images, "app.bsky.embed.record" => :record, "app.bsky.embed.external" => :external, "app.bsky.embed.video" => :video, }.freeze
Class Method Summary collapse
- .embed_view(embed) ⇒ Object
- .facets_view(facets) ⇒ Object
- .from_feed_view(post_hash) ⇒ Object
- .reply_view(reply) ⇒ Object
Class Method Details
.embed_view(embed) ⇒ Object
63 64 65 66 67 |
# File 'lib/tempest/post_view.rb', line 63 def () return { kind: nil } unless .is_a?(Hash) type = ["$type"].to_s.sub(/#view\z/, "") { kind: EMBED_KINDS[type] } end |
.facets_view(facets) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tempest/post_view.rb', line 48 def facets_view(facets) Array(facets).flat_map do |facet| idx = facet["index"] || {} Array(facet["features"]).filter_map do |feat| next unless feat["$type"] == "app.bsky.richtext.facet#link" { kind: :link, uri: feat["uri"], byte_start: idx["byteStart"], byte_end: idx["byteEnd"], } end end end |
.from_feed_view(post_hash) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tempest/post_view.rb', line 14 def from_feed_view(post_hash) h = post_hash || {} = h["author"] || {} record = h["record"] || {} reply = record["reply"] { uri: h["uri"], cid: h["cid"], author: { did: ["did"], handle: ["handle"], display_name: ["displayName"], }, text: record["text"], created_at: record["createdAt"], indexed_at: h["indexedAt"], langs: Array(record["langs"]), reply: reply_view(reply), facets: facets_view(record["facets"]), embed: (h["embed"] || record["embed"]), like_count: h["likeCount"] || 0, repost_count: h["repostCount"] || 0, reply_count: h["replyCount"] || 0, } end |
.reply_view(reply) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/tempest/post_view.rb', line 41 def reply_view(reply) return nil unless reply.is_a?(Hash) parent = reply["parent"].is_a?(Hash) ? reply["parent"]["uri"] : nil root = reply["root"].is_a?(Hash) ? reply["root"]["uri"] : nil { parent_uri: parent, root_uri: root } end |