From 271a372e3d44799c990e8fa4b314151a38a942fe Mon Sep 17 00:00:00 2001
From: Arpit Jalan <arpit@techapj.com>
Date: Thu, 22 Apr 2021 15:53:44 +0530
Subject: [PATCH] FIX: when a flag is handled archive message for moderator
 group (#12798)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When a user flags a post with the “Something Else” option, a PM between
the user and the moderators group is created. If no moderators reply to
the PM, when the flag is handled at /review, an auto-reply is created
for the PM. However, the PM is not archived, it stays in the inbox.

This commit ensures that the PM is archived for moderator group when no
moderator has replied to that PM.
---
 app/models/post_action.rb       | 3 +++
 spec/models/post_action_spec.rb | 1 +
 2 files changed, 4 insertions(+)

diff --git a/app/models/post_action.rb b/app/models/post_action.rb
index dcac3b290e5..c7d28f810fe 100644
--- a/app/models/post_action.rb
+++ b/app/models/post_action.rb
@@ -89,6 +89,9 @@ class PostAction < ActiveRecord::Base
     I18n.with_locale(SiteSetting.default_locale) do
       related_post.topic.add_moderator_post(moderator, I18n.t(message_key))
     end
+
+    # archive message for moderators
+    GroupArchivedMessage.archive!(Group[:moderators].id, related_post.topic)
   end
 
   def staff_already_replied?(topic)
diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb
index 26df835d891..dc71f1e001f 100644
--- a/spec/models/post_action_spec.rb
+++ b/spec/models/post_action_spec.rb
@@ -88,6 +88,7 @@ describe PostAction do
       topic.reload
       expect(topic.posts.count).to eq(2)
       expect(topic.posts.last.post_type).to eq(Post.types[:moderator_action])
+      expect(topic.message_archived?(mod)).to eq(true)
     end
 
   end