From 2148666991eb98fa6935f4f36fc29cf1e704f834 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sun, 1 Jan 2023 21:57:23 -0500 Subject: followers and following endpoints --- registry/registry.go | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'registry/registry.go') 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) } -- cgit v1.2.3