activity.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package apmodels
  2. import (
  3. "net/url"
  4. "time"
  5. "github.com/go-fed/activity/streams"
  6. "github.com/go-fed/activity/streams/vocab"
  7. "github.com/owncast/owncast/core/data"
  8. )
  9. // PrivacyAudience represents the audience for an activity.
  10. type PrivacyAudience = string
  11. const (
  12. // PUBLIC is an audience meaning anybody can view the item.
  13. PUBLIC PrivacyAudience = "https://www.w3.org/ns/activitystreams#Public"
  14. )
  15. // MakeCreateActivity will return a new Create activity with the provided ID.
  16. func MakeCreateActivity(activityID *url.URL) vocab.ActivityStreamsCreate {
  17. activity := streams.NewActivityStreamsCreate()
  18. id := streams.NewJSONLDIdProperty()
  19. id.Set(activityID)
  20. activity.SetJSONLDId(id)
  21. // TO the public if we're not treating ActivityPub as "private".
  22. if !data.GetFederationIsPrivate() {
  23. public, _ := url.Parse(PUBLIC)
  24. to := streams.NewActivityStreamsToProperty()
  25. to.AppendIRI(public)
  26. activity.SetActivityStreamsTo(to)
  27. audience := streams.NewActivityStreamsAudienceProperty()
  28. audience.AppendIRI(public)
  29. activity.SetActivityStreamsAudience(audience)
  30. }
  31. return activity
  32. }
  33. // MakeUpdateActivity will return a new Update activity with the provided aID.
  34. func MakeUpdateActivity(activityID *url.URL) vocab.ActivityStreamsUpdate {
  35. activity := streams.NewActivityStreamsUpdate()
  36. id := streams.NewJSONLDIdProperty()
  37. id.Set(activityID)
  38. activity.SetJSONLDId(id)
  39. // CC the public if we're not treating ActivityPub as "private".
  40. if !data.GetFederationIsPrivate() {
  41. public, _ := url.Parse(PUBLIC)
  42. cc := streams.NewActivityStreamsCcProperty()
  43. cc.AppendIRI(public)
  44. activity.SetActivityStreamsCc(cc)
  45. }
  46. return activity
  47. }
  48. // MakeNote will return a new Note object.
  49. func MakeNote(text string, noteIRI *url.URL, attributedToIRI *url.URL) vocab.ActivityStreamsNote {
  50. note := streams.NewActivityStreamsNote()
  51. content := streams.NewActivityStreamsContentProperty()
  52. content.AppendXMLSchemaString(text)
  53. note.SetActivityStreamsContent(content)
  54. id := streams.NewJSONLDIdProperty()
  55. id.Set(noteIRI)
  56. note.SetJSONLDId(id)
  57. published := streams.NewActivityStreamsPublishedProperty()
  58. published.Set(time.Now())
  59. note.SetActivityStreamsPublished(published)
  60. attributedTo := attributedToIRI
  61. attr := streams.NewActivityStreamsAttributedToProperty()
  62. attr.AppendIRI(attributedTo)
  63. note.SetActivityStreamsAttributedTo(attr)
  64. // To the public if we're not treating ActivityPub as "private".
  65. if !data.GetFederationIsPrivate() {
  66. public, _ := url.Parse(PUBLIC)
  67. to := streams.NewActivityStreamsToProperty()
  68. to.AppendIRI(public)
  69. note.SetActivityStreamsTo(to)
  70. audience := streams.NewActivityStreamsAudienceProperty()
  71. audience.AppendIRI(public)
  72. note.SetActivityStreamsAudience(audience)
  73. }
  74. return note
  75. }