FIX: Skip key consistency check when creating the topic.

FIX: Skip key consistency check when creating the topic.

Original poster used to be automatically uninvited because the key is saved after the post was created (and :post_created event was triggered).

diff --git a/plugin.rb b/plugin.rb
index cf73fc2..09273bc 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -214,7 +214,7 @@ after_initialize do
 
   # Delete TopicAllowedUser records for users who do not have the key.
   on(:post_created) do |post, opts, user|
-    if post.topic&.is_encrypted? && !DiscourseEncrypt::Store.get("key_#{post.topic_id}_#{user.id}").present?
+    if post.post_number > 1 && post.topic&.is_encrypted? && !DiscourseEncrypt::Store.get("key_#{post.topic_id}_#{user.id}").present?
       TopicAllowedUser.find_by(user_id: user.id, topic_id: post.topic_id).delete
     end
   end

GitHub sha: bcc0fe9d

Revert "FIX: Skip key consistency check when creating the topic."

Reapply "FIX: Skip key consistency check when creating the topic."