Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't truncate notification emails anymore #4830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -142,6 +142,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Allow to set unhosted button and currency for paypal donation [#5452](https://github.com/diaspora/diaspora/pull/5452)
* Add followed tags in the mobile menu [#5468](https://github.com/diaspora/diaspora/pull/5468)
* Replace Pagedown with markdown-it [#5526](https://github.com/diaspora/diaspora/pull/5526)
* Do not truncate notification emails anymore [#4342](https://github.com/diaspora/diaspora/issues/4342)

# 0.4.1.2

Expand Down
9 changes: 4 additions & 5 deletions app/helpers/notifier_helper.rb
Expand Up @@ -2,23 +2,22 @@ module NotifierHelper

# @param post [Post] The post object.
# @param opts [Hash] Optional hash. Accepts :length parameters.
# @return [String] The truncated and formatted post.
# @return [String] The formatted post.
def post_message(post, opts={})
if !post.public?
I18n.translate 'notifier.a_private_message'
elsif post.respond_to? :message
post.message.plain_text_without_markdown truncate: opts.fetch(:length, 200)
post.message.plain_text_without_markdown
else
I18n.translate 'notifier.a_post_you_shared'
end
end

# @param comment [Comment] The comment to process.
# @param opts [Hash] Optional hash. Accepts :length parameters.
# @return [String] The truncated and formatted comment.
# @return [String] The formatted comment.
def comment_message(comment, opts={})
if comment.post.public?
comment.message.plain_text_without_markdown truncate: opts.fetch(:length, 600)
comment.message.plain_text_without_markdown
else
I18n.translate 'notifier.a_limited_post_comment'
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/notifier/mentioned.markerb
@@ -1,4 +1,4 @@
<%= post_message(@notification.post, :process_newlines => true, :length => 600) %>
<%= post_message(@notification.post, :process_newlines => true) %>

[<%= t('notifier.comment_on_post.reply', :name => @notification.post_author_name) %>][1]

Expand Down
2 changes: 1 addition & 1 deletion app/views/notifier/private_message.markerb
@@ -1,4 +1,4 @@
<%= post_message(@notification.message, :process_newlines => true, :length => 2000) %>
<%= post_message(@notification.message, :process_newlines => true) %>

[<%= t('.reply_to_or_view') %>][1]

Expand Down
29 changes: 4 additions & 25 deletions spec/helpers/notifier_helper_spec.rb
Expand Up @@ -7,25 +7,16 @@
describe NotifierHelper, :type => :helper do
describe '#post_message' do
before do
# post for truncate test
@post = FactoryGirl.create(:status_message, text: "hi dude! "*10, public: true)
@truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..."
# post for markdown test
@markdown_post = FactoryGirl.create(:status_message,
text: "[link](http://diasporafoundation.org) **bold text** *other text*", public: true)
@striped_markdown_post = "link (http://diasporafoundation.org) bold text other text"

@limited_post = FactoryGirl.create(:status_message, text: "This is top secret post. Shhhhhhhh!!!", public: false)
end

it 'truncates in the post' do
opts = {:length => @post.text.length - 10}
expect(post_message(@post, opts)).to eq(@truncated_post)
end


it 'strip markdown in the post' do
opts = {:length => @markdown_post.text.length}
expect(post_message(@markdown_post, opts)).to eq(@striped_markdown_post)
expect(post_message(@markdown_post)).to eq(@striped_markdown_post)
end

it 'hides the private content' do
Expand All @@ -35,12 +26,6 @@

describe '#comment_message' do
before do
# comment for truncate test
@comment = FactoryGirl.create(:comment)
@comment.text = "hi dude! "*10
@comment.post.public = true
@truncated_comment = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi d..."

# comment for markdown test
@markdown_comment = FactoryGirl.create(:comment)
@markdown_comment.post.public = true
Expand All @@ -52,15 +37,9 @@
@limited_comment.post.public = false
@limited_comment.text = "This is top secret comment. Shhhhhhhh!!!"
end

it 'truncates in the comment' do
opts = {:length => @comment.text.length - 10}
expect(comment_message(@comment, opts)).to eq(@truncated_comment)
end


it 'strip markdown in the comment' do
opts = {:length => @markdown_comment.text.length}
expect(comment_message(@markdown_comment, opts)).to eq(@striped_markdown_comment)
expect(comment_message(@markdown_comment)).to eq(@striped_markdown_comment)
end

it 'hides the private content' do
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/notifier_spec.rb
Expand Up @@ -116,7 +116,7 @@
expect(@mail.to).to eq([alice.email])
end

it 'BODY: contains the truncated original post' do
it 'BODY: contains the original post' do
expect(@mail.body.encoded).to include(@post.message.plain_text)
end

Expand Down