diff --git a/app/assets/javascripts/initializers/initNotifications.js b/app/assets/javascripts/initializers/initNotifications.js
index a2a44d12a..2b2cd6233 100644
--- a/app/assets/javascripts/initializers/initNotifications.js
+++ b/app/assets/javascripts/initializers/initNotifications.js
@@ -3,6 +3,7 @@ function initNotifications() {
markNotificationsAsRead();
initReactions();
listenForNotificationsBellClick();
+ initPagination();
}
function markNotificationsAsRead() {
@@ -116,3 +117,19 @@ function listenForNotificationsBellClick() {
};
}, 180);
}
+
+function initPagination() {
+ var el = document.getElementById("notifications-pagination")
+ if (el) {
+ window.fetch(el.dataset.paginationPath, {
+ method: 'GET',
+ credentials: 'same-origin'
+ }).then(function (response) {
+ if (response.status === 200) {
+ response.text().then(function(html){
+ el.innerHTML = html
+ });
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb
index 377a053e4..179ae13d4 100644
--- a/app/controllers/notifications_controller.rb
+++ b/app/controllers/notifications_controller.rb
@@ -8,21 +8,28 @@ class NotificationsController < ApplicationController
else
current_user
end
- if params[:filter].to_s.downcase == "posts"
- @notifications = NotificationDecorator.
- decorate_collection(Notification.where(user_id: current_user.id, notifiable_type: "Article", action: "Published").
- order("notified_at DESC").limit(55).to_a)
- elsif params[:filter].to_s.downcase == "comments"
- @notifications = NotificationDecorator.
- decorate_collection(Notification.where(user_id: current_user.id, notifiable_type: "Comment", action: nil). # Nil action means not reaction in this context
- order("notified_at DESC").limit(55).to_a)
+ if params[:page]
+ num = 48
+ notified_at_offset = Notification.find(params[:page])&.notified_at
else
- @notifications = NotificationDecorator.
- decorate_collection(Notification.where(user_id: current_user.id).
- order("notified_at DESC").limit(55).to_a)
+ num = 12
+ end
+ if params[:filter].to_s.downcase == "posts"
+ @notifications = Notification.where(user_id: current_user.id, notifiable_type: "Article", action: "Published").
+ order("notified_at DESC")
+ elsif params[:filter].to_s.downcase == "comments"
+ @notifications = Notification.where(user_id: current_user.id, notifiable_type: "Comment", action: nil). # Nil action means not reaction in this context
+ or(Notification.where(user_id: current_user.id, notifiable_type: "Mention")).
+ order("notified_at DESC")
+ else
+ @notifications = Notification.where(user_id: current_user.id).
+ order("notified_at DESC")
end
@last_user_reaction = @user.reactions.last&.id
@last_user_comment = @user.comments.last&.id
+ @notifications = @notifications.where("notified_at < ?", notified_at_offset) if notified_at_offset
+ @notifications = NotificationDecorator.decorate_collection(@notifications.limit(num))
+ render partial: "notifications_list" if notified_at_offset
end
end
diff --git a/app/views/notifications/_aggregated_reactions.html.erb b/app/views/notifications/_aggregated_reactions.html.erb
index 515198c57..f77b4a45a 100644
--- a/app/views/notifications/_aggregated_reactions.html.erb
+++ b/app/views/notifications/_aggregated_reactions.html.erb
@@ -1,9 +1,8 @@
<%# TODO: change to map of IDs %>
<% siblings = notification.json_data["reaction"]["aggregated_siblings"].select{|n| n["created_at"] > 24.hours.ago } %>
-<% cache "activity-aggregated-reactions-#{siblings}_#{siblings}" do %>
+<% cache "activity-aggregated-reactions-#{siblings}" do %>
<% actors = siblings.map { |n| n["user"] }.uniq %>
<% reactable_data = notification.json_data["reaction"]["reactable"] %>
-
<% cache "activity-profile-pic-#{actors.first["id"]}-#{actors.first["profile_image_90"]}" do %>
" class="small-pic-link-wrapper">
"/>
<% end %>
- <% reply = Comment.select(:id, :user_id, :ancestry).find_by(id: json_data["comment"]["id"]).children.find_by(user_id: current_user.id) %>
- <% if reply %>
-
- <% else %>
-
- <% end %>
-