diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 16:37:10 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 16:37:10 +0100 |
| commit | 8638b321fdff94d034ec912ecd0910b6f564ff04 (patch) | |
| tree | 411e0ca989d8c53be5b11b39461297bf6a92d781 /src/sub_commands/list.rs | |
| parent | 95cb9c040dfa8ca18bf907a44a86df35b316b6ca (diff) | |
refactor: use nip34 kinds from rust-nostr
instead of Kind::Custom(u16) as v33 of rust-nostr introduced them
Diffstat (limited to 'src/sub_commands/list.rs')
| -rw-r--r-- | src/sub_commands/list.rs | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index cc7ac6f..73ef107 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs | |||
| @@ -2,7 +2,7 @@ use std::{collections::HashSet, io::Write, ops::Add, path::Path}; | |||
| 2 | 2 | ||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use nostr::nips::nip01::Coordinate; | 4 | use nostr::nips::nip01::Coordinate; |
| 5 | use nostr_sdk::PublicKey; | 5 | use nostr_sdk::{Kind, PublicKey}; |
| 6 | 6 | ||
| 7 | use super::send::event_is_patch_set_root; | 7 | use super::send::event_is_patch_set_root; |
| 8 | #[cfg(test)] | 8 | #[cfg(test)] |
| @@ -16,7 +16,7 @@ use crate::{ | |||
| 16 | repo_ref::{get_repo_coordinates, RepoRef}, | 16 | repo_ref::{get_repo_coordinates, RepoRef}, |
| 17 | sub_commands::send::{ | 17 | sub_commands::send::{ |
| 18 | commit_msg_from_patch_oneliner, event_is_cover_letter, event_is_revision_root, | 18 | commit_msg_from_patch_oneliner, event_is_cover_letter, event_is_revision_root, |
| 19 | event_to_cover_letter, patch_supports_commit_ids, PATCH_KIND, | 19 | event_to_cover_letter, patch_supports_commit_ids, |
| 20 | }, | 20 | }, |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| @@ -84,31 +84,31 @@ pub async fn launch() -> Result<()> { | |||
| 84 | .collect::<Vec<&nostr::Event>>() | 84 | .collect::<Vec<&nostr::Event>>() |
| 85 | .first() | 85 | .first() |
| 86 | { | 86 | { |
| 87 | e.kind().as_u16() | 87 | e.kind() |
| 88 | } else { | 88 | } else { |
| 89 | STATUS_KIND_OPEN | 89 | Kind::GitStatusOpen |
| 90 | }; | 90 | }; |
| 91 | if status.eq(&STATUS_KIND_OPEN) { | 91 | if status.eq(&Kind::GitStatusOpen) { |
| 92 | open_proposals.push(proposal); | 92 | open_proposals.push(proposal); |
| 93 | } else if status.eq(&STATUS_KIND_CLOSED) { | 93 | } else if status.eq(&Kind::GitStatusClosed) { |
| 94 | closed_proposals.push(proposal); | 94 | closed_proposals.push(proposal); |
| 95 | } else if status.eq(&STATUS_KIND_DRAFT) { | 95 | } else if status.eq(&Kind::GitStatusDraft) { |
| 96 | draft_proposals.push(proposal); | 96 | draft_proposals.push(proposal); |
| 97 | } else if status.eq(&STATUS_KIND_APPLIED) { | 97 | } else if status.eq(&Kind::GitStatusApplied) { |
| 98 | applied_proposals.push(proposal); | 98 | applied_proposals.push(proposal); |
| 99 | } | 99 | } |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | let mut selected_status = STATUS_KIND_OPEN; | 102 | let mut selected_status = Kind::GitStatusOpen; |
| 103 | 103 | ||
| 104 | loop { | 104 | loop { |
| 105 | let proposals_for_status = if selected_status == STATUS_KIND_OPEN { | 105 | let proposals_for_status = if selected_status == Kind::GitStatusOpen { |
| 106 | &open_proposals | 106 | &open_proposals |
| 107 | } else if selected_status == STATUS_KIND_DRAFT { | 107 | } else if selected_status == Kind::GitStatusDraft { |
| 108 | &draft_proposals | 108 | &draft_proposals |
| 109 | } else if selected_status == STATUS_KIND_CLOSED { | 109 | } else if selected_status == Kind::GitStatusClosed { |
| 110 | &closed_proposals | 110 | &closed_proposals |
| 111 | } else if selected_status == STATUS_KIND_APPLIED { | 111 | } else if selected_status == Kind::GitStatusApplied { |
| 112 | &applied_proposals | 112 | &applied_proposals |
| 113 | } else { | 113 | } else { |
| 114 | &open_proposals | 114 | &open_proposals |
| @@ -116,15 +116,15 @@ pub async fn launch() -> Result<()> { | |||
| 116 | 116 | ||
| 117 | let prompt = if proposals.len().eq(&open_proposals.len()) { | 117 | let prompt = if proposals.len().eq(&open_proposals.len()) { |
| 118 | "all proposals" | 118 | "all proposals" |
| 119 | } else if selected_status == STATUS_KIND_OPEN { | 119 | } else if selected_status == Kind::GitStatusOpen { |
| 120 | if open_proposals.is_empty() { | 120 | if open_proposals.is_empty() { |
| 121 | "proposals menu" | 121 | "proposals menu" |
| 122 | } else { | 122 | } else { |
| 123 | "open proposals" | 123 | "open proposals" |
| 124 | } | 124 | } |
| 125 | } else if selected_status == STATUS_KIND_DRAFT { | 125 | } else if selected_status == Kind::GitStatusDraft { |
| 126 | "draft proposals" | 126 | "draft proposals" |
| 127 | } else if selected_status == STATUS_KIND_CLOSED { | 127 | } else if selected_status == Kind::GitStatusClosed { |
| 128 | "closed proposals" | 128 | "closed proposals" |
| 129 | } else { | 129 | } else { |
| 130 | "applied proposals" | 130 | "applied proposals" |
| @@ -143,16 +143,16 @@ pub async fn launch() -> Result<()> { | |||
| 143 | }) | 143 | }) |
| 144 | .collect(); | 144 | .collect(); |
| 145 | 145 | ||
| 146 | if !selected_status.eq(&STATUS_KIND_OPEN) && open_proposals.len().gt(&0) { | 146 | if !selected_status.eq(&Kind::GitStatusOpen) && open_proposals.len().gt(&0) { |
| 147 | choices.push(format!("({}) Open proposals...", open_proposals.len())); | 147 | choices.push(format!("({}) Open proposals...", open_proposals.len())); |
| 148 | } | 148 | } |
| 149 | if !selected_status.eq(&STATUS_KIND_DRAFT) && draft_proposals.len().gt(&0) { | 149 | if !selected_status.eq(&Kind::GitStatusDraft) && draft_proposals.len().gt(&0) { |
| 150 | choices.push(format!("({}) Draft proposals...", draft_proposals.len())); | 150 | choices.push(format!("({}) Draft proposals...", draft_proposals.len())); |
| 151 | } | 151 | } |
| 152 | if !selected_status.eq(&STATUS_KIND_CLOSED) && closed_proposals.len().gt(&0) { | 152 | if !selected_status.eq(&Kind::GitStatusClosed) && closed_proposals.len().gt(&0) { |
| 153 | choices.push(format!("({}) Closed proposals...", closed_proposals.len())); | 153 | choices.push(format!("({}) Closed proposals...", closed_proposals.len())); |
| 154 | } | 154 | } |
| 155 | if !selected_status.eq(&STATUS_KIND_APPLIED) && applied_proposals.len().gt(&0) { | 155 | if !selected_status.eq(&Kind::GitStatusApplied) && applied_proposals.len().gt(&0) { |
| 156 | choices.push(format!( | 156 | choices.push(format!( |
| 157 | "({}) Applied proposals...", | 157 | "({}) Applied proposals...", |
| 158 | applied_proposals.len() | 158 | applied_proposals.len() |
| @@ -167,13 +167,13 @@ pub async fn launch() -> Result<()> { | |||
| 167 | 167 | ||
| 168 | if (selected_index + 1).gt(&proposals_for_status.len()) { | 168 | if (selected_index + 1).gt(&proposals_for_status.len()) { |
| 169 | if choices[selected_index].contains("Open") { | 169 | if choices[selected_index].contains("Open") { |
| 170 | selected_status = STATUS_KIND_OPEN; | 170 | selected_status = Kind::GitStatusOpen; |
| 171 | } else if choices[selected_index].contains("Draft") { | 171 | } else if choices[selected_index].contains("Draft") { |
| 172 | selected_status = STATUS_KIND_DRAFT; | 172 | selected_status = Kind::GitStatusDraft; |
| 173 | } else if choices[selected_index].contains("Closed") { | 173 | } else if choices[selected_index].contains("Closed") { |
| 174 | selected_status = STATUS_KIND_CLOSED; | 174 | selected_status = Kind::GitStatusClosed; |
| 175 | } else if choices[selected_index].contains("Applied") { | 175 | } else if choices[selected_index].contains("Applied") { |
| 176 | selected_status = STATUS_KIND_APPLIED; | 176 | selected_status = Kind::GitStatusApplied; |
| 177 | } | 177 | } |
| 178 | continue; | 178 | continue; |
| 179 | } | 179 | } |
| @@ -804,17 +804,12 @@ pub fn get_most_recent_patch_with_ancestors( | |||
| 804 | Ok(res) | 804 | Ok(res) |
| 805 | } | 805 | } |
| 806 | 806 | ||
| 807 | pub static STATUS_KIND_OPEN: u16 = 1630; | ||
| 808 | pub static STATUS_KIND_APPLIED: u16 = 1631; | ||
| 809 | pub static STATUS_KIND_CLOSED: u16 = 1632; | ||
| 810 | pub static STATUS_KIND_DRAFT: u16 = 1633; | ||
| 811 | |||
| 812 | pub fn status_kinds() -> Vec<nostr::Kind> { | 807 | pub fn status_kinds() -> Vec<nostr::Kind> { |
| 813 | vec![ | 808 | vec![ |
| 814 | nostr::Kind::Custom(STATUS_KIND_OPEN), | 809 | nostr::Kind::GitStatusOpen, |
| 815 | nostr::Kind::Custom(STATUS_KIND_APPLIED), | 810 | nostr::Kind::GitStatusApplied, |
| 816 | nostr::Kind::Custom(STATUS_KIND_CLOSED), | 811 | nostr::Kind::GitStatusClosed, |
| 817 | nostr::Kind::Custom(STATUS_KIND_DRAFT), | 812 | nostr::Kind::GitStatusDraft, |
| 818 | ] | 813 | ] |
| 819 | } | 814 | } |
| 820 | 815 | ||
| @@ -826,7 +821,7 @@ pub async fn get_proposals_and_revisions_from_cache( | |||
| 826 | git_repo_path, | 821 | git_repo_path, |
| 827 | vec![ | 822 | vec![ |
| 828 | nostr::Filter::default() | 823 | nostr::Filter::default() |
| 829 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 824 | .kind(nostr::Kind::GitPatch) |
| 830 | .custom_tag( | 825 | .custom_tag( |
| 831 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 826 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 832 | repo_coordinates | 827 | repo_coordinates |
| @@ -855,10 +850,10 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 855 | git_repo_path, | 850 | git_repo_path, |
| 856 | vec![ | 851 | vec![ |
| 857 | nostr::Filter::default() | 852 | nostr::Filter::default() |
| 858 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 853 | .kind(nostr::Kind::GitPatch) |
| 859 | .event(*proposal_id), | 854 | .event(*proposal_id), |
| 860 | nostr::Filter::default() | 855 | nostr::Filter::default() |
| 861 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 856 | .kind(nostr::Kind::GitPatch) |
| 862 | .id(*proposal_id), | 857 | .id(*proposal_id), |
| 863 | ], | 858 | ], |
| 864 | ) | 859 | ) |
| @@ -891,7 +886,7 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 891 | git_repo_path, | 886 | git_repo_path, |
| 892 | vec![ | 887 | vec![ |
| 893 | nostr::Filter::default() | 888 | nostr::Filter::default() |
| 894 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 889 | .kind(nostr::Kind::GitPatch) |
| 895 | .events(revision_roots) | 890 | .events(revision_roots) |
| 896 | .authors(permissioned_users.clone()), | 891 | .authors(permissioned_users.clone()), |
| 897 | ], | 892 | ], |