repl: add openfile command

This commit is contained in:
Franz Heinzmann (Frando)
2020-06-13 22:49:18 +02:00
parent 401a0fd37f
commit 1350495574
4 changed files with 24 additions and 2 deletions

View File

@@ -370,6 +370,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
===========================Message commands==\n\
listmsgs <query>\n\
msginfo <msg-id>\n\
openfile <msg-id>\n\
listfresh\n\
forward <msg-id> <chat-id>\n\
markseen <msg-id>\n\
@@ -890,6 +891,15 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let res = message::get_msg_info(&context, id).await;
println!("{}", res);
}
"openfile" => {
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
let id = MsgId::new(arg1.parse()?);
let msg = Message::load_from_db(&context, id).await?;
let filepath = msg.get_file(&context);
ensure!(filepath.is_some(), "Message has no file.");
let filepath = filepath.unwrap();
open::that(filepath)?;
}
"listfresh" => {
let msglist = context.get_fresh_msgs().await;

View File

@@ -186,9 +186,10 @@ const CHAT_COMMANDS: [&str; 26] = [
"unpin",
"delchat",
];
const MESSAGE_COMMANDS: [&str; 8] = [
const MESSAGE_COMMANDS: [&str; 9] = [
"listmsgs",
"msginfo",
"openfile",
"listfresh",
"forward",
"markseen",