Compare commits

...

4 Commits

Author SHA1 Message Date
B. Petersen
cecec79618 feat: allow to notify all webxdc peers 2024-11-25 11:21:09 +01:00
iequidoo
5db574b44f refactor: create_status_update_record: Get rid of notify var
It's used in the only place. Also this way `get_webxdc_self_addr()` which makes a db query is only
called when necessary.
2024-11-25 11:18:07 +01:00
iequidoo
8af90a1299 feat: AEAP: Check that the old peerstate verified key fingerprint hasn't changed when removing it 2024-11-24 15:51:19 -03:00
bjoern
a6db7ba1e3 api: deprecate webxdc descr parameter (#6255)
this PR removes most usages of the `descr` parameter.

- to avoid noise in different branches etc. (as annoying on similar, at
a first glance simple changes), i left the external API stable

- also, the effort to do a database migration seems to be over the top,
so the column is left and set to empty strings on future updates - maybe
we can recycle the column at some point ;)

closes #6245
2024-11-24 16:34:24 +00:00
8 changed files with 127 additions and 129 deletions

View File

@@ -1161,8 +1161,7 @@ uint32_t dc_send_videochat_invitation (dc_context_t* context, uint32_t chat_id);
* - `document`: optional document name. shown eg. in title bar.
* - `summary`: optional summary. shown beside app icon.
* - `notify`: optional array of other users `selfAddr` to be notified e.g. by a sound about `info` or `summary`.
* @param descr The user-visible description of JSON data,
* in case of a chess game, e.g. the move.
* @param descr Deprecated, set to NULL
* @return 1=success, 0=error
*/
int dc_send_webxdc_status_update (dc_context_t* context, uint32_t msg_id, const char* json, const char* descr);

View File

@@ -1065,7 +1065,7 @@ pub unsafe extern "C" fn dc_send_webxdc_status_update(
context: *mut dc_context_t,
msg_id: u32,
json: *const libc::c_char,
descr: *const libc::c_char,
_descr: *const libc::c_char,
) -> libc::c_int {
if context.is_null() {
eprintln!("ignoring careless call to dc_send_webxdc_status_update()");
@@ -1073,14 +1073,10 @@ pub unsafe extern "C" fn dc_send_webxdc_status_update(
}
let ctx = &*context;
block_on(ctx.send_webxdc_status_update(
MsgId::new(msg_id),
&to_string_lossy(json),
&to_string_lossy(descr),
))
.context("Failed to send webxdc update")
.log_err(ctx)
.is_ok() as libc::c_int
block_on(ctx.send_webxdc_status_update(MsgId::new(msg_id), &to_string_lossy(json)))
.context("Failed to send webxdc update")
.log_err(ctx)
.is_ok() as libc::c_int
}
#[no_mangle]

View File

@@ -1767,10 +1767,10 @@ impl CommandApi {
account_id: u32,
instance_msg_id: u32,
update_str: String,
description: String,
_descr: String,
) -> Result<()> {
let ctx = self.get_context(account_id).await?;
ctx.send_webxdc_status_update(MsgId::new(instance_msg_id), &update_str, &description)
ctx.send_webxdc_status_update(MsgId::new(instance_msg_id), &update_str)
.await
}

View File

@@ -969,9 +969,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
"Arguments <msg-id> <json status update> expected"
);
let msg_id = MsgId::new(arg1.parse()?);
context
.send_webxdc_status_update(msg_id, arg2, "this is a webxdc status update")
.await?;
context.send_webxdc_status_update(msg_id, arg2).await?;
}
"videochat" => {
ensure!(sel_chat.is_some(), "No chat selected.");

View File

@@ -440,7 +440,7 @@ mod tests {
let _sent1 = alice.send_msg(chat_id, &mut instance).await;
alice
.send_webxdc_status_update(instance.id, r#"{"payload":7}"#, "d")
.send_webxdc_status_update(instance.id, r#"{"payload":7}"#)
.await?;
alice.flush_status_updates().await?;
let sent2 = alice.pop_sent_msg().await;

View File

@@ -542,6 +542,8 @@ impl Peerstate {
/// * `old_addr`: Old address of the peerstate in case of an AEAP transition.
pub(crate) async fn save_to_db_ex(&self, sql: &Sql, old_addr: Option<&str>) -> Result<()> {
let trans_fn = |t: &mut rusqlite::Transaction| {
let verified_key_fingerprint =
self.verified_key_fingerprint.as_ref().map(|fp| fp.hex());
if let Some(old_addr) = old_addr {
// We are doing an AEAP transition to the new address and the SQL INSERT below will
// save the existing peerstate as belonging to this new address. We now need to
@@ -551,11 +553,14 @@ impl Peerstate {
// existing peerstate as this would break encryption to it. This is critical for
// non-verified groups -- if we can't encrypt to the old address, we can't securely
// remove it from the group (to add the new one instead).
//
// NB: We check that `verified_key_fingerprint` hasn't changed to protect from
// possible races.
t.execute(
"UPDATE acpeerstates \
SET verified_key=NULL, verified_key_fingerprint='', verifier='' \
WHERE addr=?",
(old_addr,),
"UPDATE acpeerstates
SET verified_key=NULL, verified_key_fingerprint='', verifier=''
WHERE addr=? AND verified_key_fingerprint=?",
(old_addr, &verified_key_fingerprint),
)?;
}
t.execute(
@@ -604,7 +609,7 @@ impl Peerstate {
self.public_key_fingerprint.as_ref().map(|fp| fp.hex()),
self.gossip_key_fingerprint.as_ref().map(|fp| fp.hex()),
self.verified_key.as_ref().map(|k| k.to_bytes()),
self.verified_key_fingerprint.as_ref().map(|fp| fp.hex()),
&verified_key_fingerprint,
self.verifier.as_deref().unwrap_or(""),
self.secondary_verified_key.as_ref().map(|k| k.to_bytes()),
self.secondary_verified_key_fingerprint

View File

@@ -13,7 +13,7 @@
//! - `msg_id` - ID of the message in the `msgs` table
//! - `first_serial` - serial number of the first status update to send
//! - `last_serial` - serial number of the last status update to send
//! - `descr` - text to send along with the updates
//! - `descr` - not used, set to empty string
mod integration;
mod maps_integration;
@@ -56,6 +56,9 @@ const WEBXDC_API_VERSION: u32 = 1;
pub const WEBXDC_SUFFIX: &str = "xdc";
const WEBXDC_DEFAULT_ICON: &str = "__webxdc__/default-icon.png";
/// Text shown to classic e-mail users in the visible e-mail body.
const BODY_DESCR: &str = "Webxdc Status Update";
/// Raw information read from manifest.toml
#[derive(Debug, Deserialize, Default)]
#[non_exhaustive]
@@ -323,12 +326,6 @@ impl Context {
return Ok(None);
};
let notify = if let Some(notify_list) = status_update_item.notify {
let self_addr = instance.get_webxdc_self_addr(self).await?;
notify_list.contains(&self_addr)
} else {
false
};
let mut notify_msg_id = instance.id;
let mut notify_text = "".to_string();
let mut param_changed = false;
@@ -409,12 +406,23 @@ impl Context {
});
}
if notify && !notify_text.is_empty() && from_id != ContactId::SELF {
self.emit_event(EventType::IncomingWebxdcNotify {
contact_id: from_id,
msg_id: notify_msg_id,
text: notify_text,
});
if !notify_text.is_empty() && from_id != ContactId::SELF {
if let Some(notify_list) = status_update_item.notify {
let notify = if notify_list.contains(&"all".to_string()) {
true
} else {
let self_addr = instance.get_webxdc_self_addr(self).await?;
notify_list.contains(&self_addr)
};
if notify {
self.emit_event(EventType::IncomingWebxdcNotify {
contact_id: from_id,
msg_id: notify_msg_id,
text: notify_text,
});
}
}
}
Ok(Some(status_update_serial))
@@ -483,11 +491,10 @@ impl Context {
&self,
instance_msg_id: MsgId,
update_str: &str,
descr: &str,
) -> Result<()> {
let status_update_item: StatusUpdateItem = serde_json::from_str(update_str)
.with_context(|| format!("Failed to parse webxdc update item from {update_str:?}"))?;
self.send_webxdc_status_update_struct(instance_msg_id, status_update_item, descr)
self.send_webxdc_status_update_struct(instance_msg_id, status_update_item)
.await?;
Ok(())
}
@@ -498,7 +505,6 @@ impl Context {
&self,
instance_msg_id: MsgId,
mut status_update: StatusUpdateItem,
descr: &str,
) -> Result<()> {
let instance = Message::load_from_db(self, instance_msg_id)
.await
@@ -546,10 +552,10 @@ impl Context {
if send_now {
self.sql.insert(
"INSERT INTO smtp_status_updates (msg_id, first_serial, last_serial, descr) VALUES(?, ?, ?, ?)
"INSERT INTO smtp_status_updates (msg_id, first_serial, last_serial, descr) VALUES(?, ?, ?, '')
ON CONFLICT(msg_id)
DO UPDATE SET last_serial=excluded.last_serial, descr=excluded.descr",
(instance.id, status_update_serial, status_update_serial, descr),
DO UPDATE SET last_serial=excluded.last_serial",
(instance.id, status_update_serial, status_update_serial),
).await.context("Failed to insert webxdc update into SMTP queue")?;
self.scheduler.interrupt_smtp().await;
}
@@ -557,21 +563,18 @@ impl Context {
}
/// Returns one record of the queued webxdc status updates.
async fn smtp_status_update_get(
&self,
) -> Result<Option<(MsgId, i64, StatusUpdateSerial, String)>> {
async fn smtp_status_update_get(&self) -> Result<Option<(MsgId, i64, StatusUpdateSerial)>> {
let res = self
.sql
.query_row_optional(
"SELECT msg_id, first_serial, last_serial, descr \
"SELECT msg_id, first_serial, last_serial \
FROM smtp_status_updates LIMIT 1",
(),
|row| {
let instance_id: MsgId = row.get(0)?;
let first_serial: i64 = row.get(1)?;
let last_serial: StatusUpdateSerial = row.get(2)?;
let descr: String = row.get(3)?;
Ok((instance_id, first_serial, last_serial, descr))
Ok((instance_id, first_serial, last_serial))
},
)
.await?;
@@ -609,7 +612,7 @@ impl Context {
/// Attempts to send queued webxdc status updates.
pub(crate) async fn flush_status_updates(&self) -> Result<()> {
loop {
let (instance_id, first, last, descr) = match self.smtp_status_update_get().await? {
let (instance_id, first, last) = match self.smtp_status_update_get().await? {
Some(res) => res,
None => return Ok(()),
};
@@ -626,7 +629,7 @@ impl Context {
let mut status_update = Message {
chat_id: instance.chat_id,
viewtype: Viewtype::Text,
text: descr.to_string(),
text: BODY_DESCR.to_string(),
hidden: true,
..Default::default()
};
@@ -1133,7 +1136,6 @@ mod tests {
t.send_webxdc_status_update(
instance.id,
r#"{"info": "foo", "summary":"bar", "document":"doc", "payload": 42}"#,
"descr",
)
.await?;
assert!(!instance.is_forwarded());
@@ -1184,7 +1186,6 @@ mod tests {
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload":7,"info": "i","summary":"s"}"#,
"d",
)
.await?;
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 2);
@@ -1267,7 +1268,7 @@ mod tests {
.await
.is_ok());
assert!(bob
.send_webxdc_status_update(bob_instance.id, r#"{"payload":42}"#, "descr")
.send_webxdc_status_update(bob_instance.id, r#"{"payload":42}"#)
.await
.is_err());
assert_eq!(
@@ -1279,7 +1280,7 @@ mod tests {
// Once the contact request is accepted, Bob can send updates
bob_chat.id.accept(&bob).await?;
assert!(bob
.send_webxdc_status_update(bob_instance.id, r#"{"payload":42}"#, "descr")
.send_webxdc_status_update(bob_instance.id, r#"{"payload":42}"#)
.await
.is_ok());
assert_eq!(
@@ -1310,7 +1311,6 @@ mod tests {
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload": 7, "summary":"sum", "document":"doc"}"#,
"bla",
)
.await?;
alice.flush_status_updates().await?;
@@ -1437,7 +1437,7 @@ mod tests {
.await?;
chat_id.set_draft(&t, Some(&mut instance)).await?;
let instance = chat_id.get_draft(&t).await?.unwrap();
t.send_webxdc_status_update(instance.id, r#"{"payload": 42}"#, "descr")
t.send_webxdc_status_update(instance.id, r#"{"payload": 42}"#)
.await?;
assert_eq!(
t.get_webxdc_status_updates(instance.id, StatusUpdateSerial(0))
@@ -1520,12 +1520,12 @@ mod tests {
assert_eq!(update_id1_duplicate, None);
assert!(t
.send_webxdc_status_update(instance.id, "\n\n\n", "")
.send_webxdc_status_update(instance.id, "\n\n\n")
.await
.is_err());
assert!(t
.send_webxdc_status_update(instance.id, "bad json", "")
.send_webxdc_status_update(instance.id, "bad json")
.await
.is_err());
@@ -1584,7 +1584,6 @@ mod tests {
t.send_webxdc_status_update(
instance.id,
r#"{"payload" : 1, "sender": "that is not used"}"#,
"",
)
.await?;
assert_eq!(
@@ -1719,11 +1718,7 @@ mod tests {
assert!(!sent1.payload().contains("report-type=status-update"));
alice
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload" : {"foo":"bar"}}"#,
"descr text",
)
.send_webxdc_status_update(alice_instance.id, r#"{"payload" : {"foo":"bar"}}"#)
.await?;
alice.flush_status_updates().await?;
expect_status_update_event(&alice, alice_instance.id).await?;
@@ -1732,7 +1727,7 @@ mod tests {
assert!(alice_update.hidden);
assert_eq!(alice_update.viewtype, Viewtype::Text);
assert_eq!(alice_update.get_filename(), None);
assert_eq!(alice_update.text, "descr text".to_string());
assert_eq!(alice_update.text, BODY_DESCR.to_string());
assert_eq!(alice_update.chat_id, alice_instance.chat_id);
assert_eq!(
alice_update.parent(&alice).await?.unwrap().id,
@@ -1740,7 +1735,7 @@ mod tests {
);
assert_eq!(alice_chat.id.get_msg_cnt(&alice).await?, 1);
assert!(sent2.payload().contains("report-type=status-update"));
assert!(sent2.payload().contains("descr text"));
assert!(sent2.payload().contains(BODY_DESCR));
assert_eq!(
alice
.get_webxdc_status_updates(alice_instance.id, StatusUpdateSerial(0))
@@ -1749,11 +1744,7 @@ mod tests {
);
alice
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload":{"snipp":"snapp"}}"#,
"bla text",
)
.send_webxdc_status_update(alice_instance.id, r#"{"payload":{"snipp":"snapp"}}"#)
.await?;
assert_eq!(
alice
@@ -1822,31 +1813,23 @@ mod tests {
+ &String::from_utf8(vec![b'a'; STATUS_UPDATE_SIZE_MAX])?
+ r#""}"#;
alice
.send_webxdc_status_update(alice_instance.id, &(update1_str.clone() + "}"), "descr1")
.send_webxdc_status_update(alice_instance.id, &(update1_str.clone() + "}"))
.await?;
alice
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload" : {"foo":"bar2"}}"#,
"descr2",
)
.send_webxdc_status_update(alice_instance.id, r#"{"payload" : {"foo":"bar2"}}"#)
.await?;
alice
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload" : {"foo":"bar3"}}"#,
"descr3",
)
.send_webxdc_status_update(alice_instance.id, r#"{"payload" : {"foo":"bar3"}}"#)
.await?;
alice.flush_status_updates().await?;
// There's the message stack, so we pop messages in the reverse order.
let sent3 = &alice.pop_sent_msg().await;
let alice_update = sent3.load_from_db().await;
assert_eq!(alice_update.text, "descr3".to_string());
assert_eq!(alice_update.text, BODY_DESCR.to_string());
let sent2 = &alice.pop_sent_msg().await;
let alice_update = sent2.load_from_db().await;
assert_eq!(alice_update.text, "descr3".to_string());
assert_eq!(alice_update.text, BODY_DESCR.to_string());
assert_eq!(alice_chat.id.get_msg_cnt(&alice).await?, 1);
// Bob receives the instance.
@@ -1897,7 +1880,7 @@ mod tests {
(None, StatusUpdateSerial(u32::MAX))
);
t.send_webxdc_status_update(instance.id, r#"{"payload": 1}"#, "bla")
t.send_webxdc_status_update(instance.id, r#"{"payload": 1}"#)
.await?;
let (object, first_new) = t
.render_webxdc_status_update_object(instance.id, first, last, None)
@@ -1913,13 +1896,13 @@ mod tests {
let t = TestContext::new_alice().await;
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat").await?;
let instance = send_webxdc_instance(&t, chat_id).await?;
t.send_webxdc_status_update(instance.id, r#"{"payload": 1}"#, "d")
t.send_webxdc_status_update(instance.id, r#"{"payload": 1}"#)
.await?;
t.send_webxdc_status_update(instance.id, r#"{"payload": 2}"#, "d")
t.send_webxdc_status_update(instance.id, r#"{"payload": 2}"#)
.await?;
t.send_webxdc_status_update(instance.id, r#"{"payload": 3}"#, "d")
t.send_webxdc_status_update(instance.id, r#"{"payload": 3}"#)
.await?;
t.send_webxdc_status_update(instance.id, r#"{"payload": 4}"#, "d")
t.send_webxdc_status_update(instance.id, r#"{"payload": 4}"#)
.await?;
let (json, first_new) = t
.render_webxdc_status_update_object(
@@ -1964,17 +1947,17 @@ mod tests {
let instance3 = send_webxdc_instance(&t, chat_id).await?;
assert!(t.smtp_status_update_get().await?.is_none());
t.send_webxdc_status_update(instance1.id, r#"{"payload": "1a"}"#, "descr1a")
t.send_webxdc_status_update(instance1.id, r#"{"payload": "1a"}"#)
.await?;
t.send_webxdc_status_update(instance2.id, r#"{"payload": "2a"}"#, "descr2a")
t.send_webxdc_status_update(instance2.id, r#"{"payload": "2a"}"#)
.await?;
t.send_webxdc_status_update(instance2.id, r#"{"payload": "2b"}"#, "descr2b")
t.send_webxdc_status_update(instance2.id, r#"{"payload": "2b"}"#)
.await?;
t.send_webxdc_status_update(instance3.id, r#"{"payload": "3a"}"#, "descr3a")
t.send_webxdc_status_update(instance3.id, r#"{"payload": "3a"}"#)
.await?;
t.send_webxdc_status_update(instance3.id, r#"{"payload": "3b"}"#, "descr3b")
t.send_webxdc_status_update(instance3.id, r#"{"payload": "3b"}"#)
.await?;
t.send_webxdc_status_update(instance3.id, r#"{"payload": "3c"}"#, "descr3c")
t.send_webxdc_status_update(instance3.id, r#"{"payload": "3c"}"#)
.await?;
assert_eq!(
t.sql
@@ -1986,7 +1969,7 @@ mod tests {
// order of smtp_status_update_get() is not defined, therefore the more complicated test
let mut instances_checked = 0;
for i in 0..3 {
let (instance, min_ser, max_ser, descr) = t.smtp_status_update_get().await?.unwrap();
let (instance, min_ser, max_ser) = t.smtp_status_update_get().await?.unwrap();
t.smtp_status_update_pop_serials(
instance,
min_ser,
@@ -1996,15 +1979,14 @@ mod tests {
let min_ser: u32 = min_ser.try_into()?;
if instance == instance1.id {
assert_eq!(min_ser, max_ser.to_u32());
assert_eq!(descr, "descr1a");
instances_checked += 1;
} else if instance == instance2.id {
assert_eq!(min_ser, max_ser.to_u32() - 1);
assert_eq!(descr, "descr2b");
instances_checked += 1;
} else if instance == instance3.id {
assert_eq!(min_ser, max_ser.to_u32() - 2);
assert_eq!(descr, "descr3c");
instances_checked += 1;
} else {
bail!("unexpected instance");
@@ -2042,11 +2024,11 @@ mod tests {
let mut alice_instance = alice_chat_id.get_draft(&alice).await?.unwrap();
alice
.send_webxdc_status_update(alice_instance.id, r#"{"payload": {"foo":"bar"}}"#, "descr")
.send_webxdc_status_update(alice_instance.id, r#"{"payload": {"foo":"bar"}}"#)
.await?;
expect_status_update_event(&alice, alice_instance.id).await?;
alice
.send_webxdc_status_update(alice_instance.id, r#"{"payload":42, "info":"i"}"#, "descr")
.send_webxdc_status_update(alice_instance.id, r#"{"payload":42, "info":"i"}"#)
.await?;
expect_status_update_event(&alice, alice_instance.id).await?;
assert_eq!(
@@ -2093,7 +2075,7 @@ mod tests {
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
let msg_id = send_text_msg(&t, chat_id, "ho!".to_string()).await?;
assert!(t
.send_webxdc_status_update(msg_id, r#"{"foo":"bar"}"#, "descr")
.send_webxdc_status_update(msg_id, r#"{"foo":"bar"}"#)
.await
.is_err());
Ok(())
@@ -2387,11 +2369,7 @@ sth_for_the = "future""#
assert_eq!(info.summary, "".to_string());
alice
.send_webxdc_status_update(
alice_instance.id,
r#"{"summary":"sum: 1", "payload":1}"#,
"descr",
)
.send_webxdc_status_update(alice_instance.id, r#"{"summary":"sum: 1", "payload":1}"#)
.await?;
alice.flush_status_updates().await?;
let sent_update1 = &alice.pop_sent_msg().await;
@@ -2402,11 +2380,7 @@ sth_for_the = "future""#
assert_eq!(info.summary, "sum: 1".to_string());
alice
.send_webxdc_status_update(
alice_instance.id,
r#"{"summary":"sum: 2", "payload":2}"#,
"descr",
)
.send_webxdc_status_update(alice_instance.id, r#"{"summary":"sum: 2", "payload":2}"#)
.await?;
alice.flush_status_updates().await?;
let sent_update2 = &alice.pop_sent_msg().await;
@@ -2457,7 +2431,6 @@ sth_for_the = "future""#
.send_webxdc_status_update(
alice_instance.id,
r#"{"document":"my file", "payload":1337}"#,
"descr",
)
.await?;
alice.flush_status_updates().await?;
@@ -2497,7 +2470,6 @@ sth_for_the = "future""#
.send_webxdc_status_update(
alice_instance.id,
r#"{"info":"this appears in-chat", "payload":"sth. else"}"#,
"descr text",
)
.await?;
alice.flush_status_updates().await?;
@@ -2575,13 +2547,13 @@ sth_for_the = "future""#
// Alice sends two info messages in a row;
// the second one removes the first one as there is nothing in between
alice
.send_webxdc_status_update(alice_instance.id, r#"{"info":"i1", "payload":1}"#, "d")
.send_webxdc_status_update(alice_instance.id, r#"{"info":"i1", "payload":1}"#)
.await?;
alice.flush_status_updates().await?;
let sent2 = &alice.pop_sent_msg().await;
assert_eq!(alice_chat.id.get_msg_cnt(&alice).await?, 2);
alice
.send_webxdc_status_update(alice_instance.id, r#"{"info":"i2", "payload":2}"#, "d")
.send_webxdc_status_update(alice_instance.id, r#"{"info":"i2", "payload":2}"#)
.await?;
alice.flush_status_updates().await?;
let sent3 = &alice.pop_sent_msg().await;
@@ -2608,12 +2580,12 @@ sth_for_the = "future""#
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "c").await?;
let instance = send_webxdc_instance(&t, chat_id).await?;
t.send_webxdc_status_update(instance.id, r#"{"info":"i1", "payload":1}"#, "d")
t.send_webxdc_status_update(instance.id, r#"{"info":"i1", "payload":1}"#)
.await?;
assert_eq!(chat_id.get_msg_cnt(&t).await?, 2);
send_text_msg(&t, chat_id, "msg between info".to_string()).await?;
assert_eq!(chat_id.get_msg_cnt(&t).await?, 3);
t.send_webxdc_status_update(instance.id, r#"{"info":"i2", "payload":2}"#, "d")
t.send_webxdc_status_update(instance.id, r#"{"info":"i2", "payload":2}"#)
.await?;
assert_eq!(chat_id.get_msg_cnt(&t).await?, 4);
@@ -2642,7 +2614,7 @@ sth_for_the = "future""#
let alice_instance = send_webxdc_instance(&alice, alice_chat_id).await?;
let sent1 = &alice.pop_sent_msg().await;
alice
.send_webxdc_status_update(alice_instance.id, r#"{"payload":42}"#, "descr")
.send_webxdc_status_update(alice_instance.id, r#"{"payload":42}"#)
.await?;
alice.flush_status_updates().await?;
let sent2 = &alice.pop_sent_msg().await;
@@ -2662,7 +2634,7 @@ sth_for_the = "future""#
Contact::create(&bob, "", "claire@example.org").await?,
)
.await?;
bob.send_webxdc_status_update(bob_instance.id, r#"{"payload":43}"#, "descr")
bob.send_webxdc_status_update(bob_instance.id, r#"{"payload":43}"#)
.await?;
bob.flush_status_updates().await?;
let sent3 = bob.pop_sent_msg().await;
@@ -2700,7 +2672,6 @@ sth_for_the = "future""#
t.send_webxdc_status_update(
instance_id,
r#"{"summary":"real summary", "payload": 42}"#,
"descr",
)
.await?;
let instance = Message::load_from_db(&t, instance_id).await?;
@@ -2778,7 +2749,6 @@ sth_for_the = "future""#
bob.send_webxdc_status_update(
bob_instance.id,
r#"{"payload":7,"info": "i","summary":"s"}"#,
"",
)
.await?;
bob.flush_status_updates().await?;
@@ -2898,7 +2868,6 @@ sth_for_the = "future""#
.send_webxdc_status_update(
alice_instance.id,
r#"{"payload":"p","info":"i","aNewUnknownProperty":"x","max_serial":123}"#,
"Some description",
)
.await?;
alice.flush_status_updates().await?;
@@ -2997,7 +2966,6 @@ sth_for_the = "future""#
"{{\"payload\":7,\"info\": \"Alice moved\",\"notify\":[\"{}\"]}}",
bob_instance.get_webxdc_self_addr(&bob).await?
),
"d",
)
.await?;
alice.flush_status_updates().await?;
@@ -3042,7 +3010,7 @@ sth_for_the = "future""#
bob_instance.get_webxdc_self_addr(&bob).await?,
fiona_instance.get_webxdc_self_addr(&fiona).await?
),
"d",
)
.await?;
alice.flush_status_updates().await?;
@@ -3064,6 +3032,43 @@ sth_for_the = "future""#
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_webxdc_notify_all() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = tcm.alice().await;
let bob = tcm.bob().await;
let fiona = tcm.fiona().await;
let grp_id = alice
.create_group_with_members(ProtectionStatus::Unprotected, "grp", &[&bob, &fiona])
.await;
let alice_instance = send_webxdc_instance(&alice, grp_id).await?;
let sent1 = alice.pop_sent_msg().await;
bob.recv_msg(&sent1).await;
fiona.recv_msg(&sent1).await;
alice
.send_webxdc_status_update(
alice_instance.id,
&format!("{{\"payload\":7,\"info\": \"go\", \"notify\":[\"all\"]}}"),
)
.await?;
alice.flush_status_updates().await?;
let sent2 = alice.pop_sent_msg().await;
let info_msg = alice.get_last_msg().await;
assert!(!has_incoming_webxdc_event(&alice, info_msg, "go").await);
bob.recv_msg_trash(&sent2).await;
let info_msg = bob.get_last_msg().await;
assert!(has_incoming_webxdc_event(&bob, info_msg, "go").await);
fiona.recv_msg_trash(&sent2).await;
let info_msg = fiona.get_last_msg().await;
assert!(has_incoming_webxdc_event(&fiona, info_msg, "go").await);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_webxdc_no_notify_self() -> Result<()> {
let mut tcm = TestContextManager::new();
@@ -3088,7 +3093,6 @@ sth_for_the = "future""#
"{{\"payload\":7,\"info\": \"moved\", \"notify\":[\"{}\"]}}",
alice2_instance.get_webxdc_self_addr(&alice2).await?
),
"d",
)
.await?;
alice.flush_status_updates().await?;
@@ -3125,7 +3129,6 @@ sth_for_the = "future""#
"{{\"payload\":7,\"summary\": \"4 moves done\",\"notify\":[\"{}\"]}}",
bob_instance.get_webxdc_self_addr(&bob).await?
),
"d",
)
.await?;
alice.flush_status_updates().await?;
@@ -3154,7 +3157,6 @@ sth_for_the = "future""#
.send_webxdc_status_update(
instance.id,
r##"{"payload": "my deeplink data", "info": "my move!", "href": "#foobar"}"##,
"d",
)
.await?;
alice.flush_status_updates().await?;

View File

@@ -205,7 +205,6 @@ mod tests {
t.send_webxdc_status_update(
integration_id,
r#"{"payload": {"action": "pos", "lat": 11.0, "lng": 12.0, "label": "poi #1"}}"#,
"descr",
)
.await?;
t.evtracker
@@ -239,7 +238,6 @@ mod tests {
t.send_webxdc_status_update(
integration_id,
r#"{"payload": {"action": "pos", "lat": 22.0, "lng": 23.0, "label": "poi #2"}}"#,
"descr",
)
.await?;
let updates = t