@@ -28,22 +28,6 @@ def forgot_password(user, opts={})
2828 build_email ( user . email , template : "user_notifications.forgot_password" , email_token : opts [ :email_token ] )
2929 end
3030
31- def private_message ( user , opts = { } )
32- post = opts [ :post ]
33- build_email user . email ,
34- template : "user_notifications.private_message" ,
35- message : post . raw ,
36- url : post . url ,
37- subject_prefix : "[#{ I18n . t ( 'private_message_abbrev' ) } ] #{ post . post_number != 1 ? 're: ' : '' } " ,
38- topic_title : post . topic . title ,
39- private_message_from : post . user . name ,
40- from_alias : I18n . t ( :via , username : post . user . name , site_name : SiteSetting . title ) ,
41- add_unsubscribe_link : true ,
42- allow_reply_by_email : true ,
43- post_id : post . id ,
44- topic_id : post . topic_id
45- end
46-
4731 def digest ( user , opts = { } )
4832 @user = user
4933 @base_url = Discourse . base_url
@@ -92,6 +76,15 @@ def user_posted(user, opts)
9276 notification_email ( user , opts )
9377 end
9478
79+ def user_private_message ( user , opts )
80+ opts [ :allow_reply_by_email ] = true
81+
82+ # We use the 'user_posted' event when you are emailed a post in a PM.
83+ opts [ :notification_type ] = 'posted'
84+
85+ notification_email ( user , opts )
86+ end
87+
9588 protected
9689
9790 def email_post_markdown ( post )
@@ -112,7 +105,7 @@ def notification_email(user, opts)
112105 return unless @post = opts [ :post ]
113106
114107 username = @notification . data_hash [ :display_username ]
115- notification_type = Notification . types [ @notification . notification_type ] . to_s
108+ notification_type = opts [ :notification_type ] || Notification . types [ @notification . notification_type ] . to_s
116109
117110 context = ""
118111 context_posts = Post . where ( topic_id : @post . topic_id )
@@ -128,11 +121,14 @@ def notification_email(user, opts)
128121 end
129122
130123 html = UserNotificationRenderer . new ( Rails . configuration . paths [ "app/views" ] ) . render (
131- template : 'email/notification' ,
132- format : :html ,
133- locals : { context_posts : context_posts , post : @post }
124+ template : 'email/notification' ,
125+ format : :html ,
126+ locals : { context_posts : context_posts , post : @post }
134127 )
135128
129+ if @post . topic . private_message?
130+ opts [ :subject_prefix ] = "[#{ I18n . t ( 'private_message_abbrev' ) } ] "
131+ end
136132
137133 email_opts = {
138134 topic_title : @notification . data_hash [ :topic_title ] ,
@@ -146,7 +142,8 @@ def notification_email(user, opts)
146142 allow_reply_by_email : opts [ :allow_reply_by_email ] ,
147143 template : "user_notifications.user_#{ notification_type } " ,
148144 html_override : html ,
149- style : :notification
145+ style : :notification ,
146+ subject_prefix : opts [ :subject_prefix ] || ''
150147 }
151148
152149 # If we have a display name, change the from address
0 commit comments