mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
tau: add nickname for tasks and attached to comments
This commit is contained in:
@@ -84,10 +84,10 @@ pub async fn get_state(url: &str, id: u64) -> Result<Value> {
|
||||
}
|
||||
|
||||
// Set comment for a task and returns `true` upon success.
|
||||
// --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_author, comment_content], "id": 1}
|
||||
// --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_content], "id": 1}
|
||||
// <-- {"jsonrpc": "2.0", "result": true, "id": 1}
|
||||
pub async fn set_comment(url: &str, id: u64, author: &str, content: &str) -> Result<Value> {
|
||||
let req = jsonrpc::request(json!("set_comment"), json!([id, author, content]));
|
||||
pub async fn set_comment(url: &str, id: u64, content: &str) -> Result<Value> {
|
||||
let req = jsonrpc::request(json!("set_comment"), json!([id, content]));
|
||||
request(req, url.to_string()).await
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ async fn start(mut options: CliTau) -> Result<()> {
|
||||
let rank = rank.unwrap_or(0.0);
|
||||
|
||||
add(rpc_addr,
|
||||
json!([{"title": title, "desc": desc, "assign": assign, "project": project, "due": due, "rank": rank}]),
|
||||
).await?;
|
||||
json!([{"title": title, "desc": desc, "assign": assign, "project": project, "due": due, "rank": rank}]),
|
||||
).await?;
|
||||
}
|
||||
|
||||
Some(CliTauSubCommands::Update { id, key, value }) => {
|
||||
@@ -111,18 +111,16 @@ async fn start(mut options: CliTau) -> Result<()> {
|
||||
}
|
||||
},
|
||||
|
||||
Some(CliTauSubCommands::Comment { id, author, content }) => match (author, content) {
|
||||
(Some(author), Some(content)) => {
|
||||
set_comment(rpc_addr, id, author.trim(), content.trim()).await?;
|
||||
Some(CliTauSubCommands::Comment { id, content }) => match content {
|
||||
Some(content) => {
|
||||
set_comment(rpc_addr, id, content.trim()).await?;
|
||||
}
|
||||
(None, None) => {
|
||||
None => {
|
||||
let rep = get_by_id(rpc_addr, id).await?;
|
||||
let comments = get_comments(rep)?;
|
||||
|
||||
println!("Comments on Task with id {}:\n{}", id, comments);
|
||||
}
|
||||
(None, Some(_)) => error!("Please provide the author name"),
|
||||
(Some(_), None) => error!("Please provide some content"),
|
||||
},
|
||||
|
||||
Some(CliTauSubCommands::List {}) | None => {
|
||||
|
||||
@@ -58,8 +58,6 @@ pub enum CliTauSubCommands {
|
||||
Comment {
|
||||
/// Task ID
|
||||
id: u64,
|
||||
/// Comment author
|
||||
author: Option<String>,
|
||||
/// Comment content
|
||||
content: Option<String>,
|
||||
},
|
||||
@@ -73,6 +71,7 @@ pub struct TaskInfo {
|
||||
pub id: u32,
|
||||
pub title: String,
|
||||
pub desc: String,
|
||||
pub owner: String,
|
||||
pub assign: Vec<String>,
|
||||
pub project: Vec<String>,
|
||||
pub due: Option<i64>,
|
||||
@@ -190,6 +189,7 @@ pub fn desc_in_editor() -> Result<Option<String>> {
|
||||
pub fn show_task(task: Value, taskinfo: TaskInfo, current_state: String) -> Result<()> {
|
||||
let mut table = table!([Bd => "ref_id", &taskinfo.ref_id],
|
||||
["id", &taskinfo.id.to_string()],
|
||||
[Bd =>"owner", &taskinfo.owner],
|
||||
[Bd =>"title", &taskinfo.title],
|
||||
["desc", &taskinfo.desc],
|
||||
[Bd =>"assign", get_from_task(task.clone(), "assign")?],
|
||||
|
||||
@@ -24,10 +24,11 @@ use crate::{
|
||||
pub struct JsonRpcInterface {
|
||||
dataset_path: PathBuf,
|
||||
notify_queue_sender: async_channel::Sender<Option<TaskInfo>>,
|
||||
nickname: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct BaseTaskInfo {
|
||||
struct BaseTaskInfo {
|
||||
title: String,
|
||||
desc: String,
|
||||
assign: Vec<String>,
|
||||
@@ -70,8 +71,9 @@ impl JsonRpcInterface {
|
||||
pub fn new(
|
||||
notify_queue_sender: async_channel::Sender<Option<TaskInfo>>,
|
||||
dataset_path: PathBuf,
|
||||
nickname: String,
|
||||
) -> Self {
|
||||
Self { notify_queue_sender, dataset_path }
|
||||
Self { notify_queue_sender, dataset_path, nickname }
|
||||
}
|
||||
|
||||
// RPCAPI:
|
||||
@@ -94,8 +96,14 @@ impl JsonRpcInterface {
|
||||
let args = params.as_array().unwrap();
|
||||
|
||||
let task: BaseTaskInfo = serde_json::from_value(args[0].clone())?;
|
||||
let mut new_task: TaskInfo =
|
||||
TaskInfo::new(&task.title, &task.desc, task.due, task.rank, &self.dataset_path)?;
|
||||
let mut new_task: TaskInfo = TaskInfo::new(
|
||||
&task.title,
|
||||
&task.desc,
|
||||
&self.nickname,
|
||||
task.due,
|
||||
task.rank,
|
||||
&self.dataset_path,
|
||||
)?;
|
||||
new_task.set_project(&task.project);
|
||||
new_task.set_assign(&task.assign);
|
||||
|
||||
@@ -174,21 +182,20 @@ impl JsonRpcInterface {
|
||||
|
||||
// RPCAPI:
|
||||
// Set comment for a task and returns `true` upon success.
|
||||
// --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_author, comment_content], "id": 1}
|
||||
// --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_content], "id": 1}
|
||||
// <-- {"jsonrpc": "2.0", "result": true, "id": 1}
|
||||
async fn set_comment(&self, params: Value) -> TaudResult<Value> {
|
||||
debug!(target: "tau", "JsonRpc::set_comment() params {}", params);
|
||||
let args = params.as_array().unwrap();
|
||||
|
||||
if args.len() != 3 {
|
||||
if args.len() != 2 {
|
||||
return Err(TaudError::InvalidData("len of params should be 3".into()))
|
||||
}
|
||||
|
||||
let comment_author: String = serde_json::from_value(args[1].clone())?;
|
||||
let comment_content: String = serde_json::from_value(args[2].clone())?;
|
||||
let comment_content: String = serde_json::from_value(args[1].clone())?;
|
||||
|
||||
let mut task: TaskInfo = self.load_task_by_id(&args[0])?;
|
||||
task.set_comment(Comment::new(&comment_content, &comment_author));
|
||||
task.set_comment(Comment::new(&comment_content, &self.nickname));
|
||||
|
||||
self.notify_queue_sender.send(Some(task)).await.map_err(Error::from)?;
|
||||
Ok(json!(true))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
use std::fs::create_dir_all;
|
||||
use std::{env, fs::create_dir_all};
|
||||
|
||||
use async_executor::Executor;
|
||||
use crypto_box::{aead::Aead, Box, SecretKey, KEY_SIZE};
|
||||
@@ -86,6 +86,14 @@ async_daemonize!(realmain);
|
||||
async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
let datastore_path = expand_path(&settings.datastore)?;
|
||||
|
||||
let nickname =
|
||||
if settings.nickname.is_some() { settings.nickname } else { env::var("USER").ok() };
|
||||
|
||||
if nickname.is_none() {
|
||||
error!("Provide a nickname in config file");
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
// mkdir datastore_path if not exists
|
||||
create_dir_all(datastore_path.join("month"))?;
|
||||
create_dir_all(datastore_path.join("task"))?;
|
||||
@@ -99,14 +107,17 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
save::<String>(&datastore_path.join("secret_key"), &sk_string)?;
|
||||
secret
|
||||
} else {
|
||||
let loaded_key = match load::<String>(&datastore_path.join("secret_key")) {
|
||||
Ok(key) => key,
|
||||
Err(_) => {
|
||||
error!("Could not load secret key from file, please run \"taud --help\" for more information");
|
||||
return Ok(())
|
||||
}
|
||||
};
|
||||
let sk_bytes = hex::decode(loaded_key)?;
|
||||
let loaded_key = load::<String>(&datastore_path.join("secret_key"));
|
||||
|
||||
if loaded_key.is_err() {
|
||||
error!(
|
||||
"Could not load secret key from file, \
|
||||
please run \"taud --help\" for more information"
|
||||
);
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let sk_bytes = hex::decode(loaded_key.unwrap())?;
|
||||
let sk_bytes: [u8; KEY_SIZE] = sk_bytes.as_slice().try_into()?;
|
||||
SecretKey::try_from(sk_bytes)?
|
||||
};
|
||||
@@ -124,7 +135,8 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
|
||||
let (rpc_snd, rpc_rcv) = async_channel::unbounded::<Option<TaskInfo>>();
|
||||
|
||||
let rpc_interface = Arc::new(JsonRpcInterface::new(rpc_snd, datastore_path.clone()));
|
||||
let rpc_interface =
|
||||
Arc::new(JsonRpcInterface::new(rpc_snd, datastore_path.clone(), nickname.unwrap()));
|
||||
|
||||
let executor_cloned = executor.clone();
|
||||
let rpc_listener_task =
|
||||
|
||||
@@ -154,7 +154,8 @@ mod tests {
|
||||
// load and save TaskInfo
|
||||
///////////////////////
|
||||
|
||||
let mut task = TaskInfo::new("test_title", "test_desc", None, 0.0, &dataset_path)?;
|
||||
let mut task =
|
||||
TaskInfo::new("test_title", "test_desc", "NICKNAME", None, 0.0, &dataset_path)?;
|
||||
|
||||
task.save(&dataset_path)?;
|
||||
|
||||
@@ -194,7 +195,8 @@ mod tests {
|
||||
// activate task
|
||||
///////////////////////
|
||||
|
||||
let task = TaskInfo::new("test_title_3", "test_desc", None, 0.0, &dataset_path)?;
|
||||
let task =
|
||||
TaskInfo::new("test_title_3", "test_desc", "NICKNAME", None, 0.0, &dataset_path)?;
|
||||
|
||||
task.save(&dataset_path)?;
|
||||
|
||||
|
||||
@@ -31,4 +31,7 @@ pub struct Args {
|
||||
/// Generate a new secret key
|
||||
#[structopt(long)]
|
||||
pub key_gen: bool,
|
||||
/// Current display name
|
||||
#[structopt(long)]
|
||||
pub nickname: Option<String>,
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ pub struct TaskInfo {
|
||||
id: u32,
|
||||
title: String,
|
||||
desc: String,
|
||||
owner: String,
|
||||
assign: TaskAssigns,
|
||||
project: TaskProjects,
|
||||
due: Option<Timestamp>,
|
||||
@@ -66,6 +67,7 @@ impl TaskInfo {
|
||||
pub fn new(
|
||||
title: &str,
|
||||
desc: &str,
|
||||
owner: &str,
|
||||
due: Option<Timestamp>,
|
||||
rank: f32,
|
||||
dataset_path: &Path,
|
||||
@@ -91,6 +93,7 @@ impl TaskInfo {
|
||||
id,
|
||||
title: title.into(),
|
||||
desc: desc.into(),
|
||||
owner: owner.into(),
|
||||
assign: TaskAssigns(vec![]),
|
||||
project: TaskProjects(vec![]),
|
||||
due,
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
## Sets Datastore Path
|
||||
#datastore="~/.config/tau"
|
||||
|
||||
## Current display name
|
||||
#nickname="NICKNAME"
|
||||
|
||||
## Raft net settings
|
||||
[net]
|
||||
## P2P accept address
|
||||
|
||||
Reference in New Issue
Block a user