FIX: Simplify draft decryption code

FIX: Simplify draft decryption code

diff --git a/assets/javascripts/discourse/initializers/hook-composer.js.es6 b/assets/javascripts/discourse/initializers/hook-composer.js.es6
index d429d3e..8a98886 100644
--- a/assets/javascripts/discourse/initializers/hook-composer.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-composer.js.es6
@@ -121,43 +121,43 @@ export default {
   },
 
   composerReplyReloaded(model) {
-    const draftKey = model.draftKey;
-
-    let encrypted, decTitle, decReply;
-    if (draftKey === Composer.NEW_PRIVATE_MESSAGE_KEY) {
-      encrypted = true;
-    } else if (draftKey.indexOf("topic_") === 0) {
-      const topicId = draftKey.substr("topic_".length);
-      encrypted = !!hasTopicKey(topicId);
+    if (!model.privateMessage) {
+      return;
     }
 
-    if (encrypted) {
-      if (model.action === "edit" && model.originalText) {
-        const topicId = model.get("topic.id");
-        decTitle = getTopicTitle(topicId);
-        decReply = getTopicKey(topicId)
-          .then(key => decrypt(key, model.reply))
+    let decTitle, decReply;
+
+    if (model.action === "edit" && model.originalText) {
+      const topicId = model.get("topic.id");
+      if (!hasTopicKey(topicId)) {
+        return;
+      }
+
+      decTitle = getTopicTitle(topicId);
+      decReply = getTopicKey(topicId)
+        .then(key => decrypt(key, model.reply))
+        .then(decrypted => decrypted.raw);
+    } else {
+      const pos = model.reply ? model.reply.indexOf("\n") : -1;
+      if (pos === -1) {
+        return;
+      }
+
+      const topicKey = model.reply.substr(0, pos).trim();
+      const reply = model.reply.substr(pos + 1).trim();
+
+      const decKey = getIdentity().then(identity =>
+        importKey(topicKey, identity.encryptPrivate)
+      );
+
+      if (model.title) {
+        decTitle = decKey.then(key => decrypt(key, model.title));
+      }
+
+      if (reply) {
+        decReply = decKey
+          .then(key => decrypt(key, reply))
           .then(decrypted => decrypted.raw);
-      } else {
-        const pos = model.reply ? model.reply.indexOf("\n") : -1;
-        if (pos !== -1) {
-          const topicKey = model.reply.substr(0, pos).trim();
-          const reply = model.reply.substr(pos + 1).trim();
-
-          const decKey = getIdentity().then(identity =>
-            importKey(topicKey, identity.encryptPrivate)
-          );
-
-          decTitle = model.title
-            ? decKey.then(key => decrypt(key, model.title))
-            : "";
-
-          decReply = reply
-            ? decKey
-                .then(key => decrypt(key, reply))
-                .then(decrypted => decrypted.raw)
-            : "";
-        }
       }
     }
 
diff --git a/assets/javascripts/discourse/initializers/hook-draft.js.es6 b/assets/javascripts/discourse/initializers/hook-draft.js.es6
index dfc753c..b428582 100644
--- a/assets/javascripts/discourse/initializers/hook-draft.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-draft.js.es6
@@ -23,7 +23,7 @@ const ALLOWED_DRAFT_FIELDS = [
   "reply", // will be encrypted
   "tags",
   "title", // will be encrypted
-  "usernames",
+  "recipients",
   "whisper"
 ];
 

GitHub sha: ab8a276d