Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## Unreleased

- Household multi-step chores: a multi-step chore belongs to its project's owner, so one
in a project shared with your household is everyone's, and anyone in it can start it.
Sharing a project shares its multi-step chores too.
- The Routines page lists your own routines and multi-step chores first, then each
household group's under "Shared with …".
- Who does it: give a shared task to one person. Everyone still sees it ("→ Ben") and
anyone can tick it off, but it only shows up on that person's Today, planner and morning
digest.
- Routines and multi-step chores can give what they make to one person by default, or let
people take turns (one occurrence or run each, in the order you pick). Starting a
multi-step chore shows whose turn it is; every step of a run goes to the same person.
- Leaving a group hands your chores in it back to anyone, and takes you out of the turns.
- Fixed: a routine shared with a group that starts a multi-step chore was always skipped;
it now starts the run. Sharing a project now also shares the routines in it (they used
to stay with their creator).

## 1.5.0 (2026-10-18)

- Tracking has its own page (under Reflect in the menu, "Track" in the phone tab bar, or
Expand Down
160 changes: 160 additions & 0 deletions crates/domain/src/assign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//! Who does a shared chore (D-116): its default assignee, or members taking turns.
//! Mirrored in `web/src/lib/assign.ts`.

use chrono::{Duration, NaiveDate};

use crate::recurrence::{Schedule, plan_occurrences};

/// The person for the `turn`th occurrence or run of a chore (counting from 0).
///
/// With a rotation, the people in it who are still in the group take turns in order
/// (someone who left is skipped, and the others close up). Without one, or when nobody in
/// it is left, it's the default assignee while they're still in the group; else nobody.
pub fn assignee_for(
default: Option<&str>,
rotation: &[String],
members: &[String],
turn: u64,
) -> Option<String> {
let turns: Vec<&String> = rotation.iter().filter(|u| members.contains(u)).collect();
if !turns.is_empty() {
return Some(turns[(turn % turns.len() as u64) as usize].clone());
}
default
.filter(|u| members.iter().any(|m| m == u))
.map(str::to_string)
}

/// Which turn an occurrence of a routine is (from 0): how many occurrences come before it
/// since the routine's first day. Counted a year at a time, so it keeps counting past the
/// 1000 dates one recurrence query returns.
pub fn turn_of(
schedule: &Schedule,
dtstart: NaiveDate,
until: Option<NaiveDate>,
key: &str,
day: NaiveDate,
week_start: u32,
) -> Result<u64, String> {
let mut n = 0;
let mut from = dtstart;
while from <= day {
let to = (from + Duration::days(364)).min(day);
for o in plan_occurrences(schedule, dtstart, until, from, to, week_start)? {
// A flexible window overlapping two years counts once, in the year it starts.
if o.date < from || o.date > to {
continue;
}
if o.key == key {
return Ok(n);
}
n += 1;
}
from = to + Duration::days(1);
}
Ok(n)
}

/// A rotation as given, without repeats or people outside the group (order kept).
pub fn clean_rotation(rotation: &[String], members: &[String]) -> Vec<String> {
let mut out: Vec<String> = vec![];
for u in rotation {
if members.contains(u) && !out.contains(u) {
out.push(u.clone());
}
}
out
}

#[cfg(test)]
mod tests {
use super::*;
use crate::recurrence::Window;

fn v(xs: &[&str]) -> Vec<String> {
xs.iter().map(|x| x.to_string()).collect()
}

#[test]
fn default_assignee_while_in_the_group() {
let members = v(&["anna", "ben"]);
assert_eq!(
assignee_for(Some("ben"), &[], &members, 0),
Some("ben".into())
);
assert_eq!(
assignee_for(Some("ben"), &[], &members, 7),
Some("ben".into())
);
assert_eq!(assignee_for(Some("cid"), &[], &members, 0), None);
assert_eq!(assignee_for(None, &[], &members, 0), None);
}

#[test]
fn rotation_takes_turns_in_order() {
let members = v(&["anna", "ben", "cid"]);
let rot = v(&["ben", "anna", "cid"]);
let got: Vec<_> = (0..5)
.map(|n| assignee_for(Some("anna"), &rot, &members, n).unwrap())
.collect();
assert_eq!(got, ["ben", "anna", "cid", "ben", "anna"]);
}

#[test]
fn people_who_left_are_skipped() {
let rot = v(&["anna", "ben", "cid"]);
let members = v(&["anna", "cid"]);
let got: Vec<_> = (0..4)
.map(|n| assignee_for(None, &rot, &members, n).unwrap())
.collect();
assert_eq!(got, ["anna", "cid", "anna", "cid"]);
// Nobody left in the rotation: the default, if they're still in.
assert_eq!(
assignee_for(Some("anna"), &v(&["ben"]), &members, 3),
Some("anna".into())
);
assert_eq!(assignee_for(Some("ben"), &v(&["ben"]), &members, 3), None);
}

#[test]
fn turns_keep_counting_for_years() {
let d = |s: &str| NaiveDate::parse_from_str(s, "%Y-%m-%d").unwrap();
let daily = Schedule::Rule {
rule: "FREQ=DAILY".into(),
};
let start = d("2024-01-01");
let day = d("2027-06-30");
let key = plan_occurrences(&daily, start, None, day, day, 1).unwrap()[0]
.key
.clone();
assert_eq!(
turn_of(&daily, start, None, &key, day, 1).unwrap(),
(day - start).num_days() as u64
);
// Twice a week: windows across a year boundary count once.
let flex = Schedule::Flexible {
times: 2,
window: Window::Week,
};
let day = d("2026-01-05");
let occ = plan_occurrences(&flex, start, None, day, day, 1).unwrap();
let weeks = (day - d("2024-01-01")).num_days() as u64 / 7;
assert_eq!(
turn_of(&flex, start, None, &occ[0].key, day, 1).unwrap(),
weeks * 2
);
assert_eq!(
turn_of(&flex, start, None, &occ[1].key, day, 1).unwrap(),
weeks * 2 + 1
);
}

#[test]
fn cleaning_keeps_order_and_drops_strangers_and_repeats() {
let members = v(&["anna", "ben", "cid"]);
assert_eq!(
clean_rotation(&v(&["cid", "zed", "anna", "cid"]), &members),
["cid", "anna"]
);
}
}
1 change: 1 addition & 0 deletions crates/domain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Pure domain logic for Streamline: no IO, no database, no HTTP.
//! Everything here is deterministic and unit-tested.

pub mod assign;
pub mod calendar;
pub mod checklist;
pub mod conflicts;
Expand Down
1 change: 1 addition & 0 deletions crates/server/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ async fn routine_occurrence(
WHERE t.series_id IN (SELECT value FROM json_each(?1)) AND t.deleted_at IS NULL AND t.status = 'open'
AND (t.occurrence_date = ?2 OR t.window_end IS NOT NULL AND t.occurrence_date <= ?2 AND t.window_end >= ?2)
AND t.id NOT IN (SELECT value FROM json_each(?5))
AND (t.assignee_user_id IS NULL OR t.assignee_user_id = ?3)
AND NOT EXISTS (SELECT 1 FROM day_entries e WHERE e.task_id = t.id AND e.user_id = ?3
AND e.deleted_at IS NULL AND e.date >= ?4)
ORDER BY t.occurrence_key LIMIT 1",
Expand Down
2 changes: 2 additions & 0 deletions crates/server/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub async fn gather(state: &AppState, user: &User, day: NaiveDate) -> anyhow::Re
WHERE {visible} AND t.deleted_at IS NULL AND t.status = 'open' AND t.due_date IS NOT NULL AND t.due_date <= ?2
-- an ongoing task's end date is mentioned on its last day only (D-102)
AND (t.ongoing = 0 OR t.due_date = ?2)
-- someone else's chore isn't yours to do (D-116)
AND (t.assignee_user_id IS NULL OR t.assignee_user_id = ?1)
AND NOT EXISTS (SELECT 1 FROM day_entries e WHERE e.task_id = t.id AND e.date = ?2 AND e.deleted_at IS NULL)
ORDER BY t.due_date LIMIT 20"
))
Expand Down
1 change: 1 addition & 0 deletions crates/server/src/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub async fn revoke(state: &AppState, link_id: &str) -> anyhow::Result<()> {
.bind(&link.remote_user_id)
.execute(&mut *tx)
.await?;
changes.extend(crate::ownership::unassign(&mut tx, &g, &link.remote_user_id).await?);
bump_group(&mut tx, &g).await?;
if let Some(gr) = crate::routes::groups::load(&mut tx, &g).await? {
changes.push(Change::group(&gr, &[]));
Expand Down
43 changes: 34 additions & 9 deletions crates/server/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,16 @@ pub struct WorkflowTemplate {
#[ts(as = "Vec<WorkflowVariant>")]
#[schema(value_type = Vec<WorkflowVariant>)]
pub variants: sqlx::types::Json<Vec<WorkflowVariant>>,
/// Who each run goes to by default in a shared chore (D-116); every step of a run goes
/// to the same person.
pub assignee_user_id: Option<String>,
/// Members taking turns, one run each (empty = no rotation; D-116).
#[ts(type = "Array<string>")]
#[schema(value_type = Vec<String>)]
pub rotation_user_ids: sqlx::types::Json<Vec<String>>,
/// Runs started so far: the next one goes to the member at this turn.
#[ts(type = "number")]
pub rotation_turn: i64,
pub created_at: String,
pub updated_at: String,
pub deleted_at: Option<String>,
Expand Down Expand Up @@ -524,13 +534,16 @@ pub async fn upsert_workflow(
w: &WorkflowTemplate,
) -> sqlx::Result<()> {
sqlx::query(
"INSERT INTO workflow_templates (id, owner_user_id, owner_group_id, name, description, project_id, steps, variants, created_at, updated_at, deleted_at, rev)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
ON CONFLICT(id) DO UPDATE SET name=excluded.name, description=excluded.description, project_id=excluded.project_id,
steps=excluded.steps, variants=excluded.variants, updated_at=excluded.updated_at, deleted_at=excluded.deleted_at, rev=excluded.rev",
"INSERT INTO workflow_templates (id, owner_user_id, owner_group_id, name, description, project_id, steps, variants,
assignee_user_id, rotation_user_ids, rotation_turn, created_at, updated_at, deleted_at, rev)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
ON CONFLICT(id) DO UPDATE SET owner_user_id=excluded.owner_user_id, owner_group_id=excluded.owner_group_id, name=excluded.name, description=excluded.description, project_id=excluded.project_id,
steps=excluded.steps, variants=excluded.variants, assignee_user_id=excluded.assignee_user_id,
rotation_user_ids=excluded.rotation_user_ids, rotation_turn=excluded.rotation_turn,
updated_at=excluded.updated_at, deleted_at=excluded.deleted_at, rev=excluded.rev",
)
.bind(&w.id).bind(&w.owner_user_id).bind(&w.owner_group_id).bind(&w.name).bind(&w.description).bind(&w.project_id)
.bind(&w.steps).bind(&w.variants).bind(&w.created_at).bind(&w.updated_at).bind(&w.deleted_at).bind(w.rev)
.bind(&w.steps).bind(&w.variants).bind(&w.assignee_user_id).bind(&w.rotation_user_ids).bind(w.rotation_turn).bind(&w.created_at).bind(&w.updated_at).bind(&w.deleted_at).bind(w.rev)
.execute(conn)
.await
.map(|_| ())
Expand Down Expand Up @@ -612,6 +625,15 @@ pub struct Series {
#[ts(as = "Vec<ChecklistItem>")]
#[schema(value_type = Vec<ChecklistItem>)]
pub checklist: sqlx::types::Json<Vec<ChecklistItem>>,
/// Who each occurrence of a shared routine goes to by default (D-116). (Defaults keep
/// feeds from servers before 1.6 readable, Phase 8.)
#[serde(default)]
pub assignee_user_id: Option<String>,
/// Members taking turns, one occurrence each (empty = no rotation; D-116).
#[serde(default)]
#[ts(type = "Array<string>")]
#[schema(value_type = Vec<String>)]
pub rotation_user_ids: sqlx::types::Json<Vec<String>>,
#[serde(skip)]
#[ts(skip)]
pub materialized_through: Option<String>,
Expand Down Expand Up @@ -776,22 +798,25 @@ pub async fn upsert_series(conn: &mut SqliteConnection, s: &Series) -> sqlx::Res
sqlx::query(
"INSERT INTO series (id, owner_user_id, owner_group_id, project_id, title, notes, mode, rrule, dtstart, until,
start_time, duration_min, times_per_window, window, task_type_id, estimate_min, difficulty, importance, urgency,
materialized_through, split_from, place_id, workflow_template_id, workflow_variant_ids, checklist, created_at, updated_at, deleted_at, rev)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
ON CONFLICT(id) DO UPDATE SET project_id=excluded.project_id, title=excluded.title, notes=excluded.notes,
materialized_through, split_from, place_id, workflow_template_id, workflow_variant_ids, checklist,
assignee_user_id, rotation_user_ids, created_at, updated_at, deleted_at, rev)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
ON CONFLICT(id) DO UPDATE SET owner_user_id=excluded.owner_user_id, owner_group_id=excluded.owner_group_id, project_id=excluded.project_id, title=excluded.title, notes=excluded.notes,
mode=excluded.mode, rrule=excluded.rrule, dtstart=excluded.dtstart, until=excluded.until,
start_time=excluded.start_time, duration_min=excluded.duration_min, times_per_window=excluded.times_per_window,
window=excluded.window, task_type_id=excluded.task_type_id, estimate_min=excluded.estimate_min,
difficulty=excluded.difficulty, importance=excluded.importance, urgency=excluded.urgency,
place_id=excluded.place_id, workflow_template_id=excluded.workflow_template_id,
workflow_variant_ids=excluded.workflow_variant_ids, checklist=excluded.checklist,
assignee_user_id=excluded.assignee_user_id, rotation_user_ids=excluded.rotation_user_ids,
materialized_through=excluded.materialized_through, updated_at=excluded.updated_at,
deleted_at=excluded.deleted_at, rev=excluded.rev",
)
.bind(&s.id).bind(&s.owner_user_id).bind(&s.owner_group_id).bind(&s.project_id).bind(&s.title).bind(&s.notes)
.bind(&s.mode).bind(&s.rrule).bind(&s.dtstart).bind(&s.until).bind(&s.start_time).bind(s.duration_min)
.bind(s.times_per_window).bind(&s.window).bind(&s.task_type_id).bind(s.estimate_min).bind(s.difficulty)
.bind(s.importance).bind(s.urgency).bind(&s.materialized_through).bind(&s.split_from).bind(&s.place_id).bind(&s.workflow_template_id).bind(&s.workflow_variant_ids).bind(&s.checklist).bind(&s.created_at).bind(&s.updated_at)
.bind(s.importance).bind(s.urgency).bind(&s.materialized_through).bind(&s.split_from).bind(&s.place_id).bind(&s.workflow_template_id).bind(&s.workflow_variant_ids).bind(&s.checklist)
.bind(&s.assignee_user_id).bind(&s.rotation_user_ids).bind(&s.created_at).bind(&s.updated_at)
.bind(&s.deleted_at).bind(s.rev)
.execute(conn)
.await
Expand Down
Loading
Loading