Commit f7238306 authored by Wei-Meng Lee's avatar Wei-Meng Lee

Simplify logic using new group notification settings method

parent 03e08ab7
...@@ -156,23 +156,11 @@ class NotificationRecipient ...@@ -156,23 +156,11 @@ class NotificationRecipient
# Returns the notification_setting of the lowest group in hierarchy with non global level # Returns the notification_setting of the lowest group in hierarchy with non global level
def closest_non_global_group_notification_settting def closest_non_global_group_notification_settting
return unless @group return unless @group
return if indexed_group_notification_settings.empty?
notification_setting = nil @group
.notification_settings(hierarchy_order: :asc)
@group.self_and_ancestors_ids.each do |id| .where(user: user)
notification_setting = indexed_group_notification_settings[id] .where.not(level: NotificationSetting.levels[:global])
break if notification_setting .first
end
notification_setting
end
def indexed_group_notification_settings
strong_memoize(:indexed_group_notification_settings) do
@group.notification_settings.where(user_id: user.id)
.where.not(level: NotificationSetting.levels[:global])
.index_by(&:source_id)
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment