FIX: Hide post version.

FIX: Hide post version.

From 7ac5442a34d639bb8af7cb804cb6c5b7ac45399a Mon Sep 17 00:00:00 2001
From: Dan Ungureanu <dan@ungureanu.me>
Date: Thu, 29 Nov 2018 18:25:58 +0200
Subject: [PATCH] FIX: Hide post version.


diff --git a/plugin.rb b/plugin.rb
index 86d4f39..322135a 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -106,8 +106,10 @@ after_initialize do
 
   add_preloaded_topic_list_custom_field("encrypted_title")
 
-  # Monkey-patch Post's excerpt method to hide encrypted message.
   module PostExtensions
+
+    # Patch method to hide excerpt of encrypted message (i.e. in push
+    # notifications).
     def excerpt(maxlength = nil, options = {})
       if topic.custom_fields["encrypted_title"]
         maxlength ||= SiteSetting.post_excerpt_maxlength
@@ -117,6 +119,16 @@ after_initialize do
 
       super(maxlength, options)
     end
+
+    # Hide version (staff) and public version (regular users) because post
+    # revisions will not be decrypted.
+    def version
+      topic.custom_fields["encrypted_title"] ? 1 : super
+    end
+
+    def public_version
+      topic.custom_fields["encrypted_title"] ? 1 : super
+    end
   end
 
   class ::Post

GitHub