diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-02 02:57:23 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-02 02:57:23 +0000 |
commit | 2148666991eb98fa6935f4f36fc29cf1e704f834 (patch) | |
tree | df9ef2db74685543d7458650b69ce89db14ae51a /registry/registry.go | |
parent | 5efad50005484e4bcd56fd68a46040e3d89b0efe (diff) | |
download | communique-2148666991eb98fa6935f4f36fc29cf1e704f834.tar.gz |
followers and following endpoints
Diffstat (limited to '')
-rw-r--r-- | registry/registry.go | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/registry/registry.go b/registry/registry.go index 13f2889..0a5df77 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -7,6 +7,7 @@ import ( "git.capotej.com/capotej/communique/config" "git.capotej.com/capotej/communique/models" + "git.capotej.com/capotej/communique/urls" "git.capotej.com/capotej/communique/views" ) @@ -62,7 +63,7 @@ func (r *Registry) OutboxCollection(name string) (map[string]interface{}, error) return nil, err } var outboxItems []models.OutboxItem - for _, v := range page { + for _, v := range page[0:20] { //TODO pagination buf := bytes.NewBuffer(v) dec := gob.NewDecoder(buf) var outboxItem models.OutboxItem @@ -74,29 +75,53 @@ func (r *Registry) OutboxCollection(name string) (map[string]interface{}, error) } return views.RenderOutboxCollection(handler.handlerCfg.Name, r.cfg.Domain, outboxItems) } +func (r *Registry) Following(name string) (map[string]interface{}, error) { + handler := r.findByName(name) + if handler == nil { + return nil, nil + } + profile, err := urls.UrlProfile(name, r.cfg.Domain) + if err != nil { + return nil, err + } + following, err := urls.UrlFollowing(name, r.cfg.Domain) + if err != nil { + return nil, err + } + result := make(map[string]interface{}) + result["@context"] = "https://www.w3.org/ns/activitystreams" + result["attributedTo"] = profile.String() + result["id"] = following.String() + result["totalItems"] = 0 + result["orderedItems"] = []bool{} + result["type"] = "OrderedCollection" + return result, nil +} -func (r *Registry) Activity(name, id string) (map[string]interface{}, error) { +func (r *Registry) Followers(name string) (map[string]interface{}, error) { handler := r.findByName(name) if handler == nil { return nil, nil } - lookup := models.NewOutboxItem(handler.handlerCfg) - lookup.Id = []byte(id) - result, err := r.persister.Find(lookup) + profile, err := urls.UrlProfile(name, r.cfg.Domain) if err != nil { return nil, err } - buf := bytes.NewBuffer(result) - dec := gob.NewDecoder(buf) - var outboxItem models.OutboxItem - err = dec.Decode(&outboxItem) + followers, err := urls.UrlFollowers(name, r.cfg.Domain) if err != nil { return nil, err } - return views.RenderActivity(handler.handlerCfg.Name, r.cfg.Domain, outboxItem) + result := make(map[string]interface{}) + result["@context"] = "https://www.w3.org/ns/activitystreams" + result["attributedTo"] = profile.String() + result["id"] = followers.String() + result["totalItems"] = 0 + result["orderedItems"] = []bool{} + result["type"] = "OrderedCollection" + return result, nil } -func (r *Registry) Note(name, id string) (map[string]interface{}, error) { +func (r *Registry) ActivityOrNote(activityOrNote, name, id string) (map[string]interface{}, error) { handler := r.findByName(name) if handler == nil { return nil, nil @@ -114,6 +139,9 @@ func (r *Registry) Note(name, id string) (map[string]interface{}, error) { if err != nil { return nil, err } + if activityOrNote == "activity" { + return views.RenderActivity(handler.handlerCfg.Name, r.cfg.Domain, outboxItem) + } return views.RenderNote(handler.handlerCfg.Name, r.cfg.Domain, outboxItem) } |