about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-08-07 00:20:41 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:17 -0500
commit256e85e32608f012209fd1d52486174995b77905 (patch)
tree37cef8207a19ae8c364243bac597a4c45df97e72 /app/models
parent93b17730518898d7de5ce1a3c6cc4df40f30c79d (diff)
[Feature, Federation] Add support for arbitarty account and server metadata fields
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account_metadata.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/account_metadata.rb b/app/models/account_metadata.rb
index 1085d7f14..bb0f7676e 100644
--- a/app/models/account_metadata.rb
+++ b/app/models/account_metadata.rb
@@ -18,6 +18,28 @@ class AccountMetadata < ApplicationRecord
     self[:fields].presence || {}
   end
 
+  def fields_json
+    fields.select { |name, _| name.start_with?('custom:') }
+          .map do |name, value|
+            {
+              '@context': {
+                schema: 'http://schema.org/',
+                name: 'schema:name',
+                value: 'schema:value',
+              },
+              type: 'PropertyValue',
+              name: name,
+              value: value.is_a?(Array) ? value.join("\r\n") : value,
+            }
+          end
+  end
+
+  def cached_fields_json
+    Rails.cache.fetch("custom_metadata:#{account_id}", expires_in: 1.hour) do
+      fields_json
+    end
+  end
+
   class << self
     def create_or_update(fields)
       create(fields).presence || update(fields)