From 1c5e8efa6803f33f9755917048eb3f960439e71f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 4 Sep 2014 13:04:22 -0400 Subject: [PATCH] FEATURE: Show an email icon beside posts that arrived via email --- .../javascripts/discourse/templates/post.js.handlebars | 5 ++++- app/assets/stylesheets/desktop/topic-post.scss | 5 +++++ app/serializers/post_serializer.rb | 7 ++++++- config/locales/client.en.yml | 2 ++ db/migrate/20140904160015_add_via_email_to_posts.rb | 5 +++++ lib/email/receiver.rb | 3 +++ lib/post_creator.rb | 2 +- spec/components/email/receiver_spec.rb | 4 +++- 8 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20140904160015_add_via_email_to_posts.rb diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index 083e91a1223..cb16bd9fee4 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -28,7 +28,10 @@ {{/unless}} {{#if wiki}} -
+
+ {{/if}} + {{#if via_email}} +
{{/if}} diff --git a/app/assets/stylesheets/desktop/topic-post.scss b/app/assets/stylesheets/desktop/topic-post.scss index a52755f64a2..680f72fcf8a 100644 --- a/app/assets/stylesheets/desktop/topic-post.scss +++ b/app/assets/stylesheets/desktop/topic-post.scss @@ -773,6 +773,11 @@ $topic-avatar-width: 45px; margin-left: 5px; cursor: pointer; } + + .via-email { + margin: 14px 0 0 8px; + color: scale-color($primary, $lightness: 60%); + } } .gap { diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index a7d546ead5c..582d5e06025 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -50,7 +50,8 @@ class PostSerializer < BasicPostSerializer :can_view_edit_history, :wiki, :user_custom_fields, - :static_doc + :static_doc, + :via_email def moderator? !!(object.user && object.user.moderator?) @@ -245,6 +246,10 @@ class PostSerializer < BasicPostSerializer object.post_number == 1 && Discourse.static_doc_topic_ids.include?(object.topic_id) end + def include_via_email? + object.via_email? + end + private def post_actions diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a44338e9da6..6d791eae086 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1070,6 +1070,8 @@ en: no_value: "No, keep" yes_value: "Yes, abandon" + via_email: "this post arrived via email" + wiki: about: "this post is a wiki; basic users can edit it" diff --git a/db/migrate/20140904160015_add_via_email_to_posts.rb b/db/migrate/20140904160015_add_via_email_to_posts.rb new file mode 100644 index 00000000000..2b3425b0689 --- /dev/null +++ b/db/migrate/20140904160015_add_via_email_to_posts.rb @@ -0,0 +1,5 @@ +class AddViaEmailToPosts < ActiveRecord::Migration + def change + add_column :posts, :via_email, :boolean, default: false, null: false + end +end diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index c15f8c42739..b7cb2cebeeb 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -241,6 +241,9 @@ module Email end def create_post(user, options) + # Mark the reply as incoming via email + options[:via_email] = true + creator = PostCreator.new(user, options) post = creator.create diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 9a7052af136..c4de0707c2f 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -215,7 +215,7 @@ class PostCreator reply_to_post_number: @opts[:reply_to_post_number]) # Attributes we pass through to the post instance if present - [:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method].each do |a| + [:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email].each do |a| post.send("#{a}=", @opts[a]) if @opts[a].present? end diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index a0431606773..9ddcca0c122 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -125,7 +125,9 @@ Thanks for listening." receiver.process topic.posts.count.should == (start_count + 1) - topic.posts.last.cooked.strip.should == fixture_file("emails/valid_reply.cooked").strip + created_post = topic.posts.last + created_post.via_email.should be_true + created_post.cooked.strip.should == fixture_file("emails/valid_reply.cooked").strip end end