* Remove Connect
* Remove more Connect specs
* Remove a lot more Connect code
* 🚮
* It all has to go
* Explicitly add httpclient
* Update application layout
* Remove messages association from User
* Start fixing specs
* reintroduce util function and refactor references
* Remove Connect Cypress test
* Fix more specs
* Remove Connect from listings
* Ignore contact_via_connect column on listings
* Remove contact_via_connect usages
* Ignore mod_chat_channel_id on tags
* Drop Connect tables
* Remove email_connect_messages from user notification settings
* Re-add httpclient 2.8.3
This was mistakenly removed as a merge conflict
* Don't need to exclude removed chat channel file
* Remove unneeded style for chat channels
* Remove unneeded channel list prop type
* Remove chat channels index/connect-link from getPageEntries
* Re-add comment from httpclient in Gemfile
* Remove connect references from mailers
Tag Moderators no longer have a chat channel
No longer will users be notified about new messages (there won't be
any)
No longer will users be notified about channel invites (you can't
invite anyone anymore)
* Don't configure Pusher and remove PUSHER_* from .env_sample
since it's removed from gemfile, the Pusher constant will not resolve, if this is
configured in the environment variables we'll fail to boot.
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Dan Uber <dan@forem.com>
61 lines
2.3 KiB
Ruby
61 lines
2.3 KiB
Ruby
class Follow < ApplicationRecord
|
|
extend ActsAsFollower::FollowerLib
|
|
extend ActsAsFollower::FollowScopes
|
|
|
|
COUNTER_CULTURE_COLUMN_NAME_BY_TYPE = {
|
|
"User" => "following_users_count",
|
|
"Organization" => "following_orgs_count",
|
|
"ActsAsTaggableOn::Tag" => "following_tags_count"
|
|
}.freeze
|
|
|
|
COUNTER_CULTURE_COLUMNS_NAMES = {
|
|
["follows.followable_type = ?", "User"] => "following_users_count",
|
|
["follows.followable_type = ?", "Organization"] => "following_orgs_count",
|
|
["follows.followable_type = ?", "ActsAsTaggableOn::Tag"] => "following_tags_count"
|
|
}.freeze
|
|
|
|
# Follows belong to the "followable" interface, and also to followers
|
|
belongs_to :followable, polymorphic: true
|
|
belongs_to :follower, polymorphic: true
|
|
|
|
scope :followable_user, ->(id) { where(followable_id: id, followable_type: "User") }
|
|
scope :followable_tag, ->(id) { where(followable_id: id, followable_type: "ActsAsTaggableOn::Tag") }
|
|
|
|
scope :follower_user, ->(id) { where(follower_id: id, followable_type: "User") }
|
|
scope :follower_organization, ->(id) { where(follower_id: id, followable_type: "Organization") }
|
|
scope :follower_podcast, ->(id) { where(follower_id: id, followable_type: "Podcast") }
|
|
scope :follower_tag, ->(id) { where(follower_id: id, followable_type: "ActsAsTaggableOn::Tag") }
|
|
|
|
counter_culture :follower, column_name: proc { |follow| COUNTER_CULTURE_COLUMN_NAME_BY_TYPE[follow.followable_type] },
|
|
column_names: COUNTER_CULTURE_COLUMNS_NAMES
|
|
before_save :calculate_points
|
|
after_create :send_email_notification
|
|
after_save :touch_follower
|
|
|
|
validates :blocked, inclusion: { in: [true, false] }
|
|
validates :followable_id, presence: true
|
|
validates :followable_type, presence: true
|
|
validates :follower_id, presence: true
|
|
validates :follower_type, presence: true
|
|
validates :subscription_status, presence: true, inclusion: { in: %w[all_articles none] }
|
|
|
|
def self.need_new_follower_notification_for?(followable_type)
|
|
%w[User Organization].include?(followable_type)
|
|
end
|
|
|
|
private
|
|
|
|
def calculate_points
|
|
self.points = explicit_points + implicit_points
|
|
end
|
|
|
|
def touch_follower
|
|
follower.touch(:updated_at, :last_followed_at)
|
|
end
|
|
|
|
def send_email_notification
|
|
return unless followable.instance_of?(User) && followable.email?
|
|
|
|
Follows::SendEmailNotificationWorker.perform_async(id)
|
|
end
|
|
end
|