From 87f4b4d230454d4baa7116e55d9aee42199eeb9b Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 20 Apr 2019 01:00:45 -0500 Subject: 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. --- app/lib/bangtags.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'app/lib/bangtags.rb') 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 -- cgit