Add basic handling of EDUs for /send/txn

next
Devin Ragotzy 2020-11-08 14:46:26 -05:00 committed by Timo Kösters
parent 0d69ebdc6c
commit c9a6ce54cb
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
1 changed files with 35 additions and 1 deletions

View File

@ -383,7 +383,41 @@ pub async fn send_transaction_message_route<'a>(
return Err(Error::bad_config("Federation is disabled."));
}
//dbg!(&*body);
for edu in &body.edus {
match serde_json::from_str::<send_transaction_message::v1::Edu>(edu.json().get()) {
Ok(edu) => match edu.edu_type.as_str() {
"m.typing" => {
if let Some(typing) = edu.content.get("typing") {
if typing.as_bool().unwrap_or_default() {
db.rooms.edus.typing_add(
&UserId::try_from(edu.content["user_id"].as_str().unwrap())
.unwrap(),
&RoomId::try_from(edu.content["room_id"].as_str().unwrap())
.unwrap(),
3000 + utils::millis_since_unix_epoch(),
&db.globals,
)?;
} else {
db.rooms.edus.typing_remove(
&UserId::try_from(edu.content["user_id"].as_str().unwrap())
.unwrap(),
&RoomId::try_from(edu.content["room_id"].as_str().unwrap())
.unwrap(),
&db.globals,
)?;
}
}
}
"m.presence" => {}
"m.receipt" => {}
_ => {}
},
Err(_err) => {
log::error!("{}", _err);
continue;
}
}
}
// TODO: For RoomVersion6 we must check that Raw<..> is canonical do we?
// SPEC:
// Servers MUST strictly enforce the JSON format specified in the appendices.