feat: send messages over federation

This commit is contained in:
Timo Kösters 2020-09-14 20:23:19 +02:00
parent 9f05ef926a
commit f7816b11de
No known key found for this signature in database
GPG key ID: 356E705610F626D5
15 changed files with 324 additions and 218 deletions

View file

@ -6,7 +6,7 @@ use ruma::{
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
},
EventId, Raw, RoomId, ServerKeyId, ServerName, UserId,
};
events::pdu::PduStub};
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::{collections::BTreeMap, convert::TryInto, sync::Arc, time::UNIX_EPOCH};
@ -198,6 +198,31 @@ impl PduEvent {
serde_json::from_value(json).expect("Raw::from_value always works")
}
pub fn to_outgoing_federation_event(&self) -> Raw<PduStub> {
let mut json = json!({
"room_id": self.room_id,
"sender": self.sender,
"origin_server_ts": self.origin_server_ts,
"type": self.kind,
"content": self.content,
"prev_events": self.prev_events,
"depth": self.depth,
"auth_events": self.auth_events,
"unsigned": self.unsigned,
"hashes": self.hashes,
"signatures": self.signatures,
});
if let Some(state_key) = &self.state_key {
json["state_key"] = json!(state_key);
}
if let Some(redacts) = &self.redacts {
json["redacts"] = json!(redacts);
}
serde_json::from_value(json).expect("Raw::from_value always works")
}
}
impl From<&state_res::StateEvent> for PduEvent {