diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index 83cdd2462c9..eff5c8fe825 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -17,6 +17,20 @@ Discourse.Post = Discourse.Model.extend({ new_user: Em.computed.equal('trust_level', 0), firstPost: Em.computed.equal('post_number', 1), + // Posts can show up as deleted if the topic is deleted + deletedViaTopic: Em.computed.and('firstPost', 'topic.deleted_at'), + deleted: Em.computed.or('deleted_at', 'deletedViaTopic'), + + postDeletedBy: function() { + if (this.get('firstPost')) { return this.get('topic.deleted_by') } + return this.get('deleted_by'); + }.property('firstPost', 'deleted_by', 'topic.deleted_by'), + + postDeletedAt: function() { + if (this.get('firstPost')) { return this.get('topic.deleted_at') } + return this.get('deleted_at'); + }.property('firstPost', 'deleted_at', 'topic.deleted_at'), + url: function() { return Discourse.Utilities.postUrl(this.get('topic.slug') || this.get('topic_slug'), this.get('topic_id'), this.get('post_number')); }.property('post_number', 'topic_id', 'topic.slug'), @@ -173,6 +187,7 @@ Discourse.Post = Discourse.Model.extend({ } }, + /** Recover a deleted post diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index ae609f52487..057dfd9f44d 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -56,9 +56,9 @@ {{view Discourse.RepliesView contentBinding="replies" postViewBinding="view"}} {{view Discourse.ActionsHistoryView contentBinding="actionsHistory"}} - {{#if deleted_by}} + {{#if deleted}}
- {{i18n post.deleted_by}} {{avatar deleted_by imageSize="tiny"}} {{unboundAge deleted_at}} + {{i18n post.deleted_by}} {{avatar postDeletedBy imageSize="tiny"}} {{unboundAge postDeletedAt}}
{{/if}} diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index 44e8de0d143..6c05a8f6d4b 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -12,7 +12,7 @@ Discourse.PostView = Discourse.View.extend({ classNameBindings: ['postTypeClass', 'selected', 'post.hidden:hidden', - 'deleted', + 'post.deleted', 'parentPost:replies-above'], postBinding: 'content', @@ -39,8 +39,6 @@ Discourse.PostView = Discourse.View.extend({ } }, - deletedViaTopic: Em.computed.and('post.firstPost', 'post.topic.deleted_at'), - deleted: Em.computed.or('post.deleted_at', 'deletedViaTopic'), selected: function() { var selectedPosts = this.get('controller.selectedPosts'); diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index aa2e1150026..3b84ccadcf1 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -31,7 +31,8 @@ class TopicViewSerializer < ApplicationSerializer :pinned, :details, :highest_post_number, - :last_read_post_number + :last_read_post_number, + :deleted_by # Define a delegator for each attribute of the topic we want attributes *topic_attributes @@ -108,6 +109,10 @@ class TopicViewSerializer < ApplicationSerializer object.draft_sequence end + def deleted_by + BasicUserSerializer.new(object.topic.deleted_by, root: false).as_json + end + # Topic user stuff def has_topic_user? object.topic_user.present?