Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: rename cache back to notifs
Fintan Halpenny committed 6 months ago
commit 03f30e1fc1c442f1a82a822c810b7da58e2d8019
parent e6eb85b0b608d9710bb3508560f35b4e70bc1f5c
1 file changed +38 -24
modified crates/radicle-cli/src/commands/inbox.rs
@@ -55,7 +55,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
}

fn list(
-
    cache: &notifications::StoreReader,
+
    notifs: &notifications::StoreReader,
    all: bool,
    repo: Option<RepoId>,
    sort_by: SortBy,
@@ -65,22 +65,36 @@ fn list(
    profile: &Profile,
) -> anyhow::Result<()> {
    let repos: Vec<term::VStack<'_>> = match (all, repo) {
-
        (true, None) => list_all(cache, sort_by, reverse, show_unknown, storage, profile)?,
+
        (true, None) => list_all(notifs, sort_by, reverse, show_unknown, storage, profile)?,
        (false, None) => {
            if let Ok((_, rid)) = radicle::rad::cwd() {
-
                list_repo(cache, rid, sort_by, reverse, show_unknown, storage, profile)?
-
                    .into_iter()
-
                    .collect()
-
            } else {
-
                list_all(cache, sort_by, reverse, show_unknown, storage, profile)?
-
            }
-
        }
-
        (false, Some(rid)) => {
-
            list_repo(cache, rid, sort_by, reverse, show_unknown, storage, profile)?
+
                list_repo(
+
                    notifs,
+
                    rid,
+
                    sort_by,
+
                    reverse,
+
                    show_unknown,
+
                    storage,
+
                    profile,
+
                )?
                .into_iter()
                .collect()
+
            } else {
+
                list_all(notifs, sort_by, reverse, show_unknown, storage, profile)?
+
            }
        }
-
        (true, Some(_)) => list_all(cache, sort_by, reverse, show_unknown, storage, profile)?,
+
        (false, Some(rid)) => list_repo(
+
            notifs,
+
            rid,
+
            sort_by,
+
            reverse,
+
            show_unknown,
+
            storage,
+
            profile,
+
        )?
+
        .into_iter()
+
        .collect(),
+
        (true, Some(_)) => list_all(notifs, sort_by, reverse, show_unknown, storage, profile)?,
    };

    if repos.is_empty() {
@@ -94,7 +108,7 @@ fn list(
}

fn list_all<'a>(
-
    cache: &notifications::StoreReader,
+
    notifs: &notifications::StoreReader,
    sort_by: SortBy,
    reverse: bool,
    show_unknown: bool,
@@ -107,7 +121,7 @@ fn list_all<'a>(
    let mut vstacks = Vec::new();
    for repo in repos {
        let vstack = list_repo(
-
            cache,
+
            notifs,
            repo.rid,
            sort_by.clone(),
            reverse,
@@ -121,7 +135,7 @@ fn list_all<'a>(
}

fn list_repo<'a, R: ReadStorage>(
-
    cache: &notifications::StoreReader,
+
    notifs: &notifications::StoreReader,
    rid: RepoId,
    sort_by: SortBy,
    reverse: bool,
@@ -139,7 +153,7 @@ where
    let issues = term::cob::issues(profile, &repo)?;
    let patches = term::cob::patches(profile, &repo)?;

-
    let mut cache = cache
+
    let mut cache = notifs
        .by_repo(&rid, &sort_by.to_string())?
        .collect::<Vec<_>>();
    if !reverse {
@@ -373,18 +387,18 @@ impl NotificationRow {
}

fn clear(
-
    cache: &mut notifications::StoreWriter,
+
    notifs: &mut notifications::StoreWriter,
    all: bool,
    rid: Option<RepoId>,
    ids: Option<Vec<NotificationId>>,
) -> anyhow::Result<()> {
    let cleared = match (all, rid, ids) {
-
        (true, _, _) => cache.clear_all()?,
-
        (_, _, Some(ids)) => cache.clear(&ids)?,
-
        (_, Some(rid), _) => cache.clear_by_repo(&rid)?,
+
        (true, _, _) => notifs.clear_all()?,
+
        (_, _, Some(ids)) => notifs.clear(&ids)?,
+
        (_, Some(rid), _) => notifs.clear_by_repo(&rid)?,
        (_, None, _) => {
            if let Ok((_, rid)) = radicle::rad::cwd() {
-
                cache.clear_by_repo(&rid)?
+
                notifs.clear_by_repo(&rid)?
            } else {
                return Err(anyhow!("not a radicle repository"));
            }
@@ -399,12 +413,12 @@ fn clear(
}

fn show(
-
    cache: &mut notifications::StoreWriter,
+
    notifs: &mut notifications::StoreWriter,
    id: NotificationId,
    storage: &Storage,
    profile: &Profile,
) -> anyhow::Result<()> {
-
    let n = cache.get(id)?;
+
    let n = notifs.get(id)?;
    let repo = storage.repository(n.repo)?;

    match n.kind {
@@ -449,7 +463,7 @@ fn show(
            term::json::to_pretty(&notification, Path::new("notification.json"))?.print();
        }
    }
-
    cache.set_status(NotificationStatus::ReadAt(LocalTime::now()), &[id])?;
+
    notifs.set_status(NotificationStatus::ReadAt(LocalTime::now()), &[id])?;

    Ok(())
}