about summary refs log tree commit diff
path: root/app/lib/bangtags.rb
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-04-20 01:00:45 -0500
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:22 -0500
commit87f4b4d230454d4baa7116e55d9aee42199eeb9b (patch)
tree67ba4a84653cc027a414a60732227abeced2fdc0 /app/lib/bangtags.rb
parent19b78604e9dd1acb6566edd49f5c59536d5fc209 (diff)
Implement share keys and related bangtags, add `sharekey`, `network`, and `curated` to the API, remove app info from the UI, and move timestamps to the right.
Diffstat (limited to 'app/lib/bangtags.rb')
-rw-r--r--app/lib/bangtags.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index d1a179a76..0567caf6d 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -235,6 +235,40 @@ class Bangtags
               mentions = Account.where(id: mention_ids).map { |a| "@#{a.username}" }
               chunk = mentions.join(' ')
             end
+          when 'sharekey'
+            case cmd[2]
+            when 'revoke'
+              if status.conversation_id.present?
+                roars = Status.where(conversation_id: status.conversation_id, account_id: @account.id)
+                roars.each do |roar|
+                  if roar.sharekey.present?
+                    roar.sharekey = nil
+                    roar.save
+                  end
+                end
+              end
+            when 'sync', 'new'
+              if status.conversation_id.present?
+                roars = Status.where(conversation_id: status.conversation_id, account_id: @account.id)
+                earliest_roar = roars.last # The results are in reverse-chronological order.
+                if cmd[2] == 'new' || earlist_roar.sharekey.blank?
+                  sharekey = SecureRandom.urlsafe_base64(32)
+                  earliest_roar.sharekey = sharekey
+                  earliest_roar.save
+                else
+                  sharekey = earliest_roar.sharekey
+                end
+                roars.each do |roar|
+                  if roar.sharekey != sharekey
+                    roar.sharekey = sharekey
+                    roar.save
+                  end
+                end
+              else
+                status.sharekey = SecureRandom.urlsafe_base64(32)
+                status.save
+              end
+            end
           end
         when 'parent'
           chunk = nil
@@ -326,6 +360,13 @@ class Bangtags
             end
             @vars['_they:are'] = name.strip
           end
+        when 'sharekey'
+          case cmd[1]
+          when 'new'
+            chunk = nil
+            status.sharekey = SecureRandom.urlsafe_base64(32)
+            status.save
+          end
         end
       end