]> git.openstreetmap.org Git - rails.git/blob - app/models/notifier.rb
Send email notifications when people comment on diary entries. Closes #655.
[rails.git] / app / models / notifier.rb
1 class Notifier < ActionMailer::Base
2   def signup_confirm(user, token)
3     recipients user.email
4     from "webmaster@openstreetmap.org"
5     subject "[OpenStreetMap] Confirm your email address"
6     headers "Auto-Submitted" => "auto-generated"
7     body :url => url_for(:host => SERVER_URL,
8                          :controller => "user", :action => "confirm",
9                          :confirm_string => token.token)
10   end
11
12   def lost_password(user, token)
13     recipients user.email
14     from "webmaster@openstreetmap.org"
15     subject "[OpenStreetMap] Password reset request"
16     headers "Auto-Submitted" => "auto-generated"
17     body :url => url_for(:host => SERVER_URL,
18                          :controller => "user", :action => "reset_password",
19                          :email => user.email, :token => token.token)
20   end
21
22   def reset_password(user, pass)
23     recipients user.email
24     from "webmaster@openstreetmap.org"
25     subject "[OpenStreetMap] Password reset"
26     headers "Auto-Submitted" => "auto-generated"
27     body :pass => pass
28   end
29
30   def gpx_success(trace, possible_points)
31     recipients trace.user.email
32     from "webmaster@openstreetmap.org"
33     subject "[OpenStreetMap] GPX Import success"
34     headers "Auto-Submitted" => "auto-generated"
35     body :trace_name => trace.name,
36          :trace_points => trace.size,
37          :possible_points => possible_points
38   end
39
40   def gpx_failure(trace, error)
41     recipients trace.user.email
42     from "webmaster@openstreetmap.org"
43     subject "[OpenStreetMap] GPX Import failure"
44     headers "Auto-Submitted" => "auto-generated"
45     body :trace_name => trace.name,
46          :error => error
47   end
48   
49   def message_notification(message)
50     recipients message.recipient.email
51     from "webmaster@openstreetmap.org"
52     subject "[OpenStreetMap] #{message.sender.display_name} sent you a new message"
53     headers "Auto-Submitted" => "auto-generated"
54     body :to_user => message.recipient.display_name,
55          :from_user => message.sender.display_name,
56          :body => message.body,
57          :subject => message.title,
58          :readurl => url_for(:host => SERVER_URL,
59                              :controller => "message", :action => "read",
60                              :message_id => message.id),
61          :replyurl => url_for(:host => SERVER_URL,
62                               :controller => "message", :action => "reply",
63                               :message_id => message.id)
64   end
65
66   def diary_comment_notification(comment)
67     recipients comment.diary_entry.user.email
68     from "webmaster@openstreetmap.org"
69     subject "[OpenStreetMap] #{comment.user.display_name} commented on your diary entry"
70     headers "Auto-Submitted" => "auto-generated"
71     body :to_user => comment.diary_entry.user.display_name,
72          :from_user => comment.user.display_name,
73          :body => comment.body,
74          :subject => comment.diary_entry.title,
75          :readurl => url_for(:host => SERVER_URL,
76                              :controller => "diary_entry",
77                              :action => "view",
78                              :display_name => comment.diary_entry.user.display_name,
79                              :id => comment.diary_entry.id,
80                              :anchor => "comment#{comment.id}"),
81          :commenturl => url_for(:host => SERVER_URL,
82                                 :controller => "diary_entry",
83                                 :action => "view",
84                                 :display_name => comment.diary_entry.user.display_name,
85                                 :id => comment.diary_entry.id,
86                                 :anchor => "newcomment"),
87          :replyurl => url_for(:host => SERVER_URL,
88                               :controller => "message",
89                               :action => "new",
90                               :user_id => comment.user.id,
91                               :title => "Re: #{comment.diary_entry.title}")
92   end
93
94   def friend_notification(friend)
95     befriender = User.find_by_id(friend.user_id)
96     befriendee = User.find_by_id(friend.friend_user_id)
97
98     recipients befriendee.email
99     from "webmaster@openstreetmap.org"
100     subject "[OpenStreetMap] #{befriender.display_name} added you as a friend"
101     headers "Auto-Submitted" => "auto-generated"
102     body :user => befriender.display_name,
103          :userurl => url_for(:host => SERVER_URL,
104                              :controller => "user", :action => "view",
105                              :display_name => befriender.display_name)
106   end
107 end