]> git.openstreetmap.org Git - rails.git/blob - app/models/notifier.rb
Make trace API a proper CRUD API like other object types
[rails.git] / app / models / notifier.rb
1 class Notifier < ActionMailer::Base
2   def signup_confirm(user, token)
3     common_headers user
4     subject I18n.t('notifier.signup_confirm.subject')
5     body :url => url_for(:host => SERVER_URL,
6                          :controller => "user", :action => "confirm",
7                          :display_name => user.display_name,
8                          :confirm_string => token.token)
9   end
10
11   def email_confirm(user, token)
12     common_headers user
13     recipients user.new_email
14     subject I18n.t('notifier.email_confirm.subject')
15     body :address => user.new_email,
16          :url => url_for(:host => SERVER_URL,
17                          :controller => "user", :action => "confirm_email",
18                          :confirm_string => token.token)
19   end
20
21   def lost_password(user, token)
22     common_headers user
23     subject I18n.t('notifier.lost_password.subject')
24     body :url => url_for(:host => SERVER_URL,
25                          :controller => "user", :action => "reset_password",
26                          :token => token.token)
27   end
28
29   def gpx_success(trace, possible_points)
30     common_headers trace.user
31     subject I18n.t('notifier.gpx_notification.success.subject')
32     body :trace_name => trace.name,
33          :trace_points => trace.size,
34          :trace_description => trace.description,
35          :trace_tags => trace.tags,
36          :possible_points => possible_points
37   end
38
39   def gpx_failure(trace, error)
40     common_headers trace.user
41     from "webmaster@openstreetmap.org"
42     subject I18n.t('notifier.gpx_notification.failure.subject')
43     body :trace_name => trace.name,
44          :trace_description => trace.description,
45          :trace_tags => trace.tags,
46          :error => error
47   end
48   
49   def message_notification(message)
50     common_headers message.recipient
51     from_header message.sender.display_name, "m", message.id, message.digest
52     subject I18n.t('notifier.message_notification.subject_header', :subject => message.title, :locale => locale)
53     body :to_user => message.recipient.display_name,
54          :from_user => message.sender.display_name,
55          :body => message.body,
56          :title => message.title,
57          :readurl => url_for(:host => SERVER_URL,
58                              :controller => "message", :action => "read",
59                              :message_id => message.id),
60          :replyurl => url_for(:host => SERVER_URL,
61                               :controller => "message", :action => "reply",
62                               :message_id => message.id)
63   end
64
65   def diary_comment_notification(comment)
66     common_headers comment.diary_entry.user
67     from_header comment.user.display_name, "c", comment.id, comment.digest
68     subject I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name, :locale => locale)
69     body :to_user => comment.diary_entry.user.display_name,
70          :from_user => comment.user.display_name,
71          :body => comment.body,
72          :title => comment.diary_entry.title,
73          :readurl => url_for(:host => SERVER_URL,
74                              :controller => "diary_entry",
75                              :action => "view",
76                              :display_name => comment.diary_entry.user.display_name,
77                              :id => comment.diary_entry.id,
78                              :anchor => "comment#{comment.id}"),
79          :commenturl => url_for(:host => SERVER_URL,
80                                 :controller => "diary_entry",
81                                 :action => "view",
82                                 :display_name => comment.diary_entry.user.display_name,
83                                 :id => comment.diary_entry.id,
84                                 :anchor => "newcomment"),
85          :replyurl => url_for(:host => SERVER_URL,
86                               :controller => "message",
87                               :action => "new",
88                               :display_name => comment.user.display_name,
89                               :title => "Re: #{comment.diary_entry.title}")
90   end
91
92   def friend_notification(friend)
93     common_headers friend.befriendee
94     subject I18n.t('notifier.friend_notification.subject', :user => friend.befriender.display_name, :locale => locale)
95     body :friend => friend
96   end
97
98 private
99
100   def common_headers(recipient)
101     recipients recipient.email
102     locale recipient.preferred_language_from(I18n.available_locales)
103     from EMAIL_FROM
104     headers "return-path" => EMAIL_RETURN_PATH,
105             "Auto-Submitted" => "auto-generated"
106   end
107
108   def from_header(name, type, id, digest)
109     if domain = MESSAGES_DOMAIN
110       from quote_address_if_necessary("#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>", "utf-8")
111     end
112   end
113 end