mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
allow webxdc document names (#3317)
* allow webxdc document names * test document webxdc property * update CHANGELOG
This commit is contained in:
@@ -59,6 +59,7 @@ struct WebxdcManifest {
|
||||
pub struct WebxdcInfo {
|
||||
pub name: String,
|
||||
pub icon: String,
|
||||
pub document: String,
|
||||
pub summary: String,
|
||||
pub source_code_url: String,
|
||||
}
|
||||
@@ -116,6 +117,9 @@ pub(crate) struct StatusUpdateItem {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
info: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
document: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
summary: Option<String>,
|
||||
}
|
||||
@@ -191,8 +195,8 @@ impl Context {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Takes an update-json as `{payload: PAYLOAD}` (or legacy `PAYLOAD`)
|
||||
/// writes it to the database and handles events, info-messages and summary.
|
||||
/// Takes an update-json as `{payload: PAYLOAD}`
|
||||
/// writes it to the database and handles events, info-messages, document name and summary.
|
||||
async fn create_status_update_record(
|
||||
&self,
|
||||
instance: &mut Message,
|
||||
@@ -212,6 +216,7 @@ impl Context {
|
||||
| MessageState::OutDraft => StatusUpdateItem {
|
||||
payload: item.payload,
|
||||
info: None, // no info-messages in draft mode
|
||||
document: item.document,
|
||||
summary: item.summary,
|
||||
},
|
||||
_ => item,
|
||||
@@ -234,17 +239,33 @@ impl Context {
|
||||
.await?;
|
||||
}
|
||||
|
||||
let mut param_changed = false;
|
||||
|
||||
if let Some(ref document) = status_update_item.document {
|
||||
if instance
|
||||
.param
|
||||
.update_timestamp(Param::WebxdcDocumentTimestamp, timestamp)?
|
||||
{
|
||||
instance.param.set(Param::WebxdcDocument, document);
|
||||
param_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref summary) = status_update_item.summary {
|
||||
if instance
|
||||
.param
|
||||
.update_timestamp(Param::WebxdcSummaryTimestamp, timestamp)?
|
||||
{
|
||||
instance.param.set(Param::WebxdcSummary, summary);
|
||||
instance.update_param(self).await;
|
||||
self.emit_msgs_changed(instance.chat_id, instance.id);
|
||||
param_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if param_changed {
|
||||
instance.update_param(self).await;
|
||||
self.emit_msgs_changed(instance.chat_id, instance.id);
|
||||
}
|
||||
|
||||
let rowid = self
|
||||
.sql
|
||||
.insert(
|
||||
@@ -572,6 +593,11 @@ impl Message {
|
||||
} else {
|
||||
WEBXDC_DEFAULT_ICON.to_string()
|
||||
},
|
||||
document: self
|
||||
.param
|
||||
.get(Param::WebxdcDocument)
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
summary: self
|
||||
.param
|
||||
.get(Param::WebxdcSummary)
|
||||
@@ -1536,6 +1562,48 @@ sth_for_the = "future""#
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_webxdc_document_name() -> Result<()> {
|
||||
let alice = TestContext::new_alice().await;
|
||||
let bob = TestContext::new_bob().await;
|
||||
|
||||
// Alice creates an webxdc instance and updates document name
|
||||
let alice_chat = alice.create_chat(&bob).await;
|
||||
let alice_instance = send_webxdc_instance(&alice, alice_chat.id).await?;
|
||||
let sent_instance = &alice.pop_sent_msg().await;
|
||||
let info = alice_instance.get_webxdc_info(&alice).await?;
|
||||
assert_eq!(info.document, "".to_string());
|
||||
assert_eq!(info.summary, "".to_string());
|
||||
|
||||
alice
|
||||
.send_webxdc_status_update(
|
||||
alice_instance.id,
|
||||
r#"{"document":"my file", "payload":1337}"#,
|
||||
"descr",
|
||||
)
|
||||
.await?;
|
||||
let sent_update1 = &alice.pop_sent_msg().await;
|
||||
let info = Message::load_from_db(&alice, alice_instance.id)
|
||||
.await?
|
||||
.get_webxdc_info(&alice)
|
||||
.await?;
|
||||
assert_eq!(info.document, "my file".to_string());
|
||||
assert_eq!(info.summary, "".to_string());
|
||||
|
||||
// Bob receives the updates
|
||||
bob.recv_msg(sent_instance).await;
|
||||
let bob_instance = bob.get_last_msg().await;
|
||||
bob.recv_msg(sent_update1).await;
|
||||
let info = Message::load_from_db(&bob, bob_instance.id)
|
||||
.await?
|
||||
.get_webxdc_info(&bob)
|
||||
.await?;
|
||||
assert_eq!(info.document, "my file".to_string());
|
||||
assert_eq!(info.summary, "".to_string());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_webxdc_info_msg() -> Result<()> {
|
||||
let alice = TestContext::new_alice().await;
|
||||
|
||||
Reference in New Issue
Block a user