MCPcopy Index your code
hub / github.com/writefreely/writefreely / handleFetchCollectionOutbox

Function handleFetchCollectionOutbox

activitypub.go:154–215  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

152}
153
154func handleFetchCollectionOutbox(app *App, w http.ResponseWriter, r *http.Request) error {
155 w.Header().Set("Server", serverSoftware)
156
157 vars := mux.Vars(r)
158 alias := vars["alias"]
159
160 // TODO: enforce visibility
161 // Get base Collection data
162 var c *Collection
163 var err error
164 if app.cfg.App.SingleUser {
165 c, err = app.db.GetCollectionByID(1)
166 } else {
167 c, err = app.db.GetCollection(alias)
168 }
169 if err != nil {
170 return err
171 }
172 silenced, err := app.db.IsUserSilenced(c.OwnerID)
173 if err != nil {
174 log.Error("fetch collection outbox: %v", err)
175 return ErrInternalGeneral
176 }
177 if silenced {
178 return ErrCollectionNotFound
179 }
180 c.hostName = app.cfg.App.Host
181
182 if app.cfg.App.SingleUser {
183 if alias != c.Alias {
184 return ErrCollectionNotFound
185 }
186 }
187
188 res := &CollectionObj{Collection: *c}
189 app.db.GetPostsCount(res, false)
190 accountRoot := c.FederatedAccount()
191
192 page := r.FormValue("page")
193 p, err := strconv.Atoi(page)
194 if err != nil || p < 1 {
195 // Return outbox
196 oc := activitystreams.NewOrderedCollection(accountRoot, "outbox", res.TotalPosts)
197 return impart.RenderActivityJSON(w, oc, http.StatusOK)
198 }
199
200 // Return outbox page
201 ocp := activitystreams.NewOrderedCollectionPage(accountRoot, "outbox", res.TotalPosts, p)
202 ocp.OrderedItems = []interface{}{}
203
204 posts, err := app.db.GetPosts(app.cfg, c, p, false, true, false, "")
205 for _, pp := range *posts {
206 pp.Collection = res
207 o := pp.ActivityObject(app)
208 a := activitystreams.NewCreateActivity(o)
209 a.Context = nil
210 ocp.OrderedItems = append(ocp.OrderedItems, *a)
211 }

Callers

nothing calls this directly

Calls 8

FederatedAccountMethod · 0.95
setCacheControlFunction · 0.85
IsUserSilencedMethod · 0.80
ActivityObjectMethod · 0.80
GetCollectionByIDMethod · 0.65
GetCollectionMethod · 0.65
GetPostsCountMethod · 0.65
GetPostsMethod · 0.65

Tested by

no test coverage detected