From 9965abccfb7812e0a5d3eebab556e8f26d4050bb Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 15 Aug 2021 17:32:43 +0200 Subject: [PATCH] Add option to hide feeds from the global Unread list --- client/model.go | 3 +++ database/migrations.go | 6 ++++++ locale/translations/de_DE.json | 1 + locale/translations/el_EL.json | 1 + locale/translations/en_US.json | 1 + locale/translations/es_ES.json | 1 + locale/translations/fr_FR.json | 1 + locale/translations/it_IT.json | 1 + locale/translations/ja_JP.json | 1 + locale/translations/nl_NL.json | 1 + locale/translations/pl_PL.json | 1 + locale/translations/pt_BR.json | 1 + locale/translations/ru_RU.json | 1 + locale/translations/tr_TR.json | 1 + locale/translations/zh_CN.json | 1 + model/feed.go | 7 +++++++ storage/entry.go | 5 ++++- storage/entry_query_builder.go | 1 + storage/feed.go | 12 ++++++++---- storage/feed_query_builder.go | 2 ++ template/templates/views/edit_feed.html | 1 + ui/feed_edit.go | 1 + ui/form/feed.go | 3 +++ 23 files changed, 49 insertions(+), 5 deletions(-) diff --git a/client/model.go b/client/model.go index 35af8899..9ed8de47 100644 --- a/client/model.go +++ b/client/model.go @@ -126,6 +126,7 @@ type Feed struct { Username string `json:"username"` Password string `json:"password"` Category *Category `json:"category,omitempty"` + HideGlobally bool `json:"hide_globally"` } // FeedCreationRequest represents the request to create a feed. @@ -145,6 +146,7 @@ type FeedCreationRequest struct { RewriteRules string `json:"rewrite_rules"` BlocklistRules string `json:"blocklist_rules"` KeeplistRules string `json:"keeplist_rules"` + HideGlobally bool `json:"hide_globally"` } // FeedModificationRequest represents the request to update a feed. @@ -166,6 +168,7 @@ type FeedModificationRequest struct { IgnoreHTTPCache *bool `json:"ignore_http_cache"` AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"` FetchViaProxy *bool `json:"fetch_via_proxy"` + HideGlobally *bool `json:"hide_globally"` } // FeedIcon represents the feed icon. diff --git a/database/migrations.go b/database/migrations.go index b2e901d6..18da44ed 100644 --- a/database/migrations.go +++ b/database/migrations.go @@ -540,4 +540,10 @@ var migrations = []func(tx *sql.Tx) error{ `) return err }, + func(tx *sql.Tx) (err error) { + _, err = tx.Exec(` + ALTER TABLE feeds ADD COLUMN hide_globally boolean not null default false + `) + return err + }, } diff --git a/locale/translations/de_DE.json b/locale/translations/de_DE.json index 257a333e..d2910973 100644 --- a/locale/translations/de_DE.json +++ b/locale/translations/de_DE.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Erlaube selbstsignierte oder ungültige Zertifikate", "form.feed.label.fetch_via_proxy": "Über Proxy abrufen", "form.feed.label.disabled": "Dieses Abonnement nicht aktualisieren", + "form.feed.label.hide_globally": "Einträge in der globalen Ungelesen-Liste ausblenden", "form.category.label.title": "Titel", "form.category.hide_globally": "Einträge in der globalen Ungelesen-Liste ausblenden", "form.user.label.username": "Benutzername", diff --git a/locale/translations/el_EL.json b/locale/translations/el_EL.json index 8a5411db..aee5c10b 100644 --- a/locale/translations/el_EL.json +++ b/locale/translations/el_EL.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Να επιτρέπονται αυτο-υπογεγραμμένα ή μη έγκυρα πιστοποιητικά", "form.feed.label.fetch_via_proxy": "Λήψη μέσω διακομιστή μεσολάβησης", "form.feed.label.disabled": "Μη ανανέωση αυτής της ροής", + "form.feed.label.hide_globally": "Απόκρυψη καταχωρήσεων σε γενική λίστα μη αναγνωσμένων", "form.category.label.title": "Τίτλος", "form.category.hide_globally": "Απόκρυψη καταχωρήσεων σε γενική λίστα μη αναγνωσμένων", "form.user.label.username": "Χρήστης", diff --git a/locale/translations/en_US.json b/locale/translations/en_US.json index cfe5a81f..7ed64552 100644 --- a/locale/translations/en_US.json +++ b/locale/translations/en_US.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Allow self-signed or invalid certificates", "form.feed.label.fetch_via_proxy": "Fetch via proxy", "form.feed.label.disabled": "Do not refresh this feed", + "form.feed.label.hide_globally": "Hide entries in global unread list", "form.category.label.title": "Title", "form.category.hide_globally": "Hide entries in global unread list", "form.user.label.username": "Username", diff --git a/locale/translations/es_ES.json b/locale/translations/es_ES.json index ee5b9a27..4a0172b1 100644 --- a/locale/translations/es_ES.json +++ b/locale/translations/es_ES.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Permitir certificados autofirmados o no válidos", "form.feed.label.fetch_via_proxy": "Buscar a través de proxy", "form.feed.label.disabled": "No actualice este feed", + "form.feed.label.hide_globally": "Ocultar entradas en la lista global de no leídos", "form.category.label.title": "Título", "form.category.hide_globally": "Ocultar entradas en la lista global de no leídos", "form.user.label.username": "Nombre de usuario", diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index c1843219..441617dc 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Autoriser les certificats auto-signés ou non valides", "form.feed.label.fetch_via_proxy": "Récupérer via proxy", "form.feed.label.disabled": "Ne pas actualiser ce flux", + "form.feed.label.hide_globally": "Masquer les entrées dans la liste globale non lue", "form.category.label.title": "Titre", "form.category.hide_globally": "Masquer les entrées dans la liste globale non lue", "form.user.label.username": "Nom d'utilisateur", diff --git a/locale/translations/it_IT.json b/locale/translations/it_IT.json index bdfc3a0f..a1cb5010 100644 --- a/locale/translations/it_IT.json +++ b/locale/translations/it_IT.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Consenti certificati autofirmati o non validi", "form.feed.label.fetch_via_proxy": "Recuperare tramite proxy", "form.feed.label.disabled": "Non aggiornare questo feed", + "form.feed.label.hide_globally": "Nascondere le voci nella lista globale dei non letti", "form.category.label.title": "Titolo", "form.category.hide_globally": "Nascondere le voci nella lista globale dei non letti", "form.user.label.username": "Nome utente", diff --git a/locale/translations/ja_JP.json b/locale/translations/ja_JP.json index e30705bc..8d03d038 100644 --- a/locale/translations/ja_JP.json +++ b/locale/translations/ja_JP.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "自己署名証明書または無効な証明書を許可する", "form.feed.label.fetch_via_proxy": "プロキシ経由でフェッチ", "form.feed.label.disabled": "このフィードを更新しない", + "form.feed.label.hide_globally": "グローバル未読リストのエントリーを隠す", "form.category.label.title": "タイトル", "form.category.hide_globally": "グローバル未読リストのエントリーを隠す", "form.user.label.username": "ユーザー名", diff --git a/locale/translations/nl_NL.json b/locale/translations/nl_NL.json index 91766eb6..287afbf4 100644 --- a/locale/translations/nl_NL.json +++ b/locale/translations/nl_NL.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Sta zelfondertekende of ongeldige certificaten toe", "form.feed.label.fetch_via_proxy": "Ophalen via proxy", "form.feed.label.disabled": "Vernieuw deze feed niet", + "form.feed.label.hide_globally": "Verberg items in de globale ongelezen lijst", "form.category.label.title": "Naam", "form.category.hide_globally": "Verberg items in de globale ongelezen lijst", "form.user.label.username": "Gebruikersnaam", diff --git a/locale/translations/pl_PL.json b/locale/translations/pl_PL.json index 2f92b4cf..c50f043a 100644 --- a/locale/translations/pl_PL.json +++ b/locale/translations/pl_PL.json @@ -278,6 +278,7 @@ "form.feed.label.allow_self_signed_certificates": "Zezwalaj na certyfikaty z podpisem własnym lub nieprawidłowe certyfikaty", "form.feed.label.fetch_via_proxy": "Pobierz przez proxy", "form.feed.label.disabled": "Не обновлять этот канал", + "form.feed.label.hide_globally": "Ukryj wpisy na globalnej liście nieprzeczytanych", "form.category.label.title": "Tytuł", "form.category.hide_globally": "Ukryj wpisy na globalnej liście nieprzeczytanych", "form.user.label.username": "Nazwa użytkownika", diff --git a/locale/translations/pt_BR.json b/locale/translations/pt_BR.json index ae27470f..3b163659 100644 --- a/locale/translations/pt_BR.json +++ b/locale/translations/pt_BR.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Permitir certificados autoassinados ou inválidos", "form.feed.label.disabled": "Não atualizar esta fonte", "form.feed.label.fetch_via_proxy": "Buscar via proxy", + "form.feed.label.hide_globally": "Ocultar entradas na lista global não lida", "form.category.label.title": "Título", "form.category.hide_globally": "Ocultar entradas na lista global não lida", "form.user.label.username": "Nome de usuário", diff --git a/locale/translations/ru_RU.json b/locale/translations/ru_RU.json index eb76b441..39055382 100644 --- a/locale/translations/ru_RU.json +++ b/locale/translations/ru_RU.json @@ -278,6 +278,7 @@ "form.feed.label.allow_self_signed_certificates": "Разрешить самоподписанные или недействительные сертификаты", "form.feed.label.fetch_via_proxy": "Получить через прокси", "form.feed.label.disabled": "Не обновлять этот канал", + "form.feed.label.hide_globally": "Скрыть записи в глобальном списке непрочитанных", "form.category.label.title": "Название", "form.category.hide_globally": "Скрыть записи в глобальном списке непрочитанных", "form.user.label.username": "Имя пользователя", diff --git a/locale/translations/tr_TR.json b/locale/translations/tr_TR.json index 06a39eac..1acf4141 100644 --- a/locale/translations/tr_TR.json +++ b/locale/translations/tr_TR.json @@ -276,6 +276,7 @@ "form.feed.label.allow_self_signed_certificates": "Kendinden imzalı veya geçersiz sertifikalara izin ver", "form.feed.label.fetch_via_proxy": "Proxy ile çek", "form.feed.label.disabled": "Bu beslemeyi yenileme", + "form.feed.label.hide_globally": "Genel okunmamış listesindeki girişleri gizle", "form.category.label.title": "Başlık", "form.category.hide_globally": "Genel okunmamış listesindeki girişleri gizle", "form.user.label.username": "Kullanıcı Adı", diff --git a/locale/translations/zh_CN.json b/locale/translations/zh_CN.json index 8893a487..8f0b6ff0 100644 --- a/locale/translations/zh_CN.json +++ b/locale/translations/zh_CN.json @@ -274,6 +274,7 @@ "form.feed.label.allow_self_signed_certificates": "允许自签名或无效的证书", "form.feed.label.fetch_via_proxy": "通过代理获取", "form.feed.label.disabled": "请勿刷新此Feed", + "form.feed.label.hide_globally": "隐藏全局未读列表中的条目", "form.category.label.title": "标题", "form.category.hide_globally": "隐藏全局未读列表中的条目", "form.user.label.username": "用户名", diff --git a/model/feed.go b/model/feed.go index 9ed668a3..519a1b59 100644 --- a/model/feed.go +++ b/model/feed.go @@ -51,6 +51,7 @@ type Feed struct { Category *Category `json:"category,omitempty"` Entries Entries `json:"entries,omitempty"` Icon *FeedIcon `json:"icon"` + HideGlobally bool `json:"hide_globally"` UnreadCount int `json:"-"` ReadCount int `json:"-"` } @@ -134,6 +135,7 @@ type FeedCreationRequest struct { RewriteRules string `json:"rewrite_rules"` BlocklistRules string `json:"blocklist_rules"` KeeplistRules string `json:"keeplist_rules"` + HideGlobally bool `json:"hide_globally"` } // FeedModificationRequest represents the request to update a feed. @@ -155,6 +157,7 @@ type FeedModificationRequest struct { IgnoreHTTPCache *bool `json:"ignore_http_cache"` AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"` FetchViaProxy *bool `json:"fetch_via_proxy"` + HideGlobally *bool `json:"hide_globally"` } // Patch updates a feed with modified values. @@ -226,6 +229,10 @@ func (f *FeedModificationRequest) Patch(feed *Feed) { if f.FetchViaProxy != nil { feed.FetchViaProxy = *f.FetchViaProxy } + + if f.HideGlobally != nil { + feed.HideGlobally = *f.HideGlobally + } } // Feeds is a list of feed diff --git a/storage/entry.go b/storage/entry.go index 03243467..4c4d0e78 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -357,7 +357,10 @@ func (s *Storage) SetEntriesStatusCount(userID int64, entryIDs []int64, status s FROM entries e JOIN feeds f ON (f.id = e.feed_id) JOIN categories c ON (c.id = f.category_id) - WHERE e.user_id = $1 AND e.id = ANY($2) AND NOT c.hide_globally + WHERE e.user_id = $1 + AND e.id = ANY($2) + AND NOT f.hide_globally + AND NOT c.hide_globally ` row := s.db.QueryRow(query, userID, pq.Array(entryIDs)) visible := 0 diff --git a/storage/entry_query_builder.go b/storage/entry_query_builder.go index 62def7f8..621d15ea 100644 --- a/storage/entry_query_builder.go +++ b/storage/entry_query_builder.go @@ -183,6 +183,7 @@ func (e *EntryQueryBuilder) WithOffset(offset int) *EntryQueryBuilder { func (e *EntryQueryBuilder) WithGloballyVisible() *EntryQueryBuilder { e.conditions = append(e.conditions, "not c.hide_globally") + e.conditions = append(e.conditions, "not f.hide_globally") return e } diff --git a/storage/feed.go b/storage/feed.go index ae0fb1b4..5198ed4b 100644 --- a/storage/feed.go +++ b/storage/feed.go @@ -233,10 +233,11 @@ func (s *Storage) CreateFeed(feed *model.Feed) error { keeplist_rules, ignore_http_cache, allow_self_signed_certificates, - fetch_via_proxy + fetch_via_proxy, + hide_globally ) VALUES - ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) + ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21) RETURNING id ` @@ -262,6 +263,7 @@ func (s *Storage) CreateFeed(feed *model.Feed) error { feed.IgnoreHTTPCache, feed.AllowSelfSignedCertificates, feed.FetchViaProxy, + feed.HideGlobally, ).Scan(&feed.ID) if err != nil { return fmt.Errorf(`store: unable to create feed %q: %v`, feed.FeedURL, err) @@ -319,9 +321,10 @@ func (s *Storage) UpdateFeed(feed *model.Feed) (err error) { next_check_at=$20, ignore_http_cache=$21, allow_self_signed_certificates=$22, - fetch_via_proxy=$23 + fetch_via_proxy=$23, + hide_globally=$24 WHERE - id=$24 AND user_id=$25 + id=$25 AND user_id=$26 ` _, err = s.db.Exec(query, feed.FeedURL, @@ -347,6 +350,7 @@ func (s *Storage) UpdateFeed(feed *model.Feed) (err error) { feed.IgnoreHTTPCache, feed.AllowSelfSignedCertificates, feed.FetchViaProxy, + feed.HideGlobally, feed.ID, feed.UserID, ) diff --git a/storage/feed_query_builder.go b/storage/feed_query_builder.go index dbb338ec..c095199d 100644 --- a/storage/feed_query_builder.go +++ b/storage/feed_query_builder.go @@ -166,6 +166,7 @@ func (f *FeedQueryBuilder) GetFeeds() (model.Feeds, error) { f.allow_self_signed_certificates, f.fetch_via_proxy, f.disabled, + f.hide_globally, f.category_id, c.title as category_title, fi.icon_id, @@ -226,6 +227,7 @@ func (f *FeedQueryBuilder) GetFeeds() (model.Feeds, error) { &feed.AllowSelfSignedCertificates, &feed.FetchViaProxy, &feed.Disabled, + &feed.HideGlobally, &feed.Category.ID, &feed.Category.Title, &iconID, diff --git a/template/templates/views/edit_feed.html b/template/templates/views/edit_feed.html index 017759c0..15b4439a 100644 --- a/template/templates/views/edit_feed.html +++ b/template/templates/views/edit_feed.html @@ -87,6 +87,7 @@ {{ end }} +
{{ t "action.or" }} {{ t "action.cancel" }} diff --git a/ui/feed_edit.go b/ui/feed_edit.go index 46421864..7eb2c460 100644 --- a/ui/feed_edit.go +++ b/ui/feed_edit.go @@ -58,6 +58,7 @@ func (h *handler) showEditFeedPage(w http.ResponseWriter, r *http.Request) { AllowSelfSignedCertificates: feed.AllowSelfSignedCertificates, FetchViaProxy: feed.FetchViaProxy, Disabled: feed.Disabled, + HideGlobally: feed.HideGlobally, } sess := session.New(h.store, request.SessionID(r)) diff --git a/ui/form/feed.go b/ui/form/feed.go index 0a937420..2aac4cc6 100644 --- a/ui/form/feed.go +++ b/ui/form/feed.go @@ -30,6 +30,7 @@ type FeedForm struct { AllowSelfSignedCertificates bool FetchViaProxy bool Disabled bool + HideGlobally bool } // Merge updates the fields of the given feed. @@ -53,6 +54,7 @@ func (f FeedForm) Merge(feed *model.Feed) *model.Feed { feed.AllowSelfSignedCertificates = f.AllowSelfSignedCertificates feed.FetchViaProxy = f.FetchViaProxy feed.Disabled = f.Disabled + feed.HideGlobally = f.HideGlobally return feed } @@ -80,5 +82,6 @@ func NewFeedForm(r *http.Request) *FeedForm { AllowSelfSignedCertificates: r.FormValue("allow_self_signed_certificates") == "1", FetchViaProxy: r.FormValue("fetch_via_proxy") == "1", Disabled: r.FormValue("disabled") == "1", + HideGlobally: r.FormValue("hide_globally") == "1", } }