Class: Hive::Post
- Defined in:
- lib/hive/models/post.rb
Overview
Tracks all content including posts, comments (replies).
To find a post, you can do a lookup using the #find_by_slug scope:
post = Hive::Post.find_by_slug '@steemit/firstpost'
A post has many children, which are direct replies to that post.
children = post.children
Each child post has a parent that links back to the post it is a reply to:
parent = children.first.parent
A post also has an account_record, which is the ActiveRecord version of the account string:
account = post.account_record
A post has many followers, which are the accounts that follow the author:
followers = post.followers
A post belongs to a community, which can be accessed as community_record, the ActiveRecord version of the community string:
communit = post.community_record
A post has many flaggers, which are the accounts that have flagged this post:
flaggers = post.flaggers
A post has many rebloggers, which are the accounts that have reblogged this post:
rebloggers = post.rebloggers
A post has many promoters, which are the accounts that have promoted this post:
promoters = post.promoters
Scopes
We can use these scopes to perform a lookup on posts:
posts = Hive::Post. 'alice'
posts = Hive::Post.community 'steemit'
posts = Hive::Post.category 'steemit'
posts = Hive::Post.depth 0 # only returns root posts
posts = Hive::Post.root_posts # same as depth 0
Replies can be queried by specifying depth greater than zero:
replies = Hive::Post.depth 1..10 # only returns replies up to 10 in depth
replies = Hive::Post.depth 1..255 # only returns replies
replies = Hive::Post.replies # same as depth 1..255
We can also specify replies for a particular author, which is analogous to all replies to an author on steemit.com (i.e.: steemit.com/@alice/recent-replies):
replies = Hive::Post.replies(parent_author: 'alice')
We can query for posts that were reblogged by someone:
posts = Hive::Post.rebloggers('alice')
If we want to grab all of the posts that have all of these tags:
posts = Hive::Post.tagged(all: %w(steemit steem video youtube))
Or we can grab all of the posts with any of these tags:
posts = Hive::Post.tagged(any: %w(steemit steem video youtube))
Or, which is the same as using any:
posts = Hive::Post.tagged(%w(steemit steem video youtube))
Here, we can find all of the posts that mention all of these accounts:
posts = Hive::Post.mentioned(all: %w(alice bob))
Or find all of the posts that mention any of these accounts:
posts = Hive::Post.mentioned(any: %w(alice bob))
We can order by (which automatically joins PostsCache):
posts = Hive::Post.order_by_payout(:asc)
posts = Hive::Post.order_by_payout # same as order_by_payout(:asc)
posts = Hive::Post.order_by_payout(:desc)
posts = Hive::Post.order_by_children
posts = Hive::Post.
posts = Hive::Post.order_by_total_votes
posts = Hive::Post.order_by_up_votes
posts = Hive::Post.order_by_promoted
posts = Hive::Post.order_by_created_at
posts = Hive::Post.order_by_payout_at
posts = Hive::Post.order_by_updated_at
posts = Hive::Post.order_by_rshares # first result is the most flagged post!
Other scopes:
posts = Hive::Post.deleted
posts = Hive::Post.deleted(false)
posts = Hive::Post.pinned
posts = Hive::Post.pinned(false)
posts = Hive::Post.muted
posts = Hive::Post.muted(false)
posts = Hive::Post.valid
posts = Hive::Post.valid(false)
posts = Hive::Post.promoted
posts = Hive::Post.promoted(false)
posts = Hive::Post.reblogged
posts = Hive::Post.reblogged(false)
posts = Hive::Post.after(7.days.ago)
posts = Hive::Post.after(7.days.ago, invert: true)
posts = Hive::Post.before(7.days.ago)
posts = Hive::Post.before(7.days.ago, invert: true)
posts = Hive::Post.updated_after(7.days.ago)
posts = Hive::Post.updated_after(7.days.ago, invert: true)
posts = Hive::Post.updated_before(7.days.ago)
posts = Hive::Post.updated_before(7.days.ago, invert: true)
posts = Hive::Post.payout_after(7.days.ago)
posts = Hive::Post.payout_after(7.days.ago, invert: true)
posts = Hive::Post.payout_before(7.days.ago)
posts = Hive::Post.payout_before(7.days.ago, invert: true)
posts = Hive::Post.payout_zero
posts = Hive::Post.payout_zero(false)
posts = Hive::Post.app('busy')
posts = Hive::Post.app('busy', version: '1.0')
posts = Hive::Post.app('busy', version: '1.0', invert: true)
posts = Hive::Post.format('markdown')
posts = Hive::Post.format('markdown', invert: false)
All scopes can be strung together, e.g.:
posts = Hive::Post.root_posts.('alice').promoted
posts = Hive::Post.replies(parent_author: 'alice').community('steemit')
posts = Hive::Post.category('steemit').depth(255).valid
posts = Hive::Post.tagged(all: %w(radiator ruby)).where.not(author: 'inertia')
posts = Hive::Post.mentioned(all: %w(inertia whatsup)).tagged(any: %w(community shoutout))
Most interesting queries (once your node is fully synchronized):
Hive::Post.order_by_rshares.deleted.first # o_O mfw
Constant Summary collapse
- MAX_HARD_DEPTH =
Blockchain limit on depth.
65535
- MAX_SOFT_DEPTH =
Witness limit on depth.
255
Class Method Summary collapse
-
.find_by_slug(slug) ⇒ Hive::Post
Finds a post by slug (or even URL).
Instance Method Summary collapse
-
#discussion ⇒ ActiveRecord::Relation
The entire discussion related to this post including all children and grandchildren replies (the result also includes this post).
-
#slug ⇒ Object
Returns the unique string containing the author and permlink, useful in restful development as param_id, if desired.
-
#tags ⇒ String
All tags related to this post.
Methods inherited from Base
delete, #delete, delete_all, transform_account_selector, #update, update_all
Class Method Details
.find_by_slug(slug) ⇒ Hive::Post
Finds a post by slug (or even URL).
373 374 375 376 377 378 379 380 |
# File 'lib/hive/models/post.rb', line 373 def self.find_by_slug(slug) slug = slug.split('@').last slug = slug.split('/') = slug[0] permlink = slug[1..-1].join('/') Post.where(author: , permlink: permlink).first end |
Instance Method Details
#discussion ⇒ ActiveRecord::Relation
The entire discussion related to this post including all children and grandchildren replies (the result also includes this post).
391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/hive/models/post.rb', line 391 def discussion clause = <<-DONE hive_posts.community = ? AND hive_posts.category = ? AND hive_posts.id >= ? AND hive_posts.id IN(?) DONE Post.deleted(false). where(clause, community, category, id, discussion_ids) end |
#slug ⇒ Object
Returns the unique string containing the author and permlink, useful in restful development as param_id, if desired.
407 408 409 |
# File 'lib/hive/models/post.rb', line 407 def slug "@#{}/#{permlink}" end |
#tags ⇒ String
All tags related to this post.
385 |
# File 'lib/hive/models/post.rb', line 385 def ; .pluck(:tag); end |