Use sync ephemeral events in sync Resposne (remove room_id)

Bump ruma to latest master which also fixes some server name as String
to now being of type Box<ServerName>.
This commit is contained in:
Devin R 2020-07-21 14:04:39 -04:00
parent 9a993fa7c1
commit 33bc666859
6 changed files with 82 additions and 102 deletions

View file

@ -64,7 +64,8 @@ use ruma::{
canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction,
topic,
},
AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, EventJson, EventType,
AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventJson,
EventType,
},
identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId},
};
@ -284,7 +285,7 @@ pub fn login_route(
Ok(login::Response {
user_id,
access_token: token,
home_server: Some(db.globals.server_name().to_string()),
home_server: Some(db.globals.server_name().to_owned()),
device_id: device_id.into(),
well_known: None,
}
@ -2530,9 +2531,9 @@ pub fn sync_route(
{
edus.push(
serde_json::from_str(
&serde_json::to_string(&AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Typing(
&serde_json::to_string(&AnySyncEphemeralRoomEvent::Typing(
db.rooms.edus.roomactives_all(&room_id)?,
)))
))
.expect("event is valid, we just created it"),
)
.expect("event is valid, we just created it"),
@ -2613,7 +2614,7 @@ pub fn sync_route(
{
edus.push(
serde_json::from_str(
&serde_json::to_string(&ruma::events::AnySyncEphemeralRoomEvent::Typing(
&serde_json::to_string(&AnySyncEphemeralRoomEvent::Typing(
db.rooms.edus.roomactives_all(&room_id)?,
))
.expect("event is valid, we just created it"),

View file

@ -515,7 +515,7 @@ impl Rooms {
event_id: EventId::try_from("$thiswillbefilledinlater").expect("we know this is valid"),
room_id: room_id.clone(),
sender: sender.clone(),
origin: globals.server_name().to_string(),
origin: globals.server_name().to_owned(),
origin_server_ts: utils::millis_since_unix_epoch()
.try_into()
.expect("time is valid"),

View file

@ -209,8 +209,10 @@ impl RoomEdus {
.unwrap_or(0))
}
/// Returns an iterator over all active events (e.g. typing notifications).
pub fn roomactives_all(&self, room_id: &RoomId) -> Result<ruma::events::typing::TypingEvent> {
pub fn roomactives_all(
&self,
room_id: &RoomId,
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {
let mut prefix = room_id.to_string().as_bytes().to_vec();
prefix.push(0xff);
@ -234,43 +236,10 @@ impl RoomEdus {
user_ids.push(user_id?);
}
Ok(ruma::events::typing::TypingEvent {
Ok(SyncEphemeralRoomEvent {
content: ruma::events::typing::TypingEventContent { user_ids },
room_id: room_id.clone(),
})
}
// REMOVE the above method and uncomment the bottom when ruma/ruma PR #141 is merged
// pub fn roomactives_all(
// &self,
// room_id: &RoomId,
// ) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {
// let mut prefix = room_id.to_string().as_bytes().to_vec();
// prefix.push(0xff);
// let mut user_ids = Vec::new();
// for user_id in self
// .roomactiveid_userid
// .scan_prefix(prefix)
// .values()
// .map(|user_id| {
// Ok::<_, Error>(
// UserId::try_from(utils::string_from_bytes(&user_id?).map_err(|_| {
// Error::bad_database("User ID in roomactiveid_userid is invalid unicode.")
// })?)
// .map_err(|_| {
// Error::bad_database("User ID in roomactiveid_userid is invalid.")
// })?,
// )
// })
// {
// user_ids.push(user_id?);
// }
// Ok(SyncEphemeralRoomEvent {
// content: ruma::events::typing::TypingEventContent { user_ids },
// })
// }
/// Sets a private read marker at `count`.
pub fn room_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> {

View file

@ -6,7 +6,7 @@ use ruma::{
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType,
StateEvent,
},
identifiers::{EventId, RoomId, UserId},
identifiers::{EventId, RoomId, ServerName, UserId},
};
use serde::{Deserialize, Serialize};
use serde_json::json;
@ -17,7 +17,7 @@ pub struct PduEvent {
pub event_id: EventId,
pub room_id: RoomId,
pub sender: UserId,
pub origin: String,
pub origin: Box<ServerName>,
pub origin_server_ts: UInt,
#[serde(rename = "type")]
pub kind: EventType,