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,13 +14,23 @@ module ActionTrackerHelper | ||
14 | } | 14 | } |
15 | end | 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 | def join_community_description ta | 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 | num: ta.get_resource_name.size, | 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 | link = link_to image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), | 31 | link = link_to image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), |
22 | ta.get_resource_url[i], title: n | 32 | ta.get_resource_url[i], title: n |
23 | - end.join.html_safe | 33 | + end) |
24 | } | 34 | } |
25 | end | 35 | end |
26 | 36 |
app/jobs/notify_activity_to_profiles_job.rb
@@ -22,6 +22,9 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | @@ -22,6 +22,9 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | ||
22 | # Notify all friends | 22 | # Notify all friends |
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})") | 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 | if tracked_action.user.is_a? Organization | 28 | if tracked_action.user.is_a? Organization |
26 | ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + | 29 | ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + |
27 | "select distinct accessor_id, #{tracked_action.id} from role_assignments where resource_id = #{tracked_action.user.id} and resource_type='Profile' " + | 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,9 +580,14 @@ class Person < Profile | ||
580 | person.has_permission?(:manage_friends, self) | 580 | person.has_permission?(:manage_friends, self) |
581 | end | 581 | end |
582 | 582 | ||
583 | + def following_profiles | ||
584 | + Profile.following_profiles self | ||
585 | + end | ||
586 | + | ||
583 | protected | 587 | protected |
584 | 588 | ||
585 | def followed_by?(profile) | 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 | end | 591 | end |
592 | + | ||
588 | end | 593 | end |
app/models/profile.rb
@@ -203,6 +203,12 @@ class Profile < ApplicationRecord | @@ -203,6 +203,12 @@ class Profile < ApplicationRecord | ||
203 | scope :more_active, -> { order 'activities_count DESC' } | 203 | scope :more_active, -> { order 'activities_count DESC' } |
204 | scope :more_recent, -> { order "created_at DESC" } | 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 | acts_as_trackable :dependent => :destroy | 212 | acts_as_trackable :dependent => :destroy |
207 | 213 | ||
208 | has_many :profile_activities | 214 | has_many :profile_activities |
@@ -215,6 +221,9 @@ class Profile < ApplicationRecord | @@ -215,6 +221,9 @@ class Profile < ApplicationRecord | ||
215 | 221 | ||
216 | has_many :email_templates, :foreign_key => :owner_id | 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 | # Although this should be a has_one relation, there are no non-silly names for | 227 | # Although this should be a has_one relation, there are no non-silly names for |
219 | # a foreign key on article to reference the template to which it is | 228 | # a foreign key on article to reference the template to which it is |
220 | # welcome_page... =P | 229 | # welcome_page... =P |
@@ -1136,5 +1145,4 @@ private :generate_url, :url_options | @@ -1136,5 +1145,4 @@ private :generate_url, :url_options | ||
1136 | def allow_invitation_from(person) | 1145 | def allow_invitation_from(person) |
1137 | false | 1146 | false |
1138 | end | 1147 | end |
1139 | - | ||
1140 | end | 1148 | end |
@@ -0,0 +1,9 @@ | @@ -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 @@ | @@ -0,0 +1 @@ | ||
1 | +<%= render :partial => 'default_activity', :locals => { :activity => activity, :tab_action => tab_action } %> |
config/initializers/action_tracker.rb
@@ -12,6 +12,10 @@ ActionTrackerConfig.verbs = { | @@ -12,6 +12,10 @@ ActionTrackerConfig.verbs = { | ||
12 | type: :groupable | 12 | type: :groupable |
13 | }, | 13 | }, |
14 | 14 | ||
15 | + new_follower: { | ||
16 | + type: :groupable | ||
17 | + }, | ||
18 | + | ||
15 | join_community: { | 19 | join_community: { |
16 | type: :groupable | 20 | type: :groupable |
17 | }, | 21 | }, |
db/migrate/20160608123748_create_profile_followers_table.rb
0 → 100644