Fix notifications page crashing on reactions

This commit is contained in:
Karina Kwiatek 2022-03-26 12:18:38 +01:00 committed by Karina Kwiatek
parent 0cfe5ee964
commit f20e407cc3
2 changed files with 7 additions and 2 deletions

View File

@ -1,8 +1,13 @@
class NotificationsController < ApplicationController class NotificationsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
TYPE_MAPPINGS = {
'smile' => 'appendable::reaction',
'reaction' => 'appendable::reaction',
}.freeze
def index def index
@type = params[:type] @type = TYPE_MAPPINGS[params[:type]] || params[:type]
@notifications = cursored_notifications_for(type: @type, last_id: params[:last_id]) @notifications = cursored_notifications_for(type: @type, last_id: params[:last_id])
@notifications_last_id = @notifications.map(&:id).min @notifications_last_id = @notifications.map(&:id).min
@more_data_available = !cursored_notifications_for(type: @type, last_id: @notifications_last_id, size: 1).count.zero? @more_data_available = !cursored_notifications_for(type: @type, last_id: @notifications_last_id, size: 1).count.zero?

View File

@ -13,7 +13,7 @@
- @notifications.each do |notification| - @notifications.each do |notification|
%li.list-group-item %li.list-group-item
.media .media
= render "notifications/type/#{notification.target_type.downcase}", notification: notification = render "notifications/type/#{notification.target_type.downcase.split('::').last}", notification: notification
- unless @notifications.count.zero? - unless @notifications.count.zero?
= render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @notifications_last_id, permitted_params: %i[type] = render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @notifications_last_id, permitted_params: %i[type]