merge in "policy-violation" error on empty message

Denver Gingerich created

This probably doesn't appear much in the wild, but good to have in
case we do see it.

See merge request !16 for the discussion and details behind the merge.

Change summary

sgx-catapult.rb | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

Detailed changes

sgx-catapult.rb 🔗

@@ -215,6 +215,13 @@ module SGXcatapult
 	end
 
 	def self.to_catapult(s, murl, num_dest, user_id, token, secret, usern)
+		body = s.respond_to?(:body) ? s.body : ''
+		if murl.to_s.empty? && body.to_s.strip.empty?
+			return EMPromise.reject(
+				[:modify, 'policy-violation']
+			)
+		end
+
 		extra = if murl
 			{
 				media: murl
@@ -234,7 +241,7 @@ module SGXcatapult
 			JSON.dump(extra.merge(
 				from: usern,
 				to:   num_dest,
-				text: s.respond_to?(:body) ? s.body : '',
+				text: body,
 				tag:
 					# callbacks need id and resourcepart
 					WEBrick::HTTPUtils.escape(s.id.to_s) +
@@ -279,7 +286,7 @@ module SGXcatapult
 		}
 	end
 
-	message :chat?, :body do |m|
+	message :body do |m|
 		EMPromise.all([
 			validate_num(m.to.node),
 			fetch_catapult_cred_for(m.from)