1 # frozen_string_literal: true
3 class UserNotifications
5 def self.from(notification)
6 event_type_name = event_type_name_of(notification)
7 klass = "UserNotifications::#{event_type_name}Notification".constantize
8 klass.new(notification)
11 # Takes "ChangesetCommentNotifier::Notification", returns "ChangesetComment"
12 def self.event_type_name_of(notification)
13 notification.class.name.sub("Notifier::Notification", "")
16 def initialize(notification)
17 @notification = notification
20 delegate :record, :to => :@notification
23 event_type_name = self.class.event_type_name_of(@notification)
24 "notifications/#{event_type_name.underscore}"
32 class ChangesetCommentNotification < Notification
33 delegate :changeset, :to => :record
34 delegate :id, :to => :changeset, :prefix => true
53 class DiaryCommentNotification < Notification
54 delegate :body, :to => :record
55 delegate :diary_entry, :to => :record
56 delegate :title, :to => :diary_entry, :prefix => true
75 class GpxImportFailureNotification < Notification
77 @notification.created_at
81 @notification.params[:trace_name]
85 @notification.params[:trace_description]
89 @notification.params[:trace_tags]
92 def trace_possible_points
101 @notification.params[:error]
105 class GpxImportSuccessNotification < Notification
106 delegate :timestamp, :to => :record
112 def trace_description
117 record.tags.map(&:tag)
120 def trace_possible_points
121 @notification.params[:possible_points]
128 delegate :user, :to => :record
131 class NewFollowerNotification < Notification
132 delegate :follower, :to => :record
135 class NoteCommentNotification < Notification
136 delegate :note, :to => :record
137 delegate :event, :to => :record
138 delegate :id, :to => :note, :prefix => true
159 LISTABLE_NOTIFICATIONS = %w[
160 ChangesetCommentNotifier::Notification
161 DiaryCommentNotifier::Notification
162 GpxImportFailureNotifier::Notification
163 GpxImportSuccessNotifier::Notification
164 NewFollowerNotifier::Notification
165 NoteCommentNotifier::Notification
168 def self.wrap(notification_records)
169 notification_records.map { |record| Notification.from(record) }
176 def notification_records(&)
179 .where(:type => LISTABLE_NOTIFICATIONS)