From e1c9e6ccb4607eeab2372793bc76abb50e8e0e7f Mon Sep 17 00:00:00 2001 From: Pedro Lucas Porcellis Date: Thu, 20 Aug 2020 02:17:33 -0300 Subject: [PATCH] Add link to mark a feed as read --- template/common.go | 5 ++++ template/html/common/feed_list.html | 5 ++++ ui/feed_mark_as_read.go | 37 +++++++++++++++++++++++++++++ ui/ui.go | 1 + 4 files changed, 48 insertions(+) create mode 100644 ui/feed_mark_as_read.go diff --git a/template/common.go b/template/common.go index da11d081..32acb24a 100644 --- a/template/common.go +++ b/template/common.go @@ -67,6 +67,11 @@ var templateCommonMap = map[string]string{ data-label-loading="{{ t "confirm.loading" }}" data-url="{{ route "removeFeed" "feedID" .ID }}">{{ template "icon_delete" }}{{ t "action.remove" }} + {{ if .UnreadCount }} +
  • + {{ template "icon_read" }}{{ t "menu.mark_all_as_read" }} +
  • + {{ end }} {{ if ne .ParsingErrorCount 0 }} diff --git a/template/html/common/feed_list.html b/template/html/common/feed_list.html index 8c63f74a..bd233260 100644 --- a/template/html/common/feed_list.html +++ b/template/html/common/feed_list.html @@ -42,6 +42,11 @@ data-label-loading="{{ t "confirm.loading" }}" data-url="{{ route "removeFeed" "feedID" .ID }}">{{ template "icon_delete" }}{{ t "action.remove" }} + {{ if .UnreadCount }} +
  • + {{ template "icon_read" }}{{ t "menu.mark_all_as_read" }} +
  • + {{ end }} {{ if ne .ParsingErrorCount 0 }} diff --git a/ui/feed_mark_as_read.go b/ui/feed_mark_as_read.go new file mode 100644 index 00000000..fce5646a --- /dev/null +++ b/ui/feed_mark_as_read.go @@ -0,0 +1,37 @@ +// 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. + +package ui // import "miniflux.app/ui" + +import ( + "net/http" + + "miniflux.app/http/request" + "miniflux.app/http/response/html" + "miniflux.app/http/route" +) + +func (h *handler) markFeedAsRead(w http.ResponseWriter, r *http.Request) { + feedID := request.RouteInt64Param(r, "feedID") + userID := request.UserID(r) + + feed, err := h.store.FeedByID(userID, feedID) + + if err != nil { + html.ServerError(w, r, err) + return + } + + if feed == nil { + html.NotFound(w, r) + return + } + + if err = h.store.MarkFeedAsRead(userID, feedID, feed.CheckedAt); err != nil { + html.ServerError(w, r, err) + return + } + + html.Redirect(w, r, route.Path(h.router, "feeds")) +} diff --git a/ui/ui.go b/ui/ui.go index 36c9fd7c..999a0f64 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -68,6 +68,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHa uiRouter.HandleFunc("/feed/{feedID}/entries/all", handler.showFeedEntriesAllPage).Name("feedEntriesAll").Methods(http.MethodGet) uiRouter.HandleFunc("/feed/{feedID}/entry/{entryID}", handler.showFeedEntryPage).Name("feedEntry").Methods(http.MethodGet) uiRouter.HandleFunc("/feed/icon/{iconID}", handler.showIcon).Name("icon").Methods(http.MethodGet) + uiRouter.HandleFunc("/feed/{feedID}/mark-all-as-read", handler.markFeedAsRead).Name("markFeedAsRead").Methods(http.MethodGet) // Category pages. uiRouter.HandleFunc("/category/{categoryID}/entry/{entryID}", handler.showCategoryEntryPage).Name("categoryEntry").Methods(http.MethodGet)