diff options
Diffstat (limited to 'ui/entry_unread.go')
-rw-r--r-- | ui/entry_unread.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/ui/entry_unread.go b/ui/entry_unread.go index a599bcc..0b6c001 100644 --- a/ui/entry_unread.go +++ b/ui/entry_unread.go @@ -49,6 +49,16 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { return } + // Make sure we always get the pagination in unread mode even if the page is refreshed. + if entry.Status == model.EntryStatusRead { + err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusUnread) + if err != nil { + logger.Error("[Controller:ShowUnreadEntry] %v", err) + html.ServerError(w, nil) + return + } + } + entryPaginationBuilder := storage.NewEntryPaginationBuilder(c.store, user.ID, entry.ID, user.EntryDirection) entryPaginationBuilder.WithStatus(model.EntryStatusUnread) prevEntry, nextEntry, err := entryPaginationBuilder.Entries() @@ -86,8 +96,10 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { view.Set("prevEntryRoute", prevEntryRoute) view.Set("menu", "unread") view.Set("user", user) - view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) view.Set("hasSaveEntry", c.store.HasSaveEntry(user.ID)) + // Fetching the counter here avoid to be off by one. + view.Set("countUnread", c.store.CountUnreadEntries(user.ID)) + html.OK(w, view.Render("entry")) } |