mirror of
https://github.com/chatmail/core.git
synced 2026-05-21 07:46:31 +03:00
feat: Send webxdc name instead of raw file name in pre-messages. Display it in summary (#7790)
The webxdc file name itself isn't informative for users. Still, send and display it if the webxdc manifest can't be parsed, it's better than sending "Mini App" and this isn't a normal case anyway.
This commit is contained in:
@@ -41,6 +41,14 @@ impl PostMsgMetadata {
|
|||||||
.get(Param::Filename)
|
.get(Param::Filename)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
let filename = match message.viewtype {
|
||||||
|
Viewtype::Webxdc => message
|
||||||
|
.get_webxdc_info(context)
|
||||||
|
.await
|
||||||
|
.map(|info| info.name)
|
||||||
|
.unwrap_or_else(|_| filename),
|
||||||
|
_ => filename,
|
||||||
|
};
|
||||||
let wh = {
|
let wh = {
|
||||||
match (
|
match (
|
||||||
message.param.get_int(Param::Width),
|
message.param.get_int(Param::Width),
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ impl Message {
|
|||||||
.unwrap_or_else(|_| "ErrWebxdcName".to_string()),
|
.unwrap_or_else(|_| "ErrWebxdcName".to_string()),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
type_file = Some(viewtype.to_locale_string(context).await);
|
type_file = self.get_filename();
|
||||||
}
|
}
|
||||||
append_text = true;
|
append_text = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,17 +79,22 @@ async fn test_receive_pre_message() -> Result<()> {
|
|||||||
assert_eq!(msg.get_filename(), Some("test.bin".to_owned()));
|
assert_eq!(msg.get_filename(), Some("test.bin".to_owned()));
|
||||||
assert_summary_texts(&msg, bob, "📎 test.bin – test").await;
|
assert_summary_texts(&msg, bob, "📎 test.bin – test").await;
|
||||||
|
|
||||||
// Some viewtypes are displayed unwell currently, still test them.
|
// Webxdc w/o manifest.
|
||||||
|
|
||||||
let (pre_message, ..) = send_large_webxdc_message(alice, alice_group_id).await?;
|
let (pre_message, ..) = send_large_webxdc_message(alice, alice_group_id).await?;
|
||||||
let msg = bob.recv_msg(&pre_message).await;
|
let msg = bob.recv_msg(&pre_message).await;
|
||||||
assert_eq!(msg.download_state, DownloadState::Available);
|
assert_eq!(msg.download_state, DownloadState::Available);
|
||||||
assert_summary_texts(
|
assert_summary_texts(&msg, bob, "📱 test.xdc – test").await;
|
||||||
&msg,
|
|
||||||
bob,
|
let (pre_message, ..) = send_large_file_message(
|
||||||
&format!("📱 {} – test", Viewtype::Webxdc.to_locale_string(bob).await),
|
alice,
|
||||||
|
alice_group_id,
|
||||||
|
Viewtype::Webxdc,
|
||||||
|
include_bytes!("../../../test-data/webxdc/timetracking-v0.10.1.xdc"),
|
||||||
)
|
)
|
||||||
.await;
|
.await?;
|
||||||
|
let msg = bob.recv_msg(&pre_message).await;
|
||||||
|
assert_eq!(msg.download_state, DownloadState::Available);
|
||||||
|
assert_summary_texts(&msg, bob, "📱 TimeTracking – test").await;
|
||||||
|
|
||||||
let (pre_message, ..) = send_large_file_message(
|
let (pre_message, ..) = send_large_file_message(
|
||||||
alice,
|
alice,
|
||||||
@@ -114,6 +119,33 @@ async fn test_receive_pre_message() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_receive_webxdc() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let alice = &tcm.alice().await;
|
||||||
|
let bob = &tcm.bob().await;
|
||||||
|
let alice_group_id = alice.create_group_with_members("", &[bob]).await;
|
||||||
|
|
||||||
|
let (pre_msg, post_msg, _) = send_large_file_message(
|
||||||
|
alice,
|
||||||
|
alice_group_id,
|
||||||
|
Viewtype::Webxdc,
|
||||||
|
include_bytes!("../../../test-data/webxdc/timetracking-v0.10.1.xdc"),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let msg = bob.recv_msg(&pre_msg).await;
|
||||||
|
assert_eq!(msg.download_state, DownloadState::Available);
|
||||||
|
assert_summary_texts(&msg, bob, "📱 TimeTracking – test").await;
|
||||||
|
assert_eq!(msg.get_filename().unwrap(), "TimeTracking");
|
||||||
|
|
||||||
|
bob.recv_msg_trash(&post_msg).await;
|
||||||
|
let msg = Message::load_from_db(bob, msg.id).await?;
|
||||||
|
assert_eq!(msg.download_state, DownloadState::Done);
|
||||||
|
assert_summary_texts(&msg, bob, "📱 TimeTracking – test").await;
|
||||||
|
assert_eq!(msg.get_filename().unwrap(), "test.xdc");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Test receiving the Post-Message after receiving the pre-message
|
/// Test receiving the Post-Message after receiving the pre-message
|
||||||
/// for file attachment
|
/// for file attachment
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
|||||||
BIN
test-data/webxdc/timetracking-v0.10.1.xdc
Normal file
BIN
test-data/webxdc/timetracking-v0.10.1.xdc
Normal file
Binary file not shown.
Reference in New Issue
Block a user