FIX: Fix invite user into conversation.

FIX: Fix invite user into conversation.

From 204addfee6508d2f044c4330f6566a6c670b9248 Mon Sep 17 00:00:00 2001
From: Dan Ungureanu <dan@ungureanu.me>
Date: Thu, 29 Nov 2018 22:48:03 +0200
Subject: [PATCH] FIX: Fix invite user into conversation.


diff --git a/plugin.rb b/plugin.rb
index ff139ae..1b57cec 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -81,19 +81,23 @@ after_initialize do
       #               This parameter is optional when editing a topic's title.
       def put_topickeys
         topic_id = params.require(:topic_id)
-        title = params.require(:title)
+        title = params[:title]
         keys = params[:keys]
 
-        topic = Topic.find_by(id: topic_id)
-        topic.custom_fields["encrypted_title"] = title
-        topic.save!
+        if title
+          # Title may be missing when inviting new users into conversation.
+          topic = Topic.find_by(id: topic_id)
+          topic.custom_fields["encrypted_title"] = title
+          topic.save!
+        end
 
         if keys
+          # Keys may be missing when editing a conversation.
           users = Hash[User.where(username: keys.keys).map { |u| [u.username, u] }]
           keys.each { |u, k| Store.set("key_#{topic_id}_#{users[u].id}", k) }
         end
 
-        render json: { success: true }
+        render json: success_json
       end
 
       # Deletes topic keys for a set of users.

GitHub