aboutsummaryrefslogtreecommitdiff
path: root/views/outbox.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--views/outbox.go (renamed from resources/outbox.go)87
1 files changed, 35 insertions, 52 deletions
diff --git a/resources/outbox.go b/views/outbox.go
index e7004c4..fe87e24 100644
--- a/resources/outbox.go
+++ b/views/outbox.go
@@ -1,12 +1,11 @@
-package resources
+package views
import (
"git.capotej.com/capotej/communique/urls"
- "github.com/dgraph-io/badger/v3"
"github.com/go-fed/activity/streams"
)
-func RenderOutboxPage(name, domain string, db *badger.DB) (map[string]interface{}, error) {
+func RenderOutboxPage(name, domain string) (map[string]interface{}, error) {
id, err := urls.UrlOutboxPage(name, domain)
if err != nil {
return nil, err
@@ -29,43 +28,43 @@ func RenderOutboxPage(name, domain string, db *badger.DB) (map[string]interface{
itemsProp := streams.NewActivityStreamsOrderedItemsProperty()
- err = db.View(func(txn *badger.Txn) error {
- opts := badger.DefaultIteratorOptions
- opts.PrefetchValues = false
- it := txn.NewIterator(opts)
- defer it.Close()
- prefix := []byte("outbox:sample") // TODO
- for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
- item := it.Item()
- err := item.Value(func(v []byte) error {
- crea := streams.NewActivityStreamsCreate()
- obj := streams.NewActivityStreamsObjectProperty()
- crea.SetActivityStreamsObject(obj)
-
- note := streams.NewActivityStreamsNote()
- contentProp := streams.NewActivityStreamsContentProperty()
- contentProp.AppendXMLSchemaString(string(v))
- note.SetActivityStreamsContent(contentProp)
- obj.AppendActivityStreamsNote(note)
-
- itemsProp.AppendActivityStreamsCreate(crea)
- return nil
- })
- if err != nil {
- return err
- }
- }
- return nil
- })
- if err != nil {
- return nil, err
- }
+ // err = db.View(func(txn *badger.Txn) error {
+ // opts := badger.DefaultIteratorOptions
+ // opts.PrefetchValues = false
+ // it := txn.NewIterator(opts)
+ // defer it.Close()
+ // prefix := []byte("outbox:sample") // TODO
+ // for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
+ // item := it.Item()
+ // err := item.Value(func(v []byte) error {
+ // crea := streams.NewActivityStreamsCreate()
+ // obj := streams.NewActivityStreamsObjectProperty()
+ // crea.SetActivityStreamsObject(obj)
+
+ // note := streams.NewActivityStreamsNote()
+ // contentProp := streams.NewActivityStreamsContentProperty()
+ // contentProp.AppendXMLSchemaString(string(v))
+ // note.SetActivityStreamsContent(contentProp)
+ // obj.AppendActivityStreamsNote(note)
+
+ // itemsProp.AppendActivityStreamsCreate(crea)
+ // return nil
+ // })
+ // if err != nil {
+ // return err
+ // }
+ // }
+ // return nil
+ // })
+ // if err != nil {
+ // return nil, err
+ // }
oc.SetActivityStreamsOrderedItems(itemsProp)
return streams.Serialize(oc)
}
-func RenderOutbox(name, domain string, db *badger.DB) (map[string]interface{}, error) {
+func RenderOutbox(name, domain string, totalItems int) (map[string]interface{}, error) {
id, err := urls.UrlOutbox(name, domain)
if err != nil {
@@ -83,24 +82,8 @@ func RenderOutbox(name, domain string, db *badger.DB) (map[string]interface{}, e
idProp.Set(id)
oc.SetJSONLDId(idProp)
- var i int
- // err = db.View(func(txn *badger.Txn) error {
- // opts := badger.DefaultIteratorOptions
- // opts.PrefetchValues = false
- // it := txn.NewIterator(opts)
- // defer it.Close()
- // prefix := []byte("outbox:sample") // TODO
- // for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
- // i++
- // }
- // return nil
- // })
- // if err != nil {
- // return nil, err
- // }
-
itemsProp := streams.NewActivityStreamsTotalItemsProperty()
- itemsProp.Set(i)
+ itemsProp.Set(totalItems)
oc.SetActivityStreamsTotalItems(itemsProp)
ocProp := streams.NewActivityStreamsFirstProperty()