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 /registry | |
parent | 5a990719a02f4fd33817a2188be17b3b50498b49 (diff) | |
download | communique-a4288b06bf13210721c8f2fae64bc12c118f9041.tar.gz |
refactor
Diffstat (limited to '')
-rw-r--r-- | registry/registry.go | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/registry/registry.go b/registry/registry.go index 4dbacc7..f57aede 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -4,8 +4,8 @@ import ( "fmt" "git.capotej.com/capotej/communique/config" - "git.capotej.com/capotej/communique/resources" - "github.com/dgraph-io/badger/v3" + "git.capotej.com/capotej/communique/models" + "git.capotej.com/capotej/communique/views" ) type Handler struct { @@ -14,12 +14,12 @@ type Handler struct { type Registry struct { cfg config.Config - db *badger.DB + persister *models.Persister handlerMap map[string]Handler } -func NewRegistry(cfg config.Config, db *badger.DB) *Registry { - reg := Registry{cfg: cfg, db: db} +func NewRegistry(cfg config.Config, persister *models.Persister) *Registry { + reg := Registry{cfg: cfg, persister: persister} reg.handlerMap = make(map[string]Handler) for _, v := range cfg.Handlers { reg.handlerMap[fqn(v.Name, cfg.Domain)] = Handler{handlerCfg: v} @@ -32,7 +32,7 @@ func (r *Registry) Profile(name string) (map[string]interface{}, error) { if handler == nil { return nil, nil } - return resources.RenderProfile(handler.handlerCfg.Name, r.cfg.Domain) + return views.RenderProfile(handler.handlerCfg.Name, r.cfg.Domain) } func (r *Registry) Outbox(name string) (map[string]interface{}, error) { @@ -40,7 +40,12 @@ func (r *Registry) Outbox(name string) (map[string]interface{}, error) { if handler == nil { return nil, nil } - return resources.RenderOutbox(handler.handlerCfg.Name, r.cfg.Domain, r.db) + aso := models.NewActivityStreamsObject(nil, 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) OutboxPage(name string) (map[string]interface{}, error) { @@ -48,10 +53,10 @@ func (r *Registry) OutboxPage(name string) (map[string]interface{}, error) { if handler == nil { return nil, nil } - return resources.RenderOutboxPage(handler.handlerCfg.Name, r.cfg.Domain, r.db) + return views.RenderOutboxPage(handler.handlerCfg.Name, r.cfg.Domain) } -func (r *Registry) WebfingerResource(fqn string) (*resources.WebfingerResource, error) { +func (r *Registry) WebfingerResource(fqn string) (*views.WebfingerResource, error) { handler := r.findByFQN(fqn) if handler == nil { handler = r.findByFQN("acct:" + fqn) @@ -59,7 +64,7 @@ func (r *Registry) WebfingerResource(fqn string) (*resources.WebfingerResource, if handler == nil { return nil, nil } - return resources.RenderWebfingerResource(handler.handlerCfg.Name, r.cfg.Domain) + return views.RenderWebfingerResource(handler.handlerCfg.Name, r.cfg.Domain) } func fqn(name, domain string) string { |