From f1571184bc3e057d48483bf3e98095a745f6c3b9 Mon Sep 17 00:00:00 2001 From: Andy Zhao Date: Sat, 19 May 2018 11:03:06 -0400 Subject: [PATCH] [Updated] Add aggregated follow notifications (#327) * Fix sidebar issue for XL displays * Remove grouping param for follows * Add aggregated follow notification MVP * Lint reaction model a bit * Fix a few small css issues * Remove puts statement and indent HTML * Use activity id instead of time for cache key --- app/assets/stylesheets/articles.scss | 15 +++++++ app/assets/stylesheets/notifications.scss | 3 ++ app/models/follow.rb | 6 --- app/models/reaction.rb | 4 +- .../_aggregated_follows.html.erb | 44 +++++++++++++++++++ .../activity/activities/_follow.html.erb | 2 +- app/views/notifications/index.html.erb | 10 +++-- 7 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 app/views/notifications/_aggregated_follows.html.erb diff --git a/app/assets/stylesheets/articles.scss b/app/assets/stylesheets/articles.scss index 853581862..20fbc903e 100644 --- a/app/assets/stylesheets/articles.scss +++ b/app/assets/stylesheets/articles.scss @@ -13,6 +13,9 @@ @media screen and ( min-width: 950px ){ margin-top:26px; } + @media screen and ( min-width: 2650px ){ + max-width: 1300px; + } &.sub-home{ margin-top:10px; .side-bar{ @@ -232,6 +235,18 @@ opacity:0.9; } } + .tiny-pic{ + display: inline-block; + height: 30px; + width: 30px; + img{ + height:100%; + width:100%; + &.round{ + border-radius: 30px; + } + } + } .content{ float:left; width:calc(100% - 75px); diff --git a/app/assets/stylesheets/notifications.scss b/app/assets/stylesheets/notifications.scss index 17fc37c87..c76373311 100644 --- a/app/assets/stylesheets/notifications.scss +++ b/app/assets/stylesheets/notifications.scss @@ -110,6 +110,9 @@ font-size:0.8em; opacity:0.9; } + .follower-pic-row{ + display: inline-block; + } } .comment-link-wrapper{ display:block; diff --git a/app/models/follow.rb b/app/models/follow.rb index af8fd8cc6..45677cf6e 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -30,7 +30,6 @@ class Follow < ApplicationRecord validates :followable_id, uniqueness: { scope: [:followable_type, :follower_id] } - def activity_actor follower end @@ -44,10 +43,6 @@ class Follow < ApplicationRecord followable end - def activity_target - return "follow_#{Time.now}" - end - def remove_from_feed super if followable_type == "User" @@ -76,5 +71,4 @@ class Follow < ApplicationRecord end end handle_asynchronously :send_email_notification - end diff --git a/app/models/reaction.rb b/app/models/reaction.rb index 2935117c8..9aac613f1 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -34,7 +34,7 @@ class Reaction < ApplicationRecord self.includes(:reactable). where(reactable_type: "Article", user_id: user.id). where("created_at > ?", 5.days.ago). - select('distinct on (reactable_id) *'). + select("distinct on (reactable_id) *"). take(15) end @@ -50,7 +50,7 @@ class Reaction < ApplicationRecord def activity_notify return if user_id == reactable.user_id - return if points < 0 + return if points.negative? [StreamNotifier.new(reactable.user.id).notify] end diff --git a/app/views/notifications/_aggregated_follows.html.erb b/app/views/notifications/_aggregated_follows.html.erb new file mode 100644 index 000000000..11659e591 --- /dev/null +++ b/app/views/notifications/_aggregated_follows.html.erb @@ -0,0 +1,44 @@ +<% cache "activity-aggregated-follows-#{group['activities'].last['id']}_#{group['activities'].first['id']}_#{group['is_seen']}" do %> + <% unless group['activities'][0]['object'].class.name == "String" %> + <% followers = group['activities'].map { |a| a['actor'] } %> +
+ <% cache "activity-profile-pic-#{followers.first.id}-#{followers.first.profile_image_url}" do %> + +
+ <%= followers.first.name %> +
+
+ <% end %> +
+ <% if followers.size == 1 %> + <% followers.first.name %> followed you! + <%= follow_button(activity['actor'], "follow-back") %> + <% elsif followers.size == 2 %> +
+
+ + <%= followers.last.name %> + +
+
+
+ <%= followers.first.name %> and + <%= followers.second.name %> followed you! + <% else %> +
+ <% followers.first(10)[1..-1].each do |follower| %> +
+ + <%= follower.name %> + +
+ <% end %> +
+
+ <%= followers.first.name %> + and <%= followers.size %> others followed you! + <% end %> +
+
+ <% end %> +<% end %> diff --git a/app/views/notifications/activity/activities/_follow.html.erb b/app/views/notifications/activity/activities/_follow.html.erb index fa941bc41..51289e9a3 100644 --- a/app/views/notifications/activity/activities/_follow.html.erb +++ b/app/views/notifications/activity/activities/_follow.html.erb @@ -7,7 +7,7 @@ <% end %> <% cache "activity-follow-button-#{activity['actor'].path}-#{activity['actor'].name}" do %>
- <%= activity['actor'].name %> followed you + <%= activity['actor'].name %> followed you! <%= follow_button(activity['actor'], "follow-back") %>
<% end %> \ No newline at end of file diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index aa8cfb585..f1c66da9f 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -31,20 +31,24 @@
<% if user_signed_in? %> - <% if @activities.size > 0%> + <% if @activities.size > 0 %> <% cache "notifications-fragment-#{current_user.last_notification_activity}-#{current_user.updated_at.to_s}-#{current_user.id}", expires_in: 15.minutes do %> <% @activities.each do |group| %> <% cache "notifications-fragment-#{group["is_seen"].to_s}-#{group["id"].to_s}-#{group.to_s.size}-#{@last_user_reaction}-#{@last_user_comment}" do %> <% if current_user.id == 1 || Rails.env.development? %> <% if group['verb'] == "Reaction" && group['activity_count'] > 1 %> - <%= render "notifications/aggregated_reactions", group:group %> + <%= render "notifications/aggregated_reactions", group: group %> + <% elsif group['verb'] == "Follow" && group['activity_count'] > 1 %> + <%= render "notifications/aggregated_follows", group: group %> <% else %> <%= render_activity(group, partial_root: '/notifications/activity') %> <% end %> <% else %> <% begin %> <% if group['verb'] == "Reaction" && group['activity_count'] > 1 %> - <%= render "notifications/aggregated_reactions", group:group %> + <%= render "notifications/aggregated_reactions", group: group %> + <% elsif group['verb'] == "Follow" && group['activity_count'] > 1 %> + <%= render "notifications/aggregated_follows", group: group %> <% else %> <%= render_activity(group, partial_root: '/notifications/activity') %> <% end %>