1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
use std::fs;
use clap::Args;
use nostr::{Keys};
use crate::{cli_helpers::select_relays, config::load_config, utils::{create_client, load_event}};
#[derive(Args)]
pub struct RebroadcastSubCommand {
}
pub fn rebroadcast(
_sub_command_args: &RebroadcastSubCommand,
) {
// get relay input
let relays = select_relays(
&mut load_config(),
&vec![],
)
.expect("relays to be selected");
let client = create_client(&Keys::generate(), relays)
.expect("create_client to return client for create_and_broadcast_patches");
let repo_dir_path = std::env::current_dir().unwrap();
// cycle through directories and send events
for dir_name in [
"groups",
"branches",
"patches",
"merges",
"prs",
"issues",
"comments",
] {
if !repo_dir_path.join(".ngit").exists() {
println!("this isn't a repository here to rebroadcast")
}
let dir_path = repo_dir_path.join(".ngit").join(&dir_name);
if dir_path.exists() {
let dir = fs::read_dir(&dir_path)
.expect("read_dir to produce ReadDir from a path that exists");
// get json in directories
for entry in dir {
let path = entry
.expect("DirEntry to return from ReadDir")
.path();
// send event
match client.send_event(
load_event(&path)
.expect("every file in .ngit paths is a valid json event")
) {
Ok(_) => {
println!("sent: {}", &path.to_string_lossy());
},
// TODO: this isn't working - if a relay is specified with a type it will wait 30ish secs and then return successful
Err(e) => { println!("error broadcasting event: {}",e); },
}
// TODO: better error handling here / reporting. potentially warn if taking a while and report on troublesome relays
}
}
}
}
|