2014-12-09 22:35:11 +01:00
|
|
|
class NotificationsController < ApplicationController
|
2020-04-19 01:45:50 +02:00
|
|
|
before_action :authenticate_user!
|
2014-12-12 17:54:13 +01:00
|
|
|
|
2014-12-09 22:35:11 +01:00
|
|
|
def index
|
2014-12-14 15:17:52 +01:00
|
|
|
@type = params[:type]
|
2020-04-20 23:03:57 +02:00
|
|
|
@notifications = cursored_notifications_for(type: @type, last_id: params[:last_id])
|
|
|
|
@notifications_last_id = @notifications.map(&:id).min
|
|
|
|
@more_data_available = !cursored_notifications_for(type: @type, last_id: @notifications_last_id, size: 1).count.zero?
|
|
|
|
|
2015-01-08 18:22:27 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
2014-12-09 22:35:11 +01:00
|
|
|
end
|
2020-04-20 23:03:57 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def cursored_notifications_for(type:, last_id:, size: nil)
|
|
|
|
cursor_params = { last_id: last_id, size: size }.compact
|
|
|
|
|
|
|
|
case type
|
|
|
|
when 'all'
|
|
|
|
Notification.cursored_for(current_user, **cursor_params)
|
|
|
|
when 'new'
|
|
|
|
Notification.cursored_for(current_user, new: true, **cursor_params)
|
|
|
|
else
|
|
|
|
Notification.cursored_for_type(current_user, type, **cursor_params)
|
|
|
|
end
|
|
|
|
end
|
2014-12-09 22:35:11 +01:00
|
|
|
end
|