unread.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "github.com/miniflux/miniflux/http/handler"
  7. "github.com/miniflux/miniflux/logger"
  8. "github.com/miniflux/miniflux/model"
  9. )
  10. // ShowUnreadPage render the page with all unread entries.
  11. func (c *Controller) ShowUnreadPage(ctx *handler.Context, request *handler.Request, response *handler.Response) {
  12. user := ctx.LoggedUser()
  13. offset := request.QueryIntegerParam("offset", 0)
  14. builder := c.store.NewEntryQueryBuilder(user.ID)
  15. builder.WithStatus(model.EntryStatusUnread)
  16. countUnread, err := builder.CountEntries()
  17. if err != nil {
  18. response.HTML().ServerError(err)
  19. return
  20. }
  21. if offset >= countUnread {
  22. offset = 0
  23. }
  24. builder = c.store.NewEntryQueryBuilder(user.ID)
  25. builder.WithStatus(model.EntryStatusUnread)
  26. builder.WithOrder(model.DefaultSortingOrder)
  27. builder.WithDirection(user.EntryDirection)
  28. builder.WithOffset(offset)
  29. builder.WithLimit(nbItemsPerPage)
  30. entries, err := builder.GetEntries()
  31. if err != nil {
  32. response.HTML().ServerError(err)
  33. return
  34. }
  35. response.HTML().Render("unread", tplParams{
  36. "user": user,
  37. "countUnread": countUnread,
  38. "entries": entries,
  39. "pagination": c.getPagination(ctx.Route("unread"), countUnread, offset),
  40. "menu": "unread",
  41. "csrf": ctx.CSRF(),
  42. })
  43. }
  44. // MarkAllAsRead marks all unread entries as read.
  45. func (c *Controller) MarkAllAsRead(ctx *handler.Context, request *handler.Request, response *handler.Response) {
  46. if err := c.store.MarkAllAsRead(ctx.UserID()); err != nil {
  47. logger.Error("[MarkAllAsRead] %v", err)
  48. }
  49. response.Redirect(ctx.Route("unread"))
  50. }