Class: UserNotificationTotalSerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/user_notification_total_serializer.rb

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#group_inboxesObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/serializers/user_notification_total_serializer.rb', line 35

def group_inboxes
  group_inbox_data =
    Notification
      .unread
      .where(
        user_id: scope.user.id,
        notification_type: Notification.types[:group_message_summary],
      )
      .pluck(:data)

  results = []

  return results if group_inbox_data.blank?

  group_inbox_data.map do |json|
    data = JSON.parse(json, symbolize_names: true)

    results << {
      group_id: data[:group_id],
      group_name: data[:group_name],
      count: data[:inbox_count],
    }
  end

  results
end

#include_unread_personal_messages?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/serializers/user_notification_total_serializer.rb', line 15

def include_unread_personal_messages?
  object.in_any_groups?(SiteSetting.personal_message_enabled_groups_map)
end

#include_unseen_reviewables?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/serializers/user_notification_total_serializer.rb', line 23

def include_unseen_reviewables?
  scope.user.staff?
end

#new_personal_messages_notifications_countObject



62
63
64
# File 'app/serializers/user_notification_total_serializer.rb', line 62

def new_personal_messages_notifications_count
  @new_personal_messages_notifications_count ||= object.new_personal_messages_notifications_count
end

#topic_trackingObject



31
32
33
# File 'app/serializers/user_notification_total_serializer.rb', line 31

def topic_tracking
  TopicTrackingState.report_totals(object)
end

#unread_notificationsObject



11
12
13
# File 'app/serializers/user_notification_total_serializer.rb', line 11

def unread_notifications
  object.all_unread_notifications_count - new_personal_messages_notifications_count
end

#unread_personal_messagesObject



19
20
21
# File 'app/serializers/user_notification_total_serializer.rb', line 19

def unread_personal_messages
  new_personal_messages_notifications_count
end

#unseen_reviewablesObject



27
28
29
# File 'app/serializers/user_notification_total_serializer.rb', line 27

def unseen_reviewables
  Reviewable.unseen_reviewable_count(object)
end