Merge branch 'stable'

This commit is contained in:
link2xt
2023-07-27 19:40:01 +00:00
13 changed files with 104 additions and 59 deletions

View File

@@ -19,6 +19,7 @@ use crate::context::Context;
use crate::download::DownloadState;
use crate::events::EventType;
use crate::message::{Message, MessageState, MsgId, Viewtype};
use crate::mimefactory::wrapped_base64_encode;
use crate::mimeparser::SystemMessage;
use crate::param::Param;
use crate::param::Params;
@@ -535,13 +536,16 @@ impl Context {
}
pub(crate) fn build_status_update_part(&self, json: &str) -> PartBuilder {
let encoded_body = wrapped_base64_encode(json.as_bytes());
PartBuilder::new()
.content_type(&"application/json".parse::<mime::Mime>().unwrap())
.header((
"Content-Disposition",
"attachment; filename=\"status-update.json\"",
))
.body(json)
.header(("Content-Transfer-Encoding", "base64"))
.body(encoded_body)
}
/// Receives status updates from receive_imf to the database
@@ -561,7 +565,6 @@ impl Context {
json: &str,
) -> Result<()> {
let msg = Message::load_from_db(self, msg_id).await?;
let chat_id = msg.chat_id;
let (timestamp, mut instance, can_info_msg) = if msg.viewtype == Viewtype::Webxdc {
(msg.timestamp_sort, msg, false)
} else if let Some(parent) = msg.parent(self).await? {
@@ -575,17 +578,16 @@ impl Context {
} else {
bail!("receive_status_update: status message has no parent.")
};
let chat_id = instance.chat_id;
if from_id != ContactId::SELF
&& !chat::is_contact_in_chat(self, instance.chat_id, from_id).await?
{
if from_id != ContactId::SELF && !chat::is_contact_in_chat(self, chat_id, from_id).await? {
let chat_type: Chattype = self
.sql
.query_get_value("SELECT type FROM chats WHERE id=?", (chat_id,))
.await?
.with_context(|| format!("Chat type for chat {chat_id} not found"))?;
if chat_type != Chattype::Mailinglist {
bail!("receive_status_update: status sender not chat member.")
bail!("receive_status_update: status sender {from_id} is not a member of chat {chat_id}")
}
}
@@ -1086,7 +1088,7 @@ mod tests {
.await?;
let instance = t.get_last_msg().await;
assert_eq!(instance.viewtype, Viewtype::Webxdc);
assert_eq!(instance.get_filename(), Some("minimal.xdc".to_string()));
assert_eq!(instance.get_filename().unwrap(), "minimal.xdc");
receive_imf(
&t,
@@ -1096,7 +1098,7 @@ mod tests {
.await?;
let instance = t.get_last_msg().await;
assert_eq!(instance.viewtype, Viewtype::File); // we require the correct extension, only a mime type is not sufficient
assert_eq!(instance.get_filename(), Some("index.html".to_string()));
assert_eq!(instance.get_filename().unwrap(), "index.html");
Ok(())
}
@@ -1784,10 +1786,9 @@ mod tests {
// bob receives the instance together with the initial updates in a single message
let bob_instance = bob.recv_msg(&sent1).await;
assert_eq!(bob_instance.viewtype, Viewtype::Webxdc);
assert_eq!(bob_instance.get_filename(), Some("minimal.xdc".to_string()));
assert_eq!(bob_instance.get_filename().unwrap(), "minimal.xdc");
assert!(sent1.payload().contains("Content-Type: application/json"));
assert!(sent1.payload().contains("status-update.json"));
assert!(sent1.payload().contains(r#""payload":{"foo":"bar"}"#));
assert_eq!(
bob.get_webxdc_status_updates(bob_instance.id, StatusUpdateSerial(0))
.await?,