MCPcopy
hub / github.com/writefreely/writefreely / showLocalTimeline

Function showLocalTimeline

read.go:184–248  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request, page int, author, tag string)

Source from the content-addressed store, hash-verified

182}
183
184func 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

Callers 1

viewLocalTimelineFunction · 0.85

Calls 8

updateTimelineCacheFunction · 0.85
pageForReqFunction · 0.85
getUserSessionFunction · 0.85
canUserInviteFunction · 0.85
getReaderSectionFunction · 0.85
applyMarkdownFunction · 0.85
HasTagMethod · 0.80
IsAdminMethod · 0.80

Tested by

no test coverage detected