DEV: Apply code suggestions

DEV: Apply code suggestions

diff --git a/assets/javascripts/discourse/initializers/decrypt-topics.js b/assets/javascripts/discourse/initializers/decrypt-topics.js
index 31758c7..d9f84bd 100644
--- a/assets/javascripts/discourse/initializers/decrypt-topics.js
+++ b/assets/javascripts/discourse/initializers/decrypt-topics.js
@@ -194,7 +194,7 @@ export default {
       documentTitle.setTitle(
         documentTitle
           .getTitle()
-          .replace(I18n.t("encrypt.encrypted_topic_title"), topicTitle)
+          .replace(I18n.t("encrypt.encrypted_title"), topicTitle)
       );
     });
   },
diff --git a/assets/javascripts/discourse/initializers/encrypt-drafts.js b/assets/javascripts/discourse/initializers/encrypt-drafts.js
index 1c4c0c3..a3b5028 100644
--- a/assets/javascripts/discourse/initializers/encrypt-drafts.js
+++ b/assets/javascripts/discourse/initializers/encrypt-drafts.js
@@ -118,7 +118,7 @@ export default {
         return this._super(site).then(() => {
           this.content.forEach((draft) => {
             if (draft.data.encrypted) {
-              draft.title = ":lock: " + I18n.t("encrypt.encrypted_topic_title");
+              draft.title = ":lock: " + I18n.t("encrypt.encrypted_title");
               draft.title = emojiUnescape(escapeExpression(draft.title));
               draft.excerpt = I18n.t("encrypt.encrypted_post");
             }
diff --git a/assets/javascripts/discourse/initializers/encrypt-posts.js b/assets/javascripts/discourse/initializers/encrypt-posts.js
index 92ac4c5..fd2df8f 100644
--- a/assets/javascripts/discourse/initializers/encrypt-posts.js
+++ b/assets/javascripts/discourse/initializers/encrypt-posts.js
@@ -64,7 +64,7 @@ export default {
     Topic.reopenClass({
       update(topic, props) {
         // TODO: https://github.com/emberjs/ember.js/issues/15291
-        let { _super } = this;
+        const { _super } = this;
         if (!hasTopicKey(topic.id)) {
           return _super.call(this, ...arguments);
         }
@@ -72,7 +72,7 @@ export default {
         return getTopicKey(topic.id)
           .then((key) => encrypt(key, { raw: props.title }))
           .then((encryptedTitle) => {
-            props.title = I18n.t("encrypt.encrypted_topic_title");
+            props.title = I18n.t("encrypt.encrypted_title");
             props.encrypted_title = encryptedTitle;
           })
           .then(() => _super.call(this, ...arguments));
@@ -82,58 +82,46 @@ export default {
     PostAdapter.reopen({
       createRecord(store, type, args) {
         // TODO: https://github.com/emberjs/ember.js/issues/15291
-        let { _super } = this;
+        const { _super } = this;
         if (!args.is_encrypted) {
           return _super.call(this, ...arguments);
         }
 
-        const { title, raw } = args;
-
-        let identityPromise = getIdentity();
-
-        let topicKeyPromise = args.topic_id
+        const identityPromise = getIdentity();
+        const topicKeyPromise = args.topic_id
           ? getTopicKey(args.topic_id)
           : generateKey();
 
-        let titlePromise = title
+        const { title, raw } = args;
+        const titlePromise = title
           ? topicKeyPromise
               .then((key) => encrypt(key, { raw: title }))
               .then((encryptedTitle) => (args.encrypted_title = encryptedTitle))
-              .finally(() => {
-                args.title = I18n.t("encrypt.encrypted_topic_title");
-              })
+              .finally(() => (args.title = I18n.t("encrypt.encrypted_title")))
           : Promise.resolve();
-
-        let replyPromise = raw
+        const replyPromise = raw
           ? topicKeyPromise
               .then((key) => encrypt(key, { raw }, { includeUploads: true }))
               .then((encryptedRaw) => (args.encrypted_raw = encryptedRaw))
-              .finally(() => {
-                args.raw = I18n.t("encrypt.encrypted_post");
-              })
+              .finally(() => (args.raw = I18n.t("encrypt.encrypted_post")))
           : Promise.resolve();
 
         let encryptedKeysPromise = Promise.resolve();
-
         let usernames = [];
         if (args.target_recipients) {
           usernames = args.target_recipients.split(",");
         }
-
         if (usernames.length > 0) {
           usernames.push(currentUser.username);
-          const identitiesPromise = getUserIdentities(usernames);
-
           encryptedKeysPromise = Promise.all([
             topicKeyPromise,
-            identitiesPromise,
+            getUserIdentities(usernames),
           ])
             .then(([key, identities]) => {
               const promises = [];
               for (let i = 0; i < usernames.length; ++i) {
-                const username = usernames[i];
                 promises.push(
-                  exportKey(key, identities[username].encryptPublic)
+                  exportKey(key, identities[usernames[i]].encryptPublic)
                 );
               }
               return Promise.all(promises);
@@ -165,9 +153,6 @@ export default {
               .then(([key, encTitle, identity]) => {
                 putTopicKey(result.payload.topic_id, key);
                 putTopicTitle(result.payload.topic_id, encTitle);
-                if (!identity.signPrivate) {
-                  return;
-                }
 
                 return encrypt(
                   key,
@@ -204,7 +189,7 @@ export default {
 
       update(store, type, id, attrs) {
         // TODO: https://github.com/emberjs/ember.js/issues/15291
-        let { _super } = this;
+        const { _super } = this;
         if (!hasTopicKey(attrs.topic_id)) {
           return _super.call(this, ...arguments);
         }
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index edc05e4..51ac330 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -16,7 +16,7 @@ en:
       integrity_check_warn_updated_at: "Post metadata was updated without being signed again."
       integrity_check_warn_signed_by: "This post was last signed by %{actual}, not %{expected}."
 
-      encrypted_topic_title: "A secret message"
+      encrypted_title: "A secret message"
       encrypted_post: "This is a secret message with end to end encryption. To view it, you must be invited to this topic."
       encrypted_post_email: "This is a secret message with end to end encryption. You must visit the topic to view it."
       encrypted_post_email_timer_annotation: "This message will be permanently deleted at %{delete_at}"
diff --git a/lib/encrypted_post_creator.rb b/lib/encrypted_post_creator.rb
index 769aa8b..52fb9dd 100644
--- a/lib/encrypted_post_creator.rb
+++ b/lib/encrypted_post_creator.rb
@@ -12,7 +12,9 @@ class EncryptedPostCreator < PostCreator
       # Encrypt title and post contents
       @opts[:raw] = EncryptedPostCreator.encrypt(@opts[:raw], topic_key)
       if title = @opts[:title]
-        @opts[:title] = I18n.t('js.encrypt.encrypted_topic_title')
+        @opts[:title] = I18n.with_locale(SiteSetting.default_locale) do
+          I18n.t('js.encrypt.encrypted_title')
+        end
       end
 
       ret = super
diff --git a/plugin.rb b/plugin.rb
index d3427af..6ead278 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -334,25 +334,35 @@ after_initialize do
         result.errors.add(:base, I18n.t('encrypt.no_encrypt_keys'))
         next result
       end
+
+      manager.args[:title] = I18n.with_locale(SiteSetting.default_locale) do
+        I18n.t('js.encrypt.encrypted_title')
+      end
     end
 
     manager.args[:raw] = manager.args[:encrypted_raw]
 
     result = manager.perform_create_post
-    if result.success? && encrypted_keys = manager.args[:encrypted_keys]
-      topic_id = result.post.topic_id
-      keys = JSON.parse(encrypted_keys).map { |u, k| [u.downcase, k] }.to_h
-      user_ids = User.where(username_lower: keys.keys).pluck(:username_lower, :id).to_h
-      keys.each { |u, k| EncryptedTopicsUser.create!(topic_id: topic_id, user_id: user_ids[u], key: k) }

[... diff too long, it was truncated ...]

GitHub sha: 31d7f99e87ac6f0b577d9fafa712cf2f5b22ca1c

This commit appears in #134 which was approved by eviltrout. It was merged by udan11.