Class: Hive::Account
- Defined in:
- lib/hive/models/account.rb
Overview
To find an Account, use the following idiom:
alice = Hive::Account.find_by_name 'alice'
An account has many Post records. To access associated posts, use:
alice.posts
Like posts, account has many PostsCache records. There are two ways to access an account’s related PostsCache records.
alice.posts.joins(:cache) # which includes posts_cache fields
alice.posts_cache # automatically joins posts to get posts_cache
An account also has many Reblog records that can be used to access reblogged posts, which are the posts that the account has reblogged (aka re-steemed):
alice.reblogged_posts
Accounts also have access to Follow for various things like “follow” and “mute”.
alice.following # accounts that this account is following
alice.followers # accounts that follow this account
alice.muting # accounts that this account is muting
alice.muters # accounts that mute this account
Post promotions are tracked by Payment and associated with accounts as well. To get a list of posts that this account has promoted:
alice.promoted_posts
Also, you can get a list of all accounts that this account has promoted at some point.
alice.
This is the sum of all post promotion by this account, grouped by the author being promoted:
puts JSON.pretty_generate alice.payments.
joins(:post).group(:author).sum(:amount)
This scope will limit the number of accounts to those who have only ever posted n times:
Hive::Account.root_posts_count(1)
Hive::Account.root_posts_count(1..5) # accounts with between 1 and 5 posts
Instance Method Summary collapse
-
#feed ⇒ ActiveRecord::Relation
The entire feed for this account, as in, all content created/reblogged by authors that this account follows.
-
#feed_cache ⇒ ActiveRecord::Relation
The entire feed for this account, as in, all content created/reblogged by authors that this account follows.
-
#ignored_feed ⇒ ActiveRecord::Relation
The entire ignred feed for this account, as in, all content created/reblogged by authors that this account mutes.
-
#ignored_feed_cache ⇒ ActiveRecord::Relation
The entire ignred feed for this account, as in, all content created/reblogged by authors that this account mutes.
-
#replies ⇒ Object
All comments that have replied to this account, as in, all content that has the parent_author as this account.
Methods inherited from Base
delete, #delete, delete_all, transform_account_selector, #update, update_all
Instance Method Details
#feed ⇒ ActiveRecord::Relation
The entire feed for this account, as in, all content created/reblogged by authors that this account follows.
120 |
# File 'lib/hive/models/account.rb', line 120 def feed; Post.feed(following); end |
#feed_cache ⇒ ActiveRecord::Relation
The entire feed for this account, as in, all content created/reblogged by authors that this account follows.
114 |
# File 'lib/hive/models/account.rb', line 114 def feed_cache; Post.feed_cache(following); end |
#ignored_feed ⇒ ActiveRecord::Relation
The entire ignred feed for this account, as in, all content created/reblogged by authors that this account mutes.
132 |
# File 'lib/hive/models/account.rb', line 132 def ignored_feed; Post.feed(muting); end |
#ignored_feed_cache ⇒ ActiveRecord::Relation
The entire ignred feed for this account, as in, all content created/reblogged by authors that this account mutes.
126 |
# File 'lib/hive/models/account.rb', line 126 def ignored_feed_cache; Post.feed_cache(muting); end |
#replies ⇒ Object
All comments that have replied to this account, as in, all content that has the parent_author as this account.
136 |
# File 'lib/hive/models/account.rb', line 136 def replies; Post.replies(parent_author: self); end |