(app *App, w http.ResponseWriter, req *http.Request)
| 22 | ) |
| 23 | |
| 24 | func 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 | } |
nothing calls this directly
no test coverage detected