Core components of the web application. https://write.as
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.

72 lines
1.8 KiB

  1. package activitystreams
  2. import "fmt"
  3. type (
  4. BaseObject struct {
  5. Context []string `json:"@context,omitempty"`
  6. Type string `json:"type"`
  7. ID string `json:"id"`
  8. }
  9. PublicKey struct {
  10. ID string `json:"id"`
  11. Owner string `json:"owner"`
  12. PublicKeyPEM string `json:"publicKeyPem"`
  13. privateKey []byte
  14. }
  15. Image struct {
  16. Type string `json:"type"`
  17. MediaType string `json:"mediaType"`
  18. URL string `json:"url"`
  19. }
  20. )
  21. type OrderedCollection struct {
  22. BaseObject
  23. TotalItems int `json:"totalItems"`
  24. First string `json:"first"`
  25. Last string `json:"last,omitempty"`
  26. }
  27. func NewOrderedCollection(accountRoot, collType string, items int) *OrderedCollection {
  28. oc := OrderedCollection{
  29. BaseObject: BaseObject{
  30. Context: []string{
  31. "https://www.w3.org/ns/activitystreams",
  32. },
  33. ID: accountRoot + "/" + collType,
  34. Type: "OrderedCollection",
  35. },
  36. First: accountRoot + "/" + collType + "?page=1",
  37. TotalItems: items,
  38. }
  39. return &oc
  40. }
  41. type OrderedCollectionPage struct {
  42. BaseObject
  43. TotalItems int `json:"totalItems"`
  44. PartOf string `json:"partOf"`
  45. Next string `json:"next,omitempty"`
  46. Prev string `json:"prev,omitempty"`
  47. OrderedItems []Activity `json:"orderedItems"`
  48. }
  49. func NewOrderedCollectionPage(accountRoot, collType string, items, page int) *OrderedCollectionPage {
  50. ocp := OrderedCollectionPage{
  51. BaseObject: BaseObject{
  52. Context: []string{
  53. "https://www.w3.org/ns/activitystreams",
  54. },
  55. ID: fmt.Sprintf("%s/%s?page=%d", accountRoot, collType, page),
  56. Type: "OrderedCollectionPage",
  57. },
  58. TotalItems: items,
  59. PartOf: accountRoot + "/" + collType,
  60. Next: fmt.Sprintf("%s/%s?page=%d", accountRoot, collType, page+1),
  61. }
  62. return &ocp
  63. }