Class: Hive::Account

Inherits:
Base
  • Object
show all
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.promoted_authors

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

Methods inherited from Base

delete, #delete, delete_all, transform_account_selector, #update, update_all

Instance Method Details

#feedActiveRecord::Relation

The entire feed for this account, as in, all content created/reblogged by authors that this account follows.

Returns:

  • (ActiveRecord::Relation)


120
# File 'lib/hive/models/account.rb', line 120

def feed; Post.feed(following); end

#feed_cacheActiveRecord::Relation

The entire feed for this account, as in, all content created/reblogged by authors that this account follows.

Returns:

  • (ActiveRecord::Relation)


114
# File 'lib/hive/models/account.rb', line 114

def feed_cache; Post.feed_cache(following); end

#ignored_feedActiveRecord::Relation

The entire ignred feed for this account, as in, all content created/reblogged by authors that this account mutes.

Returns:

  • (ActiveRecord::Relation)


132
# File 'lib/hive/models/account.rb', line 132

def ignored_feed; Post.feed(muting); end

#ignored_feed_cacheActiveRecord::Relation

The entire ignred feed for this account, as in, all content created/reblogged by authors that this account mutes.

Returns:

  • (ActiveRecord::Relation)


126
# File 'lib/hive/models/account.rb', line 126

def ignored_feed_cache; Post.feed_cache(muting); end

#repliesObject

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