MCPcopy
hub / github.com/writefreely/writefreely / ViewFeed

Function ViewFeed

feed.go:24–125  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

22)
23
24func ViewFeed(app *App, w http.ResponseWriter, req *http.Request) error {
25 alias := collectionAliasFromReq(req)
26
27 // Display collection if this is a collection
28 var c *Collection
29 var err error
30 if app.cfg.App.SingleUser {
31 c, err = app.db.GetCollectionByID(1)
32 } else {
33 c, err = app.db.GetCollection(alias)
34 }
35 if err != nil {
36 return nil
37 }
38
39 silenced, err := app.db.IsUserSilenced(c.OwnerID)
40 if err != nil {
41 log.Error("view feed: get user: %v", err)
42 return ErrInternalGeneral
43 }
44 if silenced {
45 return ErrCollectionNotFound
46 }
47 c.hostName = app.cfg.App.Host
48
49 if c.IsPrivate() || c.IsProtected() {
50 return ErrCollectionNotFound
51 }
52
53 // Fetch extra data about the Collection
54 // TODO: refactor out this logic, shared in collection.go:fetchCollection()
55 coll := &DisplayCollection{CollectionObj: &CollectionObj{Collection: *c}}
56 if c.PublicOwner {
57 u, err := app.db.GetUserByID(coll.OwnerID)
58 if err != nil {
59 // Log the error and just continue
60 log.Error("Error getting user for collection: %v", err)
61 } else {
62 coll.Owner = u
63 }
64 }
65
66 tag := mux.Vars(req)["tag"]
67 if tag != "" {
68 coll.Posts, _ = app.db.GetPostsTagged(app.cfg, c, tag, 1, false)
69 } else {
70 coll.Posts, _ = app.db.GetPosts(app.cfg, c, 1, false, true, false, "")
71 }
72
73 author := ""
74 if coll.Owner != nil {
75 author = coll.Owner.Username
76 }
77
78 collectionTitle := coll.DisplayTitle()
79 if tag != "" {
80 collectionTitle = tag + " — " + collectionTitle
81 }

Callers

nothing calls this directly

Calls 13

IsPrivateMethod · 0.95
IsProtectedMethod · 0.95
collectionAliasFromReqFunction · 0.85
IsUserSilencedMethod · 0.80
PlainDisplayTitleMethod · 0.80
GetCollectionByIDMethod · 0.65
GetCollectionMethod · 0.65
GetUserByIDMethod · 0.65
GetPostsTaggedMethod · 0.65
GetPostsMethod · 0.65
DisplayTitleMethod · 0.45

Tested by

no test coverage detected