logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

tag_manager.rb (2759B)


  1. # frozen_string_literal: true
  2. class OStatus::TagManager
  3. include Singleton
  4. include RoutingHelper
  5. VERBS = {
  6. post: 'http://activitystrea.ms/schema/1.0/post',
  7. share: 'http://activitystrea.ms/schema/1.0/share',
  8. favorite: 'http://activitystrea.ms/schema/1.0/favorite',
  9. unfavorite: 'http://activitystrea.ms/schema/1.0/unfavorite',
  10. delete: 'http://activitystrea.ms/schema/1.0/delete',
  11. follow: 'http://activitystrea.ms/schema/1.0/follow',
  12. request_friend: 'http://activitystrea.ms/schema/1.0/request-friend',
  13. authorize: 'http://activitystrea.ms/schema/1.0/authorize',
  14. reject: 'http://activitystrea.ms/schema/1.0/reject',
  15. unfollow: 'http://ostatus.org/schema/1.0/unfollow',
  16. block: 'http://mastodon.social/schema/1.0/block',
  17. unblock: 'http://mastodon.social/schema/1.0/unblock',
  18. }.freeze
  19. TYPES = {
  20. activity: 'http://activitystrea.ms/schema/1.0/activity',
  21. note: 'http://activitystrea.ms/schema/1.0/note',
  22. comment: 'http://activitystrea.ms/schema/1.0/comment',
  23. person: 'http://activitystrea.ms/schema/1.0/person',
  24. collection: 'http://activitystrea.ms/schema/1.0/collection',
  25. group: 'http://activitystrea.ms/schema/1.0/group',
  26. }.freeze
  27. COLLECTIONS = {
  28. public: 'http://activityschema.org/collection/public',
  29. }.freeze
  30. XMLNS = 'http://www.w3.org/2005/Atom'
  31. MEDIA_XMLNS = 'http://purl.org/syndication/atommedia'
  32. AS_XMLNS = 'http://activitystrea.ms/spec/1.0/'
  33. THR_XMLNS = 'http://purl.org/syndication/thread/1.0'
  34. POCO_XMLNS = 'http://portablecontacts.net/spec/1.0'
  35. DFRN_XMLNS = 'http://purl.org/macgirvin/dfrn/1.0'
  36. OS_XMLNS = 'http://ostatus.org/schema/1.0'
  37. MTDN_XMLNS = 'http://mastodon.social/schema/1.0'
  38. def unique_tag(date, id, type)
  39. "tag:#{Rails.configuration.x.local_domain},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}"
  40. end
  41. def unique_tag_to_local_id(tag, expected_type)
  42. return nil unless local_id?(tag)
  43. if ActivityPub::TagManager.instance.local_uri?(tag)
  44. ActivityPub::TagManager.instance.uri_to_local_id(tag)
  45. else
  46. matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag)
  47. return matches[1] unless matches.nil?
  48. end
  49. end
  50. def local_id?(id)
  51. id.start_with?("tag:#{Rails.configuration.x.local_domain}") || ActivityPub::TagManager.instance.local_uri?(id)
  52. end
  53. def uri_for(target)
  54. return target.uri if target.respond_to?(:local?) && !target.local?
  55. case target.object_type
  56. when :person
  57. account_url(target)
  58. when :note, :comment, :activity
  59. target.uri || unique_tag(target.created_at, target.id, 'Status')
  60. end
  61. end
  62. end