FEATURE: sends encrypted message when available

FEATURE: sends encrypted message when available

System user will now send an encrypted message to all the members of the gift exchange if the plugin is available and they have enabled encrypted messages.

diff --git a/jobs/scheduled/gift_exchange.rb b/jobs/scheduled/gift_exchange.rb
index 668573b..297766f 100644
--- a/jobs/scheduled/gift_exchange.rb
+++ b/jobs/scheduled/gift_exchange.rb
@@ -42,13 +42,22 @@ module Jobs
         Thanks for participating and have fun!
         MD
 
-        PostCreator.new(
-          Discourse.system_user,
+        opts = {
           archetype: Archetype.private_message,
           target_usernames: gifter,
           title: "#{now.year} Discourse Holiday Secret Gift :gift: Exchange",
           raw: raw,
-        ).create
+        }
+
+        post_created = false
+
+        if defined?(EncryptedPostCreator)
+          post_created = EncryptedPostCreator.new(Discourse.system_user, opts).create
+        end
+
+        if !post_created
+          PostCreator.new(Discourse.system_user, opts).create
+        end
       end
 
       group.custom_fields[GIFT_EXCHANGE_CUSTOM_FIELD] = true

GitHub sha: d73cbd55

nice :+1: I like how simple it is to create encrypted posts from the server with this new API

1 Like