Skip to content

Commit fe3a69c

Browse files
committed
Private message emails now include the history
1 parent 915a029 commit fe3a69c

21 files changed

Lines changed: 53 additions & 260 deletions

app/mailers/user_notifications.rb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/models/user_email_observer.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def after_commit(notification)
1616

1717
# Delegate to email_user_{{NOTIFICATION_TYPE}} if exists
1818
email_method = :"email_user_#{notification_type.to_s}"
19+
1920
send(email_method, notification) if respond_to?(email_method)
2021
end
2122
end
@@ -57,12 +58,21 @@ def email_user_replied(notification)
5758
notification_id: notification.id)
5859
end
5960

61+
def email_user_private_message(notification)
62+
return unless (notification.user.email_direct? && notification.user.email_private_messages?)
63+
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
64+
:user_email,
65+
type: :user_private_message,
66+
user_id: notification.user_id,
67+
notification_id: notification.id)
68+
end
69+
6070
def email_user_invited_to_private_message(notification)
6171
return unless notification.user.email_direct?
6272
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
63-
:user_email,
64-
type: :user_invited_to_private_message,
65-
user_id: notification.user_id,
66-
notification_id: notification.id)
73+
:user_email,
74+
type: :user_invited_to_private_message,
75+
user_id: notification.user_id,
76+
notification_id: notification.id)
6777
end
6878
end

config/locales/server.cs.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ cs:
10161016
Prosím navšivte tento odkaz, chcete-li odpovědět: %{base_url}%{url}
10171017
10181018
user_posted:
1019-
subject_template: "[%{site_name}] %{username} přispěl do tématu '%{topic_title}'"
1019+
subject_template: "[%{site_name}] %{subject_prefix}%{username} přispěl do tématu '%{topic_title}'"
10201020
text_body_template: |
10211021
%{username} přispěl do tématu '%{topic_title}' na %{site_name}:
10221022
@@ -1036,17 +1036,6 @@ cs:
10361036
from: "souhrn z %{site_name}"
10371037
read_more: "Číst dále"
10381038

1039-
private_message:
1040-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
1041-
text_body_template: |
1042-
%{from} vám právě zaslal soukromou zprávu
1043-
1044-
---
1045-
%{message}
1046-
1047-
---
1048-
Prosím navšivte tento odkaz, chcete-li odpovědět: %{base_url}%{url}
1049-
10501039
forgot_password:
10511040
subject_template: "[%{site_name}] Obnovení hesla"
10521041
text_body_template: |

config/locales/server.da.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ da:
714714
Klik her for at svare: %{base_url}%{url}
715715
716716
user_posted:
717-
subject_template: "[%{site_name}] %{username} skrev et indlæg i emnet '%{topic_title}'"
717+
subject_template: "[%{site_name}] %{subject_prefix}%{username} skrev et indlæg i emnet '%{topic_title}'"
718718
text_body_template: |
719719
%{username} skrev et indlæg i emnet '%{topic_title}' på %{site_name}:
720720
@@ -733,17 +733,6 @@ da:
733733
click_here: "klik her"
734734
from: "%{site_name} opsummering"
735735

736-
private_message:
737-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
738-
text_body_template: |
739-
%{private_message_from} har sendt dig en privat besked
740-
741-
---
742-
%{message}
743-
744-
---
745-
Klik her for at svare: %{base_url}%{url}
746-
747736
forgot_password:
748737
subject_template: "[%{site_name}] Nulstil kodeord"
749738
text_body_template: |

config/locales/server.de.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ de:
903903
Um zu antworten, besuche den folgenden Link: %{base_url}%{url}
904904
905905
user_posted:
906-
subject_template: "[%{site_name}] %{username} hat auf '%{topic_title}' geantwortet"
906+
subject_template: "[%{site_name}] %{subject_prefix}%{username} hat auf '%{topic_title}' geantwortet"
907907
text_body_template: |
908908
%{username} hat in '%{topic_title}' auf %{site_name} geantwortet:
909909
@@ -923,17 +923,6 @@ de:
923923
from: "%{site_name} Übersicht"
924924
read_more: "Weiterlesen"
925925

926-
private_message:
927-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
928-
text_body_template: |
929-
%{private_message_from} hat Die eine private Nachricht geschickt:
930-
931-
---
932-
%{message}
933-
934-
---
935-
Um zu antworten, besuche den folgenden Link: %{base_url}%{url}
936-
937926
forgot_password:
938927
subject_template: "[%{site_name}] Passwort zurückgesetzt"
939928
text_body_template: |

config/locales/server.en.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ en:
985985
%{respond_instructions}
986986
987987
user_posted:
988-
subject_template: "[%{site_name}] new post in '%{topic_title}'"
988+
subject_template: "[%{site_name}] %{subject_prefix}new post in '%{topic_title}'"
989989
text_body_template: |
990990
%{message}
991991
@@ -1004,16 +1004,6 @@ en:
10041004
from: "%{site_name} digest"
10051005
read_more: "Read More"
10061006

1007-
private_message:
1008-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
1009-
text_body_template: |
1010-
%{private_message_from} just sent you a private message
1011-
1012-
%{message}
1013-
1014-
---
1015-
%{respond_instructions}
1016-
10171007
forgot_password:
10181008
subject_template: "[%{site_name}] Password reset"
10191009
text_body_template: |

config/locales/server.es.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ es:
694694
Por favor visita este link para contestar: %{base_url}%{url}
695695
696696
user_posted:
697-
subject_template: "[%{site_name}] %{username} posteó en '%{topic_title}'"
697+
subject_template: "[%{site_name}] %{subject_prefix}%{username} posteó en '%{topic_title}'"
698698
text_body_template: |
699699
%{username} posteó en '%{topic_title}' en %{site_name}:
700700
@@ -713,17 +713,6 @@ es:
713713
click_here: "click aquí"
714714
from: "%{site_name} digest"
715715

716-
private_message:
717-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
718-
text_body_template: |
719-
%{private_message_from} te acaba de mandar un mensaje privado
720-
721-
---
722-
%{message}
723-
724-
---
725-
Por favor visita este link para contestar: %{base_url}%{url}
726-
727716
forgot_password:
728717
subject_template: "[%{site_name}] Resetear el password"
729718
text_body_template: |

config/locales/server.fr.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ fr:
883883
Merci de suivre ce lien pour répondre : %{base_url}%{url}
884884
885885
user_posted:
886-
subject_template: "[%{site_name}] nouveau message dans '%{topic_title}'"
886+
subject_template: "[%{site_name}] %{subject_prefix}nouveau message dans '%{topic_title}'"
887887
text_body_template: |
888888
%{username} à répondu à '%{topic_title}' sur %{site_name}:
889889
@@ -902,17 +902,6 @@ fr:
902902
click_here: "cliquez ici"
903903
from: "Résumé de %{site_name}"
904904

905-
private_message:
906-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
907-
text_body_template: |
908-
%{from} vous a envoyé un message privé
909-
910-
---
911-
%{message}
912-
913-
---
914-
Merci de suivre ce lien pour répondre : %{base_url}%{url}
915-
916905
forgot_password:
917906
subject_template: "[%{site_name}] Réinitialisation du mot de passe"
918907
text_body_template: |

config/locales/server.id.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ id:
711711
Please visit this link to respond: %{base_url}%{url}
712712
713713
user_posted:
714-
subject_template: "[%{site_name}] %{username} posted in '%{topic_title}'"
714+
subject_template: "[%{site_name}] %{subject_prefix}%{username} posted in '%{topic_title}'"
715715
text_body_template: |
716716
%{username} posted in '%{topic_title}' on %{site_name}:
717717
@@ -730,17 +730,6 @@ id:
730730
click_here: "click here"
731731
from: "%{site_name} digest"
732732

733-
private_message:
734-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
735-
text_body_template: |
736-
%{private_message_from} just sent you a private message
737-
738-
---
739-
%{message}
740-
741-
---
742-
Please visit this link to respond: %{base_url}%{url}
743-
744733
forgot_password:
745734
subject_template: "[%{site_name}] Password reset"
746735
text_body_template: |

config/locales/server.it.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ it:
840840
Perfavore visita questo link per rispondere: %{base_url}%{url}
841841
842842
user_posted:
843-
subject_template: "[%{site_name}] %{username} ha postato in '%{topic_title}'"
843+
subject_template: "[%{site_name}] %{subject_prefix}%{username} ha postato in '%{topic_title}'"
844844
text_body_template: |
845845
%{username} ha postato in '%{topic_title}' su %{site_name}:
846846
@@ -859,17 +859,6 @@ it:
859859
click_here: "clicca qui"
860860
from: "%{site_name} riepilogo"
861861

862-
private_message:
863-
subject_template: "[%{site_name}] %{subject_prefix}%{topic_title}"
864-
text_body_template: |
865-
%{private_message_from} ti ha appena inviato un messaggio privato
866-
867-
---
868-
%{message}
869-
870-
---
871-
Perfavore visita questo link per rispondere: %{base_url}%{url}
872-
873862
forgot_password:
874863
subject_template: "[%{site_name}] Reset Password"
875864
text_body_template: |

0 commit comments

Comments
 (0)