Use ruma/ruma master, address review issues

This commit is contained in:
Devin R 2020-06-24 17:56:56 -04:00
parent eb5949dbc2
commit b1e7bc77a4
5 changed files with 44 additions and 20 deletions

View file

@ -1492,11 +1492,8 @@ impl BaseClient {
AnyStateEventStub::RoomTombstone(e) => { AnyStateEventStub::RoomTombstone(e) => {
event_emitter.on_room_tombstone(room, &e).await event_emitter.on_room_tombstone(room, &e).await
} }
AnyStateEventStub::RoomJoinRules(_e) => { AnyStateEventStub::RoomJoinRules(e) => {
// TODO is this needed ?? event_emitter.on_room_join_rules(room, &e).await
// event_emitter
// .on_room_join_rules(room, &e).await
} }
AnyStateEventStub::Custom(e) => { AnyStateEventStub::Custom(e) => {
event_emitter event_emitter

View file

@ -141,6 +141,8 @@ pub trait EventEmitter: Send + Sync {
async fn on_room_power_levels(&self, _: SyncRoom, _: &StateEventStub<PowerLevelsEventContent>) { async fn on_room_power_levels(&self, _: SyncRoom, _: &StateEventStub<PowerLevelsEventContent>) {
} }
/// Fires when `Client` receives a `RoomEvent::Tombstone` event. /// Fires when `Client` receives a `RoomEvent::Tombstone` event.
async fn on_room_join_rules(&self, _: SyncRoom, _: &StateEventStub<JoinRulesEventContent>) {}
/// Fires when `Client` receives a `RoomEvent::Tombstone` event.
async fn on_room_tombstone(&self, _: SyncRoom, _: &StateEventStub<TombstoneEventContent>) {} async fn on_room_tombstone(&self, _: SyncRoom, _: &StateEventStub<TombstoneEventContent>) {}
// `RoomEvent`s from `IncomingState` // `RoomEvent`s from `IncomingState`

View file

@ -4,7 +4,7 @@
//! feature is enabled. //! feature is enabled.
use std::cmp::Ordering; use std::cmp::Ordering;
use std::ops::Deref; use std::ops::{Deref, DerefMut};
use std::vec::IntoIter; use std::vec::IntoIter;
use crate::events::room::message::MessageEventContent; use crate::events::room::message::MessageEventContent;
@ -30,6 +30,12 @@ impl Deref for MessageWrapper {
} }
} }
impl DerefMut for MessageWrapper {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl PartialEq for MessageWrapper { impl PartialEq for MessageWrapper {
fn eq(&self, other: &MessageWrapper) -> bool { fn eq(&self, other: &MessageWrapper) -> bool {
self.0.event_id == other.0.event_id self.0.event_id == other.0.event_id
@ -98,6 +104,10 @@ impl MessageQueue {
pub fn iter(&self) -> impl Iterator<Item = &MessageWrapper> { pub fn iter(&self) -> impl Iterator<Item = &MessageWrapper> {
self.msgs.iter() self.msgs.iter()
} }
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut MessageWrapper> {
self.msgs.iter_mut()
}
} }
impl IntoIterator for MessageQueue { impl IntoIterator for MessageQueue {

View file

@ -30,6 +30,7 @@ use crate::events::room::{
member::{MemberEventContent, MembershipChange}, member::{MemberEventContent, MembershipChange},
name::NameEventContent, name::NameEventContent,
power_levels::{NotificationPowerLevels, PowerLevelsEventContent}, power_levels::{NotificationPowerLevels, PowerLevelsEventContent},
redaction::RedactionEventStub,
tombstone::TombstoneEventContent, tombstone::TombstoneEventContent,
}; };
@ -39,17 +40,17 @@ use crate::events::{
}; };
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use crate::events::{room::message::MessageEventContent as MsgContent, MessageEventStub}; use crate::events::{
room::message::{MessageEventContent, TextMessageEventContent},
MessageEventStub,
};
use crate::identifiers::{RoomAliasId, RoomId, UserId}; use crate::identifiers::{RoomAliasId, RoomId, UserId};
use crate::js_int::{Int, UInt}; use crate::js_int::{Int, UInt};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "messages")] #[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
type SentMessageEvent = MessageEventStub<MsgContent>;
#[derive(Debug, Default, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(test, derive(Clone))] #[cfg_attr(test, derive(Clone))]
/// `RoomName` allows the calculation of a text room name. /// `RoomName` allows the calculation of a text room name.
pub struct RoomName { pub struct RoomName {
@ -614,10 +615,29 @@ impl Room {
/// Returns true if `MessageQueue` was added to. /// Returns true if `MessageQueue` was added to.
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))] #[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
pub fn handle_message(&mut self, event: &SentMessageEvent) -> bool { pub fn handle_message(&mut self, event: &MessageEventStub<MessageEventContent>) -> bool {
self.messages.push(event.clone()) self.messages.push(event.clone())
} }
/// Handle a room.redaction event and update the `MessageQueue` if necessary.
///
/// Returns true if `MessageQueue` was updated.
#[cfg(feature = "messages")]
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
pub fn handle_redaction(&mut self, event: &RedactionEventStub) -> bool {
if let Some(msg) = self
.messages
.iter_mut()
.find(|msg| event.redacts == msg.event_id)
{
// TODO make msg an enum or use AnyMessageEventStub enum to represent
msg.content = MessageEventContent::Text(TextMessageEventContent::new_plain("Redacted"));
true
} else {
false
}
}
/// Handle a room.aliases event, updating the room state if necessary. /// Handle a room.aliases event, updating the room state if necessary.
/// ///
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
@ -722,8 +742,8 @@ impl Room {
AnyRoomEventStub::Message(event) => match &event { AnyRoomEventStub::Message(event) => match &event {
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
AnyMessageEventStub::RoomMessage(event) => self.handle_message(&event), AnyMessageEventStub::RoomMessage(event) => self.handle_message(&event),
// TODO if a redaction event deletes one of our saved messages delete it? #[cfg(feature = "messages")]
AnyMessageEventStub::RoomRedaction(_) => false, AnyMessageEventStub::RoomRedaction(event) => self.handle_redaction(&event),
_ => false, _ => false,
}, },
} }

View file

@ -12,13 +12,8 @@ version = "0.1.0"
[dependencies] [dependencies]
js_int = "0.1.5" js_int = "0.1.5"
# ruma-api = "0.16.1"
# ruma-client-api = "0.9.0"
# ruma-events = "0.21.2"
# ruma-identifiers = "0.16.1"
ruma = { git = "https://github.com/DevinR528/ruma", features = ["client-api", "rand"], branch = "matrix-sdk2"} ruma = { git = "https://github.com/ruma/ruma", features = ["client-api", "rand"] }
# ruma = { path = "../../ruma/ruma", features = ["client-api", "rand"] }
instant = { version = "0.1.4", features = ["wasm-bindgen", "now"] } instant = { version = "0.1.4", features = ["wasm-bindgen", "now"] }