2018-04-29 19:35:04 -04:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-10-07 21:42:43 -04:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/http/request"
|
|
|
|
"miniflux.app/http/response/html"
|
|
|
|
"miniflux.app/http/route"
|
|
|
|
"miniflux.app/model"
|
|
|
|
"miniflux.app/ui/session"
|
|
|
|
"miniflux.app/ui/view"
|
2020-12-18 18:08:17 -05:00
|
|
|
|
|
|
|
servertiming "github.com/mitchellh/go-server-timing"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) showUnreadPage(w http.ResponseWriter, r *http.Request) {
|
2020-12-18 18:08:17 -05:00
|
|
|
timing := servertiming.FromContext(r.Context())
|
|
|
|
prep := timing.NewMetric("pre_processing").Start()
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:08:17 -05:00
|
|
|
m := timing.NewMetric("sql_count_unread_entries").Start()
|
2018-04-29 19:35:04 -04:00
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
2018-11-11 14:28:29 -05:00
|
|
|
builder := h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2021-06-02 20:39:47 -04:00
|
|
|
builder.WithGloballyVisible()
|
2018-04-29 19:35:04 -04:00
|
|
|
countUnread, err := builder.CountEntries()
|
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
2020-12-18 18:08:17 -05:00
|
|
|
m.Stop()
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
if offset >= countUnread {
|
|
|
|
offset = 0
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:08:17 -05:00
|
|
|
m = timing.NewMetric("sql_fetch_unread_entries").Start()
|
2018-11-11 14:28:29 -05:00
|
|
|
builder = h.store.NewEntryQueryBuilder(user.ID)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithStatus(model.EntryStatusUnread)
|
2021-05-14 07:51:51 -04:00
|
|
|
builder.WithOrder(user.EntryOrder)
|
2018-04-29 19:35:04 -04:00
|
|
|
builder.WithDirection(user.EntryDirection)
|
|
|
|
builder.WithOffset(offset)
|
2020-07-08 19:24:54 -04:00
|
|
|
builder.WithLimit(user.EntriesPerPage)
|
2021-06-02 20:39:47 -04:00
|
|
|
builder.WithGloballyVisible()
|
2018-04-29 19:35:04 -04:00
|
|
|
entries, err := builder.GetEntries()
|
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
2020-12-18 18:08:17 -05:00
|
|
|
m.Stop()
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
view.Set("entries", entries)
|
2020-07-08 19:24:54 -04:00
|
|
|
view.Set("pagination", getPagination(route.Path(h.router, "unread"), countUnread, offset, user.EntriesPerPage))
|
2018-04-29 19:35:04 -04:00
|
|
|
view.Set("menu", "unread")
|
|
|
|
view.Set("user", user)
|
2018-06-09 16:40:20 -04:00
|
|
|
view.Set("countUnread", countUnread)
|
2020-09-27 19:01:06 -04:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2018-11-11 14:28:29 -05:00
|
|
|
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2020-12-18 18:08:17 -05:00
|
|
|
prep.Stop()
|
|
|
|
|
|
|
|
m = timing.NewMetric("template_rendering").Start()
|
|
|
|
render := view.Render("unread_entries")
|
|
|
|
m.Stop()
|
|
|
|
|
|
|
|
html.OK(w, r, render)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|