[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
This commit is contained in:
parent
95891897b7
commit
f1571184bc
7 changed files with 72 additions and 12 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -110,6 +110,9 @@
|
|||
font-size:0.8em;
|
||||
opacity:0.9;
|
||||
}
|
||||
.follower-pic-row{
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
.comment-link-wrapper{
|
||||
display:block;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
44
app/views/notifications/_aggregated_follows.html.erb
Normal file
44
app/views/notifications/_aggregated_follows.html.erb
Normal file
|
|
@ -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'] } %>
|
||||
<div class="single-article single-article-small-pic <%= 'unseen' if group['is_seen'] == false %>">
|
||||
<% cache "activity-profile-pic-#{followers.first.id}-#{followers.first.profile_image_url}" do %>
|
||||
<a href="<%= followers.first.path %>" class="small-pic-link-wrapper">
|
||||
<div class="small-pic">
|
||||
<img src="<%= ProfileImage.new(followers.first).get %>" alt="<%= followers.first.name %>">
|
||||
</div>
|
||||
</a>
|
||||
<% end %>
|
||||
<div class="content notification-content reaction-content">
|
||||
<% if followers.size == 1 %>
|
||||
<a href="<%= followers.first.path %>"><% followers.first.name %></a> followed you!
|
||||
<%= follow_button(activity['actor'], "follow-back") %>
|
||||
<% elsif followers.size == 2 %>
|
||||
<div class="follower-pic-row">
|
||||
<div class="tiny-pic">
|
||||
<a href="<%= followers.last.path %>">
|
||||
<img src="<%= ProfileImage.new(followers.last).get %>" alt="<%= followers.last.name %>" class="round">
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<a href="<%= followers.first.path %>"><%= followers.first.name %></a> and
|
||||
<a href="<%= followers.second.path %>"><%= followers.second.name %></a> followed you!
|
||||
<% else %>
|
||||
<div class="follower-pic-row">
|
||||
<% followers.first(10)[1..-1].each do |follower| %>
|
||||
<div class="tiny-pic">
|
||||
<a href="<%= follower.path %>">
|
||||
<img src="<%= ProfileImage.new(follower).get %>" alt="<%= follower.name %>" class="round">
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<br>
|
||||
<a href="<%= followers.first.path %>"><%= followers.first.name %></a>
|
||||
and <%= followers.size %> others followed you!
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<% end %>
|
||||
<% cache "activity-follow-button-#{activity['actor'].path}-#{activity['actor'].name}" do %>
|
||||
<div class="content notification-content comment-content">
|
||||
<a href="<%= activity['actor'].path %>"><%= activity['actor'].name %></a> followed you
|
||||
<a href="<%= activity['actor'].path %>"><%= activity['actor'].name %></a> followed you!
|
||||
<%= follow_button(activity['actor'], "follow-back") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
@ -31,20 +31,24 @@
|
|||
<div class="side-bar"></div>
|
||||
<div class="articles-list" id="articles-list">
|
||||
<% 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 %>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue