Module: Hub::UserRelation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/hub/user_relation.rb
Instance Method Summary collapse
- #can_publish_topic? ⇒ Boolean
- #feed ⇒ Object
- #follow(other_user) ⇒ Object
- #following?(other_user) ⇒ Boolean
- #like(topic) ⇒ Object
- #liked?(topic) ⇒ Boolean
- #my_participant_topics ⇒ Object
- #my_replies ⇒ Object
- #replied?(topic) ⇒ Boolean
- #unfollow(other_user) ⇒ Object
- #unlike(topic) ⇒ Object
- #unread_notification_count ⇒ Object
Instance Method Details
#can_publish_topic? ⇒ Boolean
74 75 76 77 78 79 |
# File 'app/models/concerns/hub/user_relation.rb', line 74 def can_publish_topic? # 1天之内发送的频率为10 topic_count = topics.where('created_at > ? and created_at < ?', Time.current.beginning_of_day, Time.current.end_of_day).count return false if topic_count >= 10 true end |
#feed ⇒ Object
31 32 33 |
# File 'app/models/concerns/hub/user_relation.rb', line 31 def feed Hub::Topic.where(customer: self).or(Hub::Topic.where(customer: following)).page_includes.recent end |
#follow(other_user) ⇒ Object
35 36 37 |
# File 'app/models/concerns/hub/user_relation.rb', line 35 def follow(other_user) active_relationships.create(followed_customer_id: other_user.id) end |
#following?(other_user) ⇒ Boolean
43 44 45 |
# File 'app/models/concerns/hub/user_relation.rb', line 43 def following?(other_user) active_relationships.find_by(followed_customer_id: other_user.id).present? end |
#like(topic) ⇒ Object
58 59 60 |
# File 'app/models/concerns/hub/user_relation.rb', line 58 def like(topic) topic.likers.create(customer_id: id) end |
#liked?(topic) ⇒ Boolean
66 67 68 |
# File 'app/models/concerns/hub/user_relation.rb', line 66 def liked?(topic) topic.likers.find_by(customer_id: id).present? end |
#my_participant_topics ⇒ Object
51 52 53 54 55 56 |
# File 'app/models/concerns/hub/user_relation.rb', line 51 def my_participant_topics Hub::Topic.joins('left join hub_replies on hub_replies.hubs_topic_id = hub_topics.id') .joins('left join hub_likers on hub_likers.hubs_topic_id = hub_topics.id') .where('hub_replies.customer_id = ? or hub_likers.customer_id = ?', id, id) .group('hub_topics.id') end |
#my_replies ⇒ Object
47 48 49 |
# File 'app/models/concerns/hub/user_relation.rb', line 47 def my_replies replies.or(reply_to_replies) end |
#replied?(topic) ⇒ Boolean
70 71 72 |
# File 'app/models/concerns/hub/user_relation.rb', line 70 def replied?(topic) replies.find_by(topic: topic).present? end |
#unfollow(other_user) ⇒ Object
39 40 41 |
# File 'app/models/concerns/hub/user_relation.rb', line 39 def unfollow(other_user) active_relationships.find_by(followed_customer_id: other_user.id).destroy end |
#unlike(topic) ⇒ Object
62 63 64 |
# File 'app/models/concerns/hub/user_relation.rb', line 62 def unlike(topic) topic.likers.find_by(customer_id: id).destroy end |
#unread_notification_count ⇒ Object
27 28 29 |
# File 'app/models/concerns/hub/user_relation.rb', line 27 def unread_notification_count liker_notifications_count + reply_notifications_count + follower_notifications_count + notifications_count end |