FEATURE: show raw email for replies/topics created via email

This commit is contained in:
Arpit Jalan 2014-10-16 11:38:02 +05:30
parent ab9a0235b4
commit 2131a37811
13 changed files with 60 additions and 4 deletions

View File

@ -0,0 +1,24 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object';
/**
This controller handles displaying of raw email
@class RawEmailController
@extends ObjectController
@namespace Discourse
@uses ModalFunctionality
@module Discourse
**/
export default ObjectController.extend(ModalFunctionality, {
raw_email: "",
loadEmail: function(postId) {
var self = this;
Discourse.Post.load(postId).then(function (result) {
self.set("raw_email", result.get('raw_email'));
});
}
});

View File

@ -73,6 +73,11 @@ Discourse.TopicRoute = Discourse.Route.extend({
this.controllerFor('modal').set('modalClass', 'history-modal'); this.controllerFor('modal').set('modalClass', 'history-modal');
}, },
showRawEmail: function(post) {
Discourse.Route.showModal(this, 'raw-email', post);
this.controllerFor('raw_email').loadEmail(post.get("id"));
},
mergeTopic: function() { mergeTopic: function() {
Discourse.Route.showModal(this, 'mergeTopic', this.modelFor('topic')); Discourse.Route.showModal(this, 'mergeTopic', this.modelFor('topic'));
}, },

View File

@ -0,0 +1,7 @@
<div class="modal-body">
{{#if raw_email}}
<pre><code>{{raw_email}}</code></pre>
{{else}}
Not Available!
{{/if}}
</div>

View File

@ -53,7 +53,7 @@
<div class="post-info wiki" title="{{i18n post.wiki.about}}" {{action "editPost" this}}><i class="fa fa-pencil-square-o"></i></div> <div class="post-info wiki" title="{{i18n post.wiki.about}}" {{action "editPost" this}}><i class="fa fa-pencil-square-o"></i></div>
{{/if}} {{/if}}
{{#if via_email}} {{#if via_email}}
<div class="post-info via-email" title="{{i18n post.via_email}}"><i class="fa fa-envelope-o"></i></div> <div class="post-info via-email" title="{{i18n post.via_email}}" {{action "showRawEmail" this}}><i class="fa fa-envelope-o"></i></div>
{{/if}} {{/if}}
<div {{bind-attr class=":read-state read"}} title="{{i18n post.unread}}"><i class='fa fa-circle'></i></div> <div {{bind-attr class=":read-state read"}} title="{{i18n post.unread}}"><i class='fa fa-circle'></i></div>
</div> </div>

View File

@ -0,0 +1,9 @@
export default Discourse.ModalBodyView.extend({
templateName: 'modal/raw_email',
title: I18n.t('raw_email'),
resizeModal: function(){
var viewPortHeight = $(window).height();
this.$(".modal-body").css("max-height", Math.floor(0.8 * viewPortHeight) + "px");
}.on("didInsertElement")
});

View File

@ -122,13 +122,13 @@ aside.quote {
.post-info { .post-info {
&.wiki, &.via-email { &.wiki, &.via-email {
cursor: pointer;
margin-right: 5px; margin-right: 5px;
i.fa { i.fa {
font-size: 14px; font-size: 14px;
} }
} }
&.wiki { &.wiki {
cursor: pointer;
color: $wiki; color: $wiki;
} }
&.via-email { &.via-email {

View File

@ -606,6 +606,8 @@ end
# version :integer default(1), not null # version :integer default(1), not null
# cook_method :integer default(1), not null # cook_method :integer default(1), not null
# wiki :boolean default(FALSE), not null # wiki :boolean default(FALSE), not null
# via_email :boolean default(FALSE), not null
# raw_email :text
# baked_at :datetime # baked_at :datetime
# baked_version :integer # baked_version :integer
# hidden_at :datetime # hidden_at :datetime

View File

@ -51,7 +51,8 @@ class PostSerializer < BasicPostSerializer
:wiki, :wiki,
:user_custom_fields, :user_custom_fields,
:static_doc, :static_doc,
:via_email :via_email,
:raw_email
def topic_slug def topic_slug
object.try(:topic).try(:slug) object.try(:topic).try(:slug)

View File

@ -1382,6 +1382,7 @@ en:
users_lowercase: "users" users_lowercase: "users"
category_title: "Category" category_title: "Category"
history: "History" history: "History"
raw_email: "Raw Email"
changed_by: "by {{author}}" changed_by: "by {{author}}"
categories_list: "Categories List" categories_list: "Categories List"

View File

@ -0,0 +1,5 @@
class AddRawEmailToPosts < ActiveRecord::Migration
def change
add_column :posts, :raw_email, :text
end
end

View File

@ -245,6 +245,7 @@ module Email
def create_post(user, options) def create_post(user, options)
# Mark the reply as incoming via email # Mark the reply as incoming via email
options[:via_email] = true options[:via_email] = true
options[:raw_email] = @raw
creator = PostCreator.new(user, options) creator = PostCreator.new(user, options)
post = creator.create post = creator.create

View File

@ -223,7 +223,7 @@ class PostCreator
reply_to_post_number: @opts[:reply_to_post_number]) reply_to_post_number: @opts[:reply_to_post_number])
# Attributes we pass through to the post instance if present # Attributes we pass through to the post instance if present
[:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email].each do |a| [:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email, :raw_email].each do |a|
post.send("#{a}=", @opts[a]) if @opts[a].present? post.send("#{a}=", @opts[a]) if @opts[a].present?
end end

View File

@ -146,6 +146,7 @@ Pleasure to have you here!
topic.posts.count.should == (start_count + 1) topic.posts.count.should == (start_count + 1)
created_post = topic.posts.last created_post = topic.posts.last
created_post.via_email.should == true created_post.via_email.should == true
created_post.raw_email.should == fixture_file("emails/valid_reply.eml")
created_post.cooked.strip.should == fixture_file("emails/valid_reply.cooked").strip created_post.cooked.strip.should == fixture_file("emails/valid_reply.cooked").strip
end end
end end