diff options
author | Julio Capote <jcapote@gmail.com> | 2022-12-29 20:08:16 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-12-29 20:08:16 +0000 |
commit | a4288b06bf13210721c8f2fae64bc12c118f9041 (patch) | |
tree | 49808a68d61aa450c6625477e468968fd3198ded /views | |
parent | 5a990719a02f4fd33817a2188be17b3b50498b49 (diff) | |
download | communique-a4288b06bf13210721c8f2fae64bc12c118f9041.tar.gz |
refactor
Diffstat (limited to '')
-rw-r--r-- | views/outbox.go (renamed from resources/outbox.go) | 87 | ||||
-rw-r--r-- | views/profile.go (renamed from resources/profile.go) | 2 | ||||
-rw-r--r-- | views/webfinger.go (renamed from resources/webfinger.go) | 2 |
3 files changed, 37 insertions, 54 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() diff --git a/resources/profile.go b/views/profile.go index 971b11c..12aae54 100644 --- a/resources/profile.go +++ b/views/profile.go @@ -1,4 +1,4 @@ -package resources +package views import ( "git.capotej.com/capotej/communique/urls" diff --git a/resources/webfinger.go b/views/webfinger.go index e7c47ea..4252bae 100644 --- a/resources/webfinger.go +++ b/views/webfinger.go @@ -1,4 +1,4 @@ -package resources +package views import ( "fmt" |