(app *App, w http.ResponseWriter, r *http.Request, page int, author, tag string)
| 182 | } |
| 183 | |
| 184 | func showLocalTimeline(app *App, w http.ResponseWriter, r *http.Request, page int, author, tag string) error { |
| 185 | updateTimelineCache(app.timeline, false) |
| 186 | |
| 187 | pl := len(*(app.timeline.posts)) |
| 188 | ttlPages := int(math.Ceil(float64(pl) / float64(app.timeline.postsPerPage))) |
| 189 | |
| 190 | start := 0 |
| 191 | if page > 1 { |
| 192 | start = app.timeline.postsPerPage * (page - 1) |
| 193 | if start > pl { |
| 194 | return impart.HTTPError{http.StatusFound, fmt.Sprintf("/read/p/%d", ttlPages)} |
| 195 | } |
| 196 | } |
| 197 | end := app.timeline.postsPerPage * page |
| 198 | if end > pl { |
| 199 | end = pl |
| 200 | } |
| 201 | var posts []PublicPost |
| 202 | if author != "" { |
| 203 | posts = []PublicPost{} |
| 204 | for _, p := range *app.timeline.posts { |
| 205 | if author == "anonymous" { |
| 206 | if p.Collection == nil { |
| 207 | posts = append(posts, p) |
| 208 | } |
| 209 | } else if p.Collection != nil && p.Collection.Alias == author { |
| 210 | posts = append(posts, p) |
| 211 | } |
| 212 | } |
| 213 | } else if tag != "" { |
| 214 | posts = []PublicPost{} |
| 215 | for _, p := range *app.timeline.posts { |
| 216 | if p.HasTag(tag) { |
| 217 | posts = append(posts, p) |
| 218 | } |
| 219 | } |
| 220 | } else { |
| 221 | posts = *app.timeline.posts |
| 222 | posts = posts[start:end] |
| 223 | } |
| 224 | |
| 225 | d := &readPublication{ |
| 226 | StaticPage: pageForReq(app, r), |
| 227 | Posts: &posts, |
| 228 | CurrentPage: page, |
| 229 | TotalPages: ttlPages, |
| 230 | SelTopic: tag, |
| 231 | } |
| 232 | u := getUserSession(app, r) |
| 233 | d.IsAdmin = u != nil && u.IsAdmin() |
| 234 | d.CanInvite = canUserInvite(app.cfg, d.IsAdmin) |
| 235 | c, err := getReaderSection(app) |
| 236 | if err != nil { |
| 237 | return err |
| 238 | } |
| 239 | d.ContentTitle = c.Title.String |
| 240 | d.Content = template.HTML(applyMarkdown([]byte(c.Content), "", app.cfg)) |
| 241 |
no test coverage detected