mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
add mute options to repl tool
This commit is contained in:
@@ -4,7 +4,9 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use anyhow::{bail, ensure, Error};
|
use anyhow::{bail, ensure, Error};
|
||||||
use async_std::path::Path;
|
use async_std::path::Path;
|
||||||
use deltachat::chat::{self, Chat, ChatId, ChatItem, ChatVisibility, ProtectionStatus};
|
use deltachat::chat::{
|
||||||
|
self, Chat, ChatId, ChatItem, ChatVisibility, MuteDuration, ProtectionStatus,
|
||||||
|
};
|
||||||
use deltachat::chatlist::*;
|
use deltachat::chatlist::*;
|
||||||
use deltachat::constants::*;
|
use deltachat::constants::*;
|
||||||
use deltachat::contact::*;
|
use deltachat::contact::*;
|
||||||
@@ -22,6 +24,7 @@ use deltachat::sql;
|
|||||||
use deltachat::EventType;
|
use deltachat::EventType;
|
||||||
use deltachat::{config, provider};
|
use deltachat::{config, provider};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
/// Reset database tables.
|
/// Reset database tables.
|
||||||
/// Argument is a bitmask, executing single or multiple actions in one call.
|
/// Argument is a bitmask, executing single or multiple actions in one call.
|
||||||
@@ -379,6 +382,8 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
unarchive <chat-id>\n\
|
unarchive <chat-id>\n\
|
||||||
pin <chat-id>\n\
|
pin <chat-id>\n\
|
||||||
unpin <chat-id>\n\
|
unpin <chat-id>\n\
|
||||||
|
mute <chat-id> [<seconds>]\n\
|
||||||
|
unmute <chat-id>\n\
|
||||||
protect <chat-id>\n\
|
protect <chat-id>\n\
|
||||||
unprotect <chat-id>\n\
|
unprotect <chat-id>\n\
|
||||||
delchat <chat-id>\n\
|
delchat <chat-id>\n\
|
||||||
@@ -534,11 +539,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
for i in (0..cnt).rev() {
|
for i in (0..cnt).rev() {
|
||||||
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)).await?;
|
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)).await?;
|
||||||
println!(
|
println!(
|
||||||
"{}#{}: {} [{} fresh] {}{}",
|
"{}#{}: {} [{} fresh] {}{}{}",
|
||||||
chat_prefix(&chat),
|
chat_prefix(&chat),
|
||||||
chat.get_id(),
|
chat.get_id(),
|
||||||
chat.get_name(),
|
chat.get_name(),
|
||||||
chat.get_id().get_fresh_msg_cnt(&context).await,
|
chat.get_id().get_fresh_msg_cnt(&context).await,
|
||||||
|
if chat.is_muted() { "🔇" } else { "" },
|
||||||
match chat.visibility {
|
match chat.visibility {
|
||||||
ChatVisibility::Normal => "",
|
ChatVisibility::Normal => "",
|
||||||
ChatVisibility::Archived => "📦",
|
ChatVisibility::Archived => "📦",
|
||||||
@@ -621,11 +627,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
format!("{} member(s)", members.len())
|
format!("{} member(s)", members.len())
|
||||||
};
|
};
|
||||||
println!(
|
println!(
|
||||||
"{}#{}: {} [{}]{}{} {}",
|
"{}#{}: {} [{}]{}{}{} {}",
|
||||||
chat_prefix(sel_chat),
|
chat_prefix(sel_chat),
|
||||||
sel_chat.get_id(),
|
sel_chat.get_id(),
|
||||||
sel_chat.get_name(),
|
sel_chat.get_name(),
|
||||||
subtitle,
|
subtitle,
|
||||||
|
if sel_chat.is_muted() { "🔇" } else { "" },
|
||||||
if sel_chat.is_sending_locations() {
|
if sel_chat.is_sending_locations() {
|
||||||
"📍"
|
"📍"
|
||||||
} else {
|
} else {
|
||||||
@@ -965,6 +972,24 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
"mute" | "unmute" => {
|
||||||
|
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
||||||
|
let chat_id = ChatId::new(arg1.parse()?);
|
||||||
|
let duration = match arg0 {
|
||||||
|
"mute" => {
|
||||||
|
if arg2.is_empty() {
|
||||||
|
MuteDuration::Forever
|
||||||
|
} else {
|
||||||
|
SystemTime::now()
|
||||||
|
.checked_add(Duration::from_secs(arg2.parse()?))
|
||||||
|
.map_or(MuteDuration::Forever, MuteDuration::Until)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"unmute" => MuteDuration::NotMuted,
|
||||||
|
_ => unreachable!("arg0={:?}", arg0),
|
||||||
|
};
|
||||||
|
chat::set_muted(&context, chat_id, duration).await?;
|
||||||
|
}
|
||||||
"protect" | "unprotect" => {
|
"protect" | "unprotect" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
||||||
let chat_id = ChatId::new(arg1.parse()?);
|
let chat_id = ChatId::new(arg1.parse()?);
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ const DB_COMMANDS: [&str; 9] = [
|
|||||||
"housekeeping",
|
"housekeeping",
|
||||||
];
|
];
|
||||||
|
|
||||||
const CHAT_COMMANDS: [&str; 30] = [
|
const CHAT_COMMANDS: [&str; 34] = [
|
||||||
"listchats",
|
"listchats",
|
||||||
"listarchived",
|
"listarchived",
|
||||||
"chat",
|
"chat",
|
||||||
@@ -198,6 +198,10 @@ const CHAT_COMMANDS: [&str; 30] = [
|
|||||||
"unarchive",
|
"unarchive",
|
||||||
"pin",
|
"pin",
|
||||||
"unpin",
|
"unpin",
|
||||||
|
"mute",
|
||||||
|
"unmute",
|
||||||
|
"protect",
|
||||||
|
"unprotect",
|
||||||
"delchat",
|
"delchat",
|
||||||
];
|
];
|
||||||
const MESSAGE_COMMANDS: [&str; 6] = [
|
const MESSAGE_COMMANDS: [&str; 6] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user