]> git.openstreetmap.org Git - rails.git/blob - app/models/notifier.rb
Changed required version of OAuth gem, as that exact version wasn't necessary.
[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                          :email => user.email, :token => token.token)
26   end
27
28   def reset_password(user, pass)
29     common_headers user
30     subject I18n.t('notifier.reset_password.subject')
31     body :pass => pass
32   end
33
34   def gpx_success(trace, possible_points)
35     common_headers trace.user
36     subject I18n.t('notifier.gpx_notification.success.subject')
37     body :trace_name => trace.name,
38          :trace_points => trace.size,
39          :trace_description => trace.description,
40          :trace_tags => trace.tags,
41          :possible_points => possible_points
42   end
43
44   def gpx_failure(trace, error)
45     common_headers trace.user
46     from "webmaster@openstreetmap.org"
47     subject I18n.t('notifier.gpx_notification.failure.subject')
48     body :trace_name => trace.name,
49          :trace_description => trace.description,
50          :trace_tags => trace.tags,
51          :error => error
52   end
53   
54   def message_notification(message)
55     common_headers message.recipient
56     subject I18n.t('notifier.message_notification.subject', :user => message.sender.display_name, :locale => locale)
57     body :to_user => message.recipient.display_name,
58          :from_user => message.sender.display_name,
59          :body => message.body,
60          :title => message.title,
61          :readurl => url_for(:host => SERVER_URL,
62                              :controller => "message", :action => "read",
63                              :message_id => message.id),
64          :replyurl => url_for(:host => SERVER_URL,
65                               :controller => "message", :action => "reply",
66                               :message_id => message.id)
67   end
68
69   def diary_comment_notification(comment)
70     common_headers comment.diary_entry.user
71     subject I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name, :locale => locale)
72     body :to_user => comment.diary_entry.user.display_name,
73          :from_user => comment.user.display_name,
74          :body => comment.body,
75          :title => comment.diary_entry.title,
76          :readurl => 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 => "comment#{comment.id}"),
82          :commenturl => url_for(:host => SERVER_URL,
83                                 :controller => "diary_entry",
84                                 :action => "view",
85                                 :display_name => comment.diary_entry.user.display_name,
86                                 :id => comment.diary_entry.id,
87                                 :anchor => "newcomment"),
88          :replyurl => url_for(:host => SERVER_URL,
89                               :controller => "message",
90                               :action => "new",
91                               :user_id => comment.user.id,
92                               :title => "Re: #{comment.diary_entry.title}")
93   end
94
95   def friend_notification(friend)
96     befriender = User.find_by_id(friend.user_id)
97     befriendee = User.find_by_id(friend.friend_user_id)
98
99     common_headers befriendee
100     subject I18n.t('notifier.friend_notification.subject', :user => befriender.display_name, :locale => locale)
101     body :user => befriender.display_name,
102          :userurl => url_for(:host => SERVER_URL,
103                              :controller => "user", :action => "view",
104                              :display_name => befriender.display_name)
105   end
106
107 private
108
109   def common_headers(recipient)
110     recipients recipient.email
111     locale recipient.preferred_language_from(I18n.available_locales)
112     from "webmaster@openstreetmap.org"
113     headers "return-path" => "bounces@openstreetmap.org",
114             "Auto-Submitted" => "auto-generated"
115   end
116 end