闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::ActivityPresenter < ActiveModelSerializers::Model
  3. attributes :id, :type, :actor, :published, :to, :cc, :virtual_object
  4. class << self
  5. def from_status(status)
  6. new.tap do |presenter|
  7. presenter.id = ActivityPub::TagManager.instance.activity_uri_for(status)
  8. presenter.type = status.reblog? ? 'Announce' : 'Create'
  9. presenter.actor = ActivityPub::TagManager.instance.uri_for(status.account)
  10. presenter.published = status.created_at
  11. presenter.to = ActivityPub::TagManager.instance.to(status)
  12. presenter.cc = ActivityPub::TagManager.instance.cc(status)
  13. presenter.virtual_object = begin
  14. if status.reblog?
  15. if status.account == status.proper.account && status.proper.private_visibility? && status.local?
  16. status.proper
  17. else
  18. ActivityPub::TagManager.instance.uri_for(status.proper)
  19. end
  20. else
  21. status.proper
  22. end
  23. end
  24. end
  25. end
  26. def from_encrypted_message(encrypted_message)
  27. new.tap do |presenter|
  28. presenter.id = ActivityPub::TagManager.instance.generate_uri_for(nil)
  29. presenter.type = 'Create'
  30. presenter.actor = ActivityPub::TagManager.instance.uri_for(encrypted_message.source_account)
  31. presenter.published = Time.now.utc
  32. presenter.to = ActivityPub::TagManager.instance.uri_for(encrypted_message.target_account)
  33. presenter.virtual_object = encrypted_message
  34. end
  35. end
  36. end
  37. end