Commit d23ec096e7046f3b34262f11a6f0a77e9f5bfc48
1 parent
160be2a2
Exists in
federation_followers_backend
and in
1 other branch
Adds backend to profile followers feature
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Victor Matias Navarro <victor.matias.navarro@gmail.com> Signed-off-by: Vitor Barbosa <vitormga15@gmail.com>
Showing
8 changed files
with
53 additions
and
5 deletions
Show diff stats
app/helpers/action_tracker_helper.rb
... | ... | @@ -14,13 +14,23 @@ module ActionTrackerHelper |
14 | 14 | } |
15 | 15 | end |
16 | 16 | |
17 | + def new_follower_description ta | |
18 | + n_('has followed 1 new profile:<br />%{name}', 'has followed %{num} new profiles:<br />%{name}', ta.get_follower_name.size).html_safe % { | |
19 | + num: ta.get_follower_name.size, | |
20 | + name: safe_join(ta.collect_group_with_index(:follower_name) do |n,i| | |
21 | + link_to image_tag(ta.get_follower_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/person-icon.png")), | |
22 | + ta.get_follower_url[i], title: n | |
23 | + end) | |
24 | + } | |
25 | + end | |
26 | + | |
17 | 27 | def join_community_description ta |
18 | - n_('has joined 1 community:<br />%{name}'.html_safe, 'has joined %{num} communities:<br />%{name}'.html_safe, ta.get_resource_name.size) % { | |
28 | + n_('has joined 1 community:<br />%{name}', 'has joined %{num} communities:<br />%{name}', ta.get_resource_name.size).html_safe % { | |
19 | 29 | num: ta.get_resource_name.size, |
20 | - name: ta.collect_group_with_index(:resource_name) do |n,i| | |
30 | + name: safe_join(ta.collect_group_with_index(:resource_name) do |n,i| | |
21 | 31 | link = link_to image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), |
22 | 32 | ta.get_resource_url[i], title: n |
23 | - end.join.html_safe | |
33 | + end) | |
24 | 34 | } |
25 | 35 | end |
26 | 36 | ... | ... |
app/jobs/notify_activity_to_profiles_job.rb
... | ... | @@ -22,6 +22,9 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) |
22 | 22 | # Notify all friends |
23 | 23 | ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select f.friend_id, #{tracked_action.id} from friendships as f where person_id=#{tracked_action.user.id} and f.friend_id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id})") |
24 | 24 | |
25 | + # Notify all followers | |
26 | + ActionTrackerNotification.connection.execute("INSERT INTO action_tracker_notifications(profile_id, action_tracker_id) SELECT f.follower_id, #{tracked_action.id} FROM profile_followers AS f WHERE profile_id=#{tracked_action.user.id} AND (f.follower_id NOT IN (SELECT atn.profile_id FROM action_tracker_notifications AS atn WHERE atn.action_tracker_id = #{tracked_action.id})) AND (f.follower_id IN SELECT friendships.friend_id FROM friendships WHERE friendships.person_id = #{tracked_action.user.id} OR SELECT profiles.public FROM profiles where id=#{tracked_action.user.id})") | |
27 | + | |
25 | 28 | if tracked_action.user.is_a? Organization |
26 | 29 | ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + |
27 | 30 | "select distinct accessor_id, #{tracked_action.id} from role_assignments where resource_id = #{tracked_action.user.id} and resource_type='Profile' " + | ... | ... |
app/models/person.rb
... | ... | @@ -580,9 +580,14 @@ class Person < Profile |
580 | 580 | person.has_permission?(:manage_friends, self) |
581 | 581 | end |
582 | 582 | |
583 | + def following_profiles | |
584 | + Profile.following_profiles self | |
585 | + end | |
586 | + | |
583 | 587 | protected |
584 | 588 | |
585 | 589 | def followed_by?(profile) |
586 | - self == profile || self.is_a_friend?(profile) | |
590 | + self == profile || self.is_a_friend?(profile) || self.followers.include(profile) | |
587 | 591 | end |
592 | + | |
588 | 593 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -203,6 +203,12 @@ class Profile < ApplicationRecord |
203 | 203 | scope :more_active, -> { order 'activities_count DESC' } |
204 | 204 | scope :more_recent, -> { order "created_at DESC" } |
205 | 205 | |
206 | + scope :following_profiles, -> person { | |
207 | + distinct.select('profiles.*'). | |
208 | + joins('join profile_followers ON profile_followers.profile_id = profiles.id'). | |
209 | + where('profile_followers.follower_id = ?', person.id) | |
210 | + } | |
211 | + | |
206 | 212 | acts_as_trackable :dependent => :destroy |
207 | 213 | |
208 | 214 | has_many :profile_activities |
... | ... | @@ -215,6 +221,9 @@ class Profile < ApplicationRecord |
215 | 221 | |
216 | 222 | has_many :email_templates, :foreign_key => :owner_id |
217 | 223 | |
224 | + has_many :profile_followers | |
225 | + has_many :followers, :class_name => 'Person', :through => :profile_followers | |
226 | + | |
218 | 227 | # Although this should be a has_one relation, there are no non-silly names for |
219 | 228 | # a foreign key on article to reference the template to which it is |
220 | 229 | # welcome_page... =P |
... | ... | @@ -1136,5 +1145,4 @@ private :generate_url, :url_options |
1136 | 1145 | def allow_invitation_from(person) |
1137 | 1146 | false |
1138 | 1147 | end |
1139 | - | |
1140 | 1148 | end | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | +class ProfileFollower < ApplicationRecord | |
2 | + track_actions :new_follower, :after_create, :keep_params => ["follower.name", "follower.url", "follower.profile_custom_icon"], :custom_user => :profile | |
3 | + | |
4 | + belongs_to :profile, :foreign_key => :profile_id | |
5 | + belongs_to :follower, :class_name => 'Person', :foreign_key => :follower_id | |
6 | + | |
7 | + validates_presence_of :profile_id, :follower_id | |
8 | + | |
9 | +end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= render :partial => 'default_activity', :locals => { :activity => activity, :tab_action => tab_action } %> | ... | ... |
config/initializers/action_tracker.rb
db/migrate/20160608123748_create_profile_followers_table.rb
0 → 100644