basic w30 sending and receiving

This commit is contained in:
B. Petersen
2021-11-22 18:20:34 +01:00
committed by bjoern
parent 41f9314e2a
commit de20e4c9dd
16 changed files with 810 additions and 7 deletions

View File

@@ -66,6 +66,7 @@ pub struct MimeMessage {
pub location_kml: Option<location::Kml>,
pub message_kml: Option<location::Kml>,
pub(crate) sync_items: Option<SyncItems>,
pub(crate) w30_status_update: Option<String>,
pub(crate) user_avatar: Option<AvatarAction>,
pub(crate) group_avatar: Option<AvatarAction>,
pub(crate) mdn_reports: Vec<Report>,
@@ -135,6 +136,10 @@ pub enum SystemMessage {
/// Self-sent-message that contains only json used for multi-device-sync;
/// if possible, we attach that to other messages as for locations.
MultiDeviceSync = 20,
// Sync message that contains a json payload
// sent to the other w30 instances
W30StatusUpdate = 30,
}
impl Default for SystemMessage {
@@ -296,6 +301,7 @@ impl MimeMessage {
location_kml: None,
message_kml: None,
sync_items: None,
w30_status_update: None,
user_avatar: None,
group_avatar: None,
failure_report: None,
@@ -538,7 +544,7 @@ impl MimeMessage {
};
if let Some(ref subject) = self.get_subject() {
if !self.has_chat_version() {
if !self.has_chat_version() && self.w30_status_update.is_none() {
part.msg = subject.to_string();
}
}
@@ -837,6 +843,12 @@ impl MimeMessage {
.await?;
}
}
Some("status-update") => {
if let Some(second) = mail.subparts.get(1) {
self.add_single_part_if_known(context, second, is_related)
.await?;
}
}
Some(_) => {
if let Some(first) = mail.subparts.get(0) {
any_part_added = self
@@ -1006,8 +1018,13 @@ impl MimeMessage {
if decoded_data.is_empty() {
return;
}
// treat location/message kml file attachments specially
if filename.ends_with(".kml") {
let msg_type = if context
.is_w30_file(filename, decoded_data)
.await
.unwrap_or(false)
{
Viewtype::W30
} else if filename.ends_with(".kml") {
// XXX what if somebody sends eg an "location-highlights.kml"
// attachment unrelated to location streaming?
if filename.starts_with("location") || filename.starts_with("message") {
@@ -1023,6 +1040,7 @@ impl MimeMessage {
}
return;
}
msg_type
} else if filename == "multi-device-sync.json" {
let serialized = String::from_utf8_lossy(decoded_data)
.parse()
@@ -1035,7 +1053,15 @@ impl MimeMessage {
})
.ok();
return;
}
} else if filename == "status-update.json" {
let serialized = String::from_utf8_lossy(decoded_data)
.parse()
.unwrap_or_default();
self.w30_status_update = Some(serialized);
return;
} else {
msg_type
};
/* we have a regular file attachment,
write decoded data to new blob object */