]> git.openstreetmap.org Git - rails.git/blob - app/models/notifier.rb
Add russian pluralization logic, based on description in the russion
[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                          :confirm_string => token.token)
8   end
9
10   def email_confirm(user, token)
11     common_headers user
12     recipients user.new_email
13     subject I18n.t('notifier.email_confirm.subject')
14     body :address => user.new_email,
15          :url => url_for(:host => SERVER_URL,
16                          :controller => "user", :action => "confirm_email",
17                          :confirm_string => token.token)
18   end
19
20   def lost_password(user, token)
21     common_headers user
22     subject I18n.t('notifier.lost_password.subject')
23     body :url => url_for(:host => SERVER_URL,
24                          :controller => "user", :action => "reset_password",
25                          :token => token.token)
26   end
27
28   def gpx_success(trace, possible_points)
29     common_headers trace.user
30     subject I18n.t('notifier.gpx_notification.success.subject')
31     body :trace_name => trace.name,
32          :trace_points => trace.size,
33          :trace_description => trace.description,
34          :trace_tags => trace.tags,
35          :possible_points => possible_points
36   end
37
38   def gpx_failure(trace, error)
39     common_headers trace.user
40     from "webmaster@openstreetmap.org"
41     subject I18n.t('notifier.gpx_notification.failure.subject')
42     body :trace_name => trace.name,
43          :trace_description => trace.description,
44          :trace_tags => trace.tags,
45          :error => error
46   end
47   
48   def message_notification(message)
49     common_headers message.recipient
50     subject I18n.t('notifier.message_notification.subject', :user => message.sender.display_name, :locale => locale)
51     body :to_user => message.recipient.display_name,
52          :from_user => message.sender.display_name,
53          :body => message.body,
54          :title => message.title,
55          :readurl => url_for(:host => SERVER_URL,
56                              :controller => "message", :action => "read",
57                              :message_id => message.id),
58          :replyurl => url_for(:host => SERVER_URL,
59                               :controller => "message", :action => "reply",
60                               :message_id => message.id)
61   end
62
63   def diary_comment_notification(comment)
64     common_headers comment.diary_entry.user
65     subject I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name, :locale => locale)
66     body :to_user => comment.diary_entry.user.display_name,
67          :from_user => comment.user.display_name,
68          :body => comment.body,
69          :title => comment.diary_entry.title,
70          :readurl => url_for(:host => SERVER_URL,
71                              :controller => "diary_entry",
72                              :action => "view",
73                              :display_name => comment.diary_entry.user.display_name,
74                              :id => comment.diary_entry.id,
75                              :anchor => "comment#{comment.id}"),
76          :commenturl => url_for(:host => SERVER_URL,
77                                 :controller => "diary_entry",
78                                 :action => "view",
79                                 :display_name => comment.diary_entry.user.display_name,
80                                 :id => comment.diary_entry.id,
81                                 :anchor => "newcomment"),
82          :replyurl => url_for(:host => SERVER_URL,
83                               :controller => "message",
84                               :action => "new",
85                               :user_id => comment.user.id,
86                               :title => "Re: #{comment.diary_entry.title}")
87   end
88
89   def friend_notification(friend)
90     befriender = User.find_by_id(friend.user_id)
91     befriendee = User.find_by_id(friend.friend_user_id)
92
93     common_headers befriendee
94     subject I18n.t('notifier.friend_notification.subject', :user => befriender.display_name, :locale => locale)
95     body :user => befriender.display_name,
96          :userurl => url_for(:host => SERVER_URL,
97                              :controller => "user", :action => "view",
98                              :display_name => befriender.display_name)
99   end
100
101 private
102
103   def common_headers(recipient)
104     recipients recipient.email
105     locale recipient.preferred_language_from(I18n.available_locales)
106     from "webmaster@openstreetmap.org"
107     headers "return-path" => "bounces@openstreetmap.org",
108             "Auto-Submitted" => "auto-generated"
109   end
110 end