mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
Allow drafts without text if there is a quote
This commit is contained in:
13
src/chat.rs
13
src/chat.rs
@@ -315,14 +315,11 @@ impl ChatId {
|
|||||||
async fn do_set_draft(self, context: &Context, msg: &mut Message) -> Result<(), Error> {
|
async fn do_set_draft(self, context: &Context, msg: &mut Message) -> Result<(), Error> {
|
||||||
match msg.viewtype {
|
match msg.viewtype {
|
||||||
Viewtype::Unknown => bail!("Can not set draft of unknown type."),
|
Viewtype::Unknown => bail!("Can not set draft of unknown type."),
|
||||||
Viewtype::Text => match msg.text.as_ref() {
|
Viewtype::Text => {
|
||||||
Some(text) => {
|
if msg.text.is_none_or_empty() && msg.in_reply_to.is_none_or_empty() {
|
||||||
if text.is_empty() {
|
bail!("No text and no quote in draft");
|
||||||
bail!("No text in draft");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => bail!("No text in draft"),
|
}
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
let blob = msg
|
let blob = msg
|
||||||
.param
|
.param
|
||||||
@@ -346,7 +343,7 @@ impl ChatId {
|
|||||||
msg.text.as_deref().unwrap_or(""),
|
msg.text.as_deref().unwrap_or(""),
|
||||||
msg.param.to_string(),
|
msg.param.to_string(),
|
||||||
1,
|
1,
|
||||||
msg.in_reply_to,
|
msg.in_reply_to.as_deref().unwrap_or_default(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -709,6 +709,21 @@ pub(crate) fn improve_single_line_input(input: impl AsRef<str>) -> String {
|
|||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) trait IsNoneOrEmpty<T> {
|
||||||
|
fn is_none_or_empty(&self) -> bool;
|
||||||
|
}
|
||||||
|
impl<T> IsNoneOrEmpty<T> for Option<T>
|
||||||
|
where
|
||||||
|
T: AsRef<str>,
|
||||||
|
{
|
||||||
|
fn is_none_or_empty(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Some(s) if !s.as_ref().is_empty() => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
|
|||||||
Reference in New Issue
Block a user