hide_from_signals on a subscription, on an OPML or creator covering every show in it, as hide_from_all does for All Subscriptions: the judge does not put its items to Jev, and each Signal's list and counts leave them out. shown_in() is the one SQL rule for both. The settings dialog had grown one captioned setting at a time into a single column, one part boxed and the rest not. It is in named parts now, the name in a column beside the controls and above them on a phone, ruled apart; All Subscriptions and Signals carry the sidebar's icons. The address, the same for everyone, moves to the foot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -126,6 +126,10 @@ async fn create_missing(orm: &sea_orm::DatabaseConnection) -> Result<()> {
|
||||
let sql = "ALTER TABLE subscriptions ADD COLUMN hide_from_all BOOLEAN NOT NULL DEFAULT false";
|
||||
orm.execute_unprepared(sql).await.with_context(|| sql.to_owned())?;
|
||||
}
|
||||
if orm.execute_unprepared("SELECT hide_from_signals FROM subscriptions LIMIT 0").await.is_err() {
|
||||
let sql = "ALTER TABLE subscriptions ADD COLUMN hide_from_signals BOOLEAN NOT NULL DEFAULT false";
|
||||
orm.execute_unprepared(sql).await.with_context(|| sql.to_owned())?;
|
||||
}
|
||||
if orm.execute_unprepared("SELECT description FROM signals LIMIT 0").await.is_err() {
|
||||
// Every verdict so far answered the old question, any one keyword on its own, which put
|
||||
// a game's remaster in AI Development (#259): all of them are asked again.
|
||||
@@ -1190,15 +1194,21 @@ fn entries_from(
|
||||
Some([f]) => format!("e.feed_id = {}", a.p(*f)),
|
||||
Some([]) => "false".into(),
|
||||
Some(fs) => format!("e.feed_id IN ({})", fs.iter().map(|f| a.p(*f)).collect::<Vec<_>>().join(", ")),
|
||||
// All Subscriptions leaves out what this person hid from it, on the feed or on its OPML
|
||||
// (#288). A Signal reads every feed, and an episode under way still shows in Currently
|
||||
// Listening, which is this list's in-progress filter.
|
||||
None if signal.is_none() && filter != Filter::InProgress => format!(
|
||||
"e.feed_id IN (SELECT m.feed_id FROM subscriptions m JOIN feeds f ON f.id = m.feed_id
|
||||
WHERE m.user_id = {user} AND NOT m.hide_from_all
|
||||
AND NOT EXISTS (SELECT 1 FROM subscriptions g
|
||||
WHERE g.user_id = {user} AND g.feed_id = f.group_id AND g.hide_from_all))"
|
||||
),
|
||||
// A Signal and All Subscriptions leave out what this person hid from them (#288, #289).
|
||||
// An episode under way still shows in Currently Listening, which is All Subscriptions'
|
||||
// in-progress filter.
|
||||
None if signal.is_some() => {
|
||||
format!(
|
||||
"e.feed_id IN (SELECT m.feed_id FROM subscriptions m WHERE m.user_id = {user} AND {})",
|
||||
shown_in("hide_from_signals", "m")
|
||||
)
|
||||
}
|
||||
None if filter != Filter::InProgress => {
|
||||
format!(
|
||||
"e.feed_id IN (SELECT m.feed_id FROM subscriptions m WHERE m.user_id = {user} AND {})",
|
||||
shown_in("hide_from_all", "m")
|
||||
)
|
||||
}
|
||||
None => format!("e.feed_id IN (SELECT feed_id FROM subscriptions WHERE user_id = {user})"),
|
||||
};
|
||||
if let Some(id) = signal {
|
||||
@@ -1226,6 +1236,15 @@ fn entries_from(
|
||||
)
|
||||
}
|
||||
|
||||
/// A subscription, `s`, not hidden from All Subscriptions or from Signals by `column`: neither on
|
||||
/// the feed nor on the OPML or Patreon creator it is in (#288, #289).
|
||||
fn shown_in(column: &str, s: &str) -> String {
|
||||
format!(
|
||||
"NOT {s}.{column} AND NOT EXISTS (SELECT 1 FROM feeds lf JOIN subscriptions lg
|
||||
ON lg.user_id = {s}.user_id AND lg.feed_id = lf.group_id WHERE lf.id = {s}.feed_id AND lg.{column})"
|
||||
)
|
||||
}
|
||||
|
||||
/// Not hidden from this person by their block lists. `e` is entries.
|
||||
fn not_hidden(user: &str) -> String {
|
||||
format!(
|
||||
@@ -1880,22 +1899,44 @@ impl Db {
|
||||
Ok(r.rows_affected > 0)
|
||||
}
|
||||
|
||||
/// The feeds and lists this person hid from All Subscriptions (#288).
|
||||
pub async fn hidden_from_all(&self, user_id: i64) -> Result<std::collections::HashSet<String>> {
|
||||
Ok(subscriptions::Entity::find()
|
||||
.filter(subscriptions::Column::UserId.eq(user_id))
|
||||
.filter(subscriptions::Column::HideFromAll.eq(true))
|
||||
.all(&self.orm)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|s| s.feed_id)
|
||||
.collect())
|
||||
/// The feeds and lists this person hid from All Subscriptions (#288) and from Signals (#289).
|
||||
pub async fn hidden_from(
|
||||
&self,
|
||||
user_id: i64,
|
||||
) -> Result<(std::collections::HashSet<String>, std::collections::HashSet<String>)> {
|
||||
let (mut all, mut signals) = (std::collections::HashSet::new(), std::collections::HashSet::new());
|
||||
let rows =
|
||||
subscriptions::Entity::find().filter(subscriptions::Column::UserId.eq(user_id)).all(&self.orm).await?;
|
||||
for s in rows {
|
||||
if s.hide_from_all {
|
||||
all.insert(s.feed_id.clone());
|
||||
}
|
||||
if s.hide_from_signals {
|
||||
signals.insert(s.feed_id);
|
||||
}
|
||||
}
|
||||
Ok((all, signals))
|
||||
}
|
||||
|
||||
/// False when they do not subscribe to it, as `set_pinned`.
|
||||
pub async fn set_hide_from_all(&self, user_id: i64, feed_id: &str, on: bool) -> Result<bool> {
|
||||
self.set_hidden_from(subscriptions::Column::HideFromAll, user_id, feed_id, on).await
|
||||
}
|
||||
|
||||
/// As `set_hide_from_all`, for Signals (#289).
|
||||
pub async fn set_hide_from_signals(&self, user_id: i64, feed_id: &str, on: bool) -> Result<bool> {
|
||||
self.set_hidden_from(subscriptions::Column::HideFromSignals, user_id, feed_id, on).await
|
||||
}
|
||||
|
||||
async fn set_hidden_from(
|
||||
&self,
|
||||
column: subscriptions::Column,
|
||||
user_id: i64,
|
||||
feed_id: &str,
|
||||
on: bool,
|
||||
) -> Result<bool> {
|
||||
let r = subscriptions::Entity::update_many()
|
||||
.col_expr(subscriptions::Column::HideFromAll, Expr::val(on))
|
||||
.col_expr(column, Expr::val(on))
|
||||
.filter(subscriptions::Column::UserId.eq(user_id))
|
||||
.filter(subscriptions::Column::FeedId.eq(feed_id))
|
||||
.exec(&self.orm)
|
||||
@@ -2749,8 +2790,9 @@ impl Db {
|
||||
JOIN entries e ON e.feed_id = v.feed_id AND e.guid = v.guid
|
||||
JOIN subscriptions s ON s.user_id = g.user_id AND s.feed_id = v.feed_id
|
||||
LEFT JOIN entry_state st ON st.user_id = g.user_id AND st.feed_id = v.feed_id AND st.guid = v.guid
|
||||
WHERE v.signal_id = g.id AND v.hit AND {unread} AND {})",
|
||||
not_hidden(&user)
|
||||
WHERE v.signal_id = g.id AND v.hit AND {unread} AND {} AND {})",
|
||||
not_hidden(&user),
|
||||
shown_in("hide_from_signals", "s")
|
||||
)
|
||||
};
|
||||
let sql = format!(
|
||||
@@ -2869,6 +2911,8 @@ impl Db {
|
||||
};
|
||||
let limit = a.p(limit);
|
||||
let keyed = if everyone { "true" } else { "u.typesafe_key IS NOT NULL" };
|
||||
// A feed kept out of Signals is not put to Jev at all, so it costs nothing (#289).
|
||||
let in_signals = shown_in("hide_from_signals", "s");
|
||||
// Two halves, not one OR: the recent half reads entries_recent, and the rechecks are a few
|
||||
// rows of signal_verdicts. The same placeholders serve both.
|
||||
let half = |items: &str| {
|
||||
@@ -2880,7 +2924,7 @@ impl Db {
|
||||
JOIN subscriptions s ON s.user_id = g.user_id
|
||||
{items}
|
||||
LEFT JOIN feeds f ON f.id = e.feed_id
|
||||
WHERE {keyed} {skip}
|
||||
WHERE {keyed} {skip} AND {in_signals}
|
||||
AND NOT EXISTS (SELECT 1 FROM hidden h
|
||||
WHERE h.user_id = g.user_id AND h.feed_id = e.feed_id AND h.guid = e.guid)"
|
||||
)
|
||||
@@ -3798,6 +3842,42 @@ mod tests {
|
||||
assert_eq!(all(1, Filter::All).await, ["D four", "B two", "A one"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_feed_kept_out_of_signals_is_neither_judged_nor_listed() {
|
||||
let db = Db::memory().await.unwrap();
|
||||
let now = now();
|
||||
db.exec_for_test(&format!(
|
||||
"INSERT INTO users (id, name, is_admin, typesafe_key) VALUES (1,'a',true,'k');
|
||||
INSERT INTO feeds (id, url, group_id, managed) VALUES ('a','u1','o',true), ('c','u3',NULL,false), ('d','u4',NULL,false);
|
||||
INSERT INTO subscriptions (user_id, feed_id) VALUES (1,'o'), (1,'a'), (1,'c'), (1,'d');
|
||||
INSERT INTO signals (id, user_id, name, keywords, created) VALUES (9, 1, 'S', '[\"x\"]', {now});
|
||||
INSERT INTO entries (feed_id, guid, title, first_seen) VALUES ('a','1','A one',{now}), ('c','3','C three',{now}), ('d','4','D four',{now});
|
||||
INSERT INTO signal_verdicts (signal_id, feed_id, guid, hit, recheck) VALUES (9,'a','1',true,false), (9,'c','3',true,false);"
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
let judged = async || {
|
||||
let mut f: Vec<_> = db.unjudged(&[], 50, false, 30).await.unwrap().into_iter().map(|u| u.feed_id).collect();
|
||||
f.sort();
|
||||
f
|
||||
};
|
||||
let order = order_sql("published", "desc");
|
||||
let listed = async || {
|
||||
let rows = db.signal_entries(1, 9, Filter::All, None, 0, 50, &order).await.unwrap();
|
||||
let n = db.signal_count(1, 9, Filter::All, None).await.unwrap();
|
||||
assert_eq!(rows.len() as i64, n, "the count is of the same list");
|
||||
assert_eq!(db.signal(1, 9).await.unwrap().unwrap().items, n, "and the Signal's own count");
|
||||
rows.into_iter().map(|r| r.title.unwrap()).collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(judged().await, ["d"]);
|
||||
assert_eq!(listed().await, ["C three", "A one"]);
|
||||
assert!(db.set_hide_from_signals(1, "o", true).await.unwrap());
|
||||
assert!(db.set_hide_from_signals(1, "d", true).await.unwrap());
|
||||
assert_eq!(judged().await, Vec::<String>::new(), "Jev is not asked about a hidden feed");
|
||||
assert_eq!(listed().await, ["C three"], "the OPML's show left out with it");
|
||||
assert_eq!(db.count_of(1, None, Filter::All, None).await.unwrap(), 3, "All Subscriptions keeps them");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn pending_takes_the_latest_episodes_first() {
|
||||
// A cap of 3 must mean the three newest, not the three recorded first.
|
||||
|
||||
Reference in New Issue
Block a user