mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +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> {
|
||||
match msg.viewtype {
|
||||
Viewtype::Unknown => bail!("Can not set draft of unknown type."),
|
||||
Viewtype::Text => match msg.text.as_ref() {
|
||||
Some(text) => {
|
||||
if text.is_empty() {
|
||||
bail!("No text in draft");
|
||||
}
|
||||
Viewtype::Text => {
|
||||
if msg.text.is_none_or_empty() && msg.in_reply_to.is_none_or_empty() {
|
||||
bail!("No text and no quote in draft");
|
||||
}
|
||||
None => bail!("No text in draft"),
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
let blob = msg
|
||||
.param
|
||||
@@ -346,7 +343,7 @@ impl ChatId {
|
||||
msg.text.as_deref().unwrap_or(""),
|
||||
msg.param.to_string(),
|
||||
1,
|
||||
msg.in_reply_to,
|
||||
msg.in_reply_to.as_deref().unwrap_or_default(),
|
||||
],
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -709,6 +709,21 @@ pub(crate) fn improve_single_line_input(input: impl AsRef<str>) -> 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)]
|
||||
mod tests {
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
Reference in New Issue
Block a user