aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-02 18:27:18 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-02 18:27:18 +0000
commit4f42b00ec18cfdf3f97527a6fe91babc03f118aa (patch)
tree2fdd7a5fe227846a1b1f3015dcd25cdbdef68d70
parent9027aba0621018caf177611d9105213645efe491 (diff)
downloadcommunique-4f42b00ec18cfdf3f97527a6fe91babc03f118aa.tar.gz
return ordered collection for outbox instead of page
-rw-r--r--http/router.go8
-rw-r--r--registry/registry.go13
-rw-r--r--urls/urls.go11
-rw-r--r--views/outbox.go48
4 files changed, 10 insertions, 70 deletions
diff --git a/http/router.go b/http/router.go
index d5d0de5..a0cc351 100644
--- a/http/router.go
+++ b/http/router.go
@@ -82,13 +82,7 @@ func (s *Router) Start(zapWriter io.Writer) {
// Actor Outbox
router.GET("/actors/:actor/outbox", func(c *gin.Context) {
actorParam := c.Param("actor")
- var resource map[string]interface{}
- var err error
- if c.Query("page") == "true" {
- resource, err = s.registry.OutboxCollection(actorParam)
- } else {
- resource, err = s.registry.Outbox(actorParam)
- }
+ resource, err := s.registry.OutboxCollection(actorParam)
render(c, resource, err)
})
diff --git a/registry/registry.go b/registry/registry.go
index 451704e..16ae828 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -40,19 +40,6 @@ func (r *Registry) Actor(name string) (map[string]interface{}, error) {
return views.RenderActor(handler.handlerCfg.Name, r.cfg.Domain)
}
-func (r *Registry) Outbox(name string) (map[string]interface{}, error) {
- handler := r.findByName(name)
- if handler == nil {
- return nil, nil
- }
- aso := models.NewOutboxItem(handler.handlerCfg)
- totalItems, err := r.persister.Count(aso)
- if err != nil {
- return nil, err
- }
- return views.RenderOutbox(handler.handlerCfg.Name, r.cfg.Domain, totalItems)
-}
-
func (r *Registry) OutboxCollection(name string) (map[string]interface{}, error) {
handler := r.findByName(name)
if handler == nil {
diff --git a/urls/urls.go b/urls/urls.go
index 65aa042..d2bfb4a 100644
--- a/urls/urls.go
+++ b/urls/urls.go
@@ -44,14 +44,3 @@ func UrlActivity(name, domain, id string) (*url.URL, error) {
func UrlNote(name, domain, id string) (*url.URL, error) {
return linkTo("note", domain, "actors", name, "activity", id, "note")
}
-
-func UrlOutboxPage(name, domain string) (*url.URL, error) {
- u, err := UrlOutbox(name, domain)
- if err != nil {
- return nil, fmt.Errorf("could not build outbox page url: %w", err)
- }
- q := u.Query()
- q.Set("page", "true")
- u.RawQuery = q.Encode()
- return u, nil
-}
diff --git a/views/outbox.go b/views/outbox.go
index 4dd5ab5..c2b8015 100644
--- a/views/outbox.go
+++ b/views/outbox.go
@@ -11,15 +11,15 @@ import (
// RenderOutboxCollection takes a page of ActivityStream objects as JSON strings and concatenates them together to return an
// ActivtyStreamsOrderedCollection
func RenderOutboxCollection(name, domain string, page []models.OutboxItem) (map[string]interface{}, error) {
- id, err := urls.UrlOutboxPage(name, domain)
+ id, err := urls.UrlOutbox(name, domain)
if err != nil {
return nil, err
}
- partOf, err := urls.UrlOutbox(name, domain)
- if err != nil {
- return nil, err
- }
+ // partOf, err := urls.UrlOutbox(name, domain)
+ // if err != nil {
+ // return nil, err
+ // }
publicUrl, err := url.Parse("https://www.w3.org/ns/activitystreams#Public")
if err != nil {
return nil, err
@@ -27,16 +27,12 @@ func RenderOutboxCollection(name, domain string, page []models.OutboxItem) (map[
toProp := streams.NewActivityStreamsToProperty()
toProp.AppendIRI(publicUrl)
- oc := streams.NewActivityStreamsOrderedCollectionPage()
+ oc := streams.NewActivityStreamsOrderedCollection()
idProp := streams.NewJSONLDIdProperty()
idProp.Set(id)
oc.SetJSONLDId(idProp)
- partOfProp := streams.NewActivityStreamsPartOfProperty()
- partOfProp.SetIRI(partOf)
- oc.SetActivityStreamsPartOf(partOfProp)
-
itemsProp := streams.NewActivityStreamsOrderedItemsProperty()
for _, v := range page {
@@ -52,35 +48,9 @@ func RenderOutboxCollection(name, domain string, page []models.OutboxItem) (map[
itemsProp.AppendActivityStreamsCreate(crea)
}
+ totalProp := streams.NewActivityStreamsTotalItemsProperty()
+ totalProp.Set(20)
+ oc.SetActivityStreamsTotalItems(totalProp)
oc.SetActivityStreamsOrderedItems(itemsProp)
return streams.Serialize(oc)
}
-
-func RenderOutbox(name, domain string, totalItems int) (map[string]interface{}, error) {
- id, err := urls.UrlOutbox(name, domain)
-
- if err != nil {
- return nil, err
- }
-
- first, err := urls.UrlOutboxPage(name, domain)
- if err != nil {
- return nil, err
- }
-
- oc := streams.NewActivityStreamsOrderedCollection()
-
- idProp := streams.NewJSONLDIdProperty()
- idProp.Set(id)
- oc.SetJSONLDId(idProp)
-
- itemsProp := streams.NewActivityStreamsTotalItemsProperty()
- itemsProp.Set(totalItems)
- oc.SetActivityStreamsTotalItems(itemsProp)
-
- ocProp := streams.NewActivityStreamsFirstProperty()
- ocProp.SetIRI(first)
- oc.SetActivityStreamsFirst(ocProp)
-
- return streams.Serialize(oc)
-}