mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: the ability to permanently destroy the private message (#11115)
PostDestroyer should accept the option to permanently destroy post from the database. In addition, when the first post is destroyed it destroys the whole topic. Currently, that feature is limited to private messages and creator of the post. It will be used by discourse-encrypt to explode encrypted private messages.
This commit is contained in:
committed by
GitHub
parent
27e94f2f98
commit
586c8efbd8
@@ -66,7 +66,7 @@ class PostDestroyer
|
||||
|
||||
delete_removed_posts_after = @opts[:delete_removed_posts_after] || SiteSetting.delete_removed_posts_after
|
||||
|
||||
if delete_removed_posts_after < 1 || post_is_reviewable? || Guardian.new(@user).can_moderate_topic?(topic)
|
||||
if delete_removed_posts_after < 1 || post_is_reviewable? || Guardian.new(@user).can_moderate_topic?(topic) || permanent?
|
||||
perform_delete
|
||||
elsif @user.id == @post.user_id
|
||||
mark_for_deletion(delete_removed_posts_after)
|
||||
@@ -140,9 +140,10 @@ class PostDestroyer
|
||||
|
||||
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
||||
# show up in the topic
|
||||
# Permanent option allows to hard delete.
|
||||
def perform_delete
|
||||
Post.transaction do
|
||||
@post.trash!(@user)
|
||||
permanent? ? @post.destroy! : @post.trash!(@user)
|
||||
if @post.topic
|
||||
make_previous_post_the_last_one
|
||||
mark_topic_changed
|
||||
@@ -162,7 +163,9 @@ class PostDestroyer
|
||||
end
|
||||
end
|
||||
|
||||
@post.topic.trash!(@user) if @post.topic && @post.is_first_post?
|
||||
if @post.topic && @post.is_first_post?
|
||||
permanent? ? @post.topic.destroy! : @post.topic.trash!(@user)
|
||||
end
|
||||
update_associated_category_latest_topic
|
||||
update_user_counts
|
||||
TopicUser.update_post_action_cache(post_id: @post.id)
|
||||
@@ -178,8 +181,12 @@ class PostDestroyer
|
||||
|
||||
update_imap_sync(@post, true) if @post.topic&.deleted_at
|
||||
feature_users_in_the_topic if @post.topic
|
||||
@post.publish_change_to_clients! :deleted if @post.topic
|
||||
TopicTrackingState.publish_delete(@post.topic) if @post.topic && @post.post_number == 1
|
||||
@post.publish_change_to_clients!(permanent? ? :destroyed : :deleted) if @post.topic
|
||||
TopicTrackingState.send(permanent? ? :publish_destroy : :publish_delete, @post.topic) if @post.topic && @post.post_number == 1
|
||||
end
|
||||
|
||||
def permanent?
|
||||
@opts[:permanent] && @user == @post.user && @post.topic.private_message?
|
||||
end
|
||||
|
||||
# When a user 'deletes' their own post. We just change the text.
|
||||
|
||||
@@ -174,6 +174,7 @@ module SvgSprite
|
||||
"star",
|
||||
"step-backward",
|
||||
"step-forward",
|
||||
"stopwatch",
|
||||
"stream",
|
||||
"sync-alt",
|
||||
"sync",
|
||||
|
||||
Reference in New Issue
Block a user