Rebase upstream/master into ruma-mono branch
parent
b1e7bc77a4
commit
68822861d5
|
@ -1,7 +1,9 @@
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
api::r0::sync::sync_events::Response as SyncResponse,
|
api::r0::sync::sync_events::Response as SyncResponse,
|
||||||
events::room::message::{MessageEventContent, TextMessageEventContent},
|
events::{
|
||||||
events::MessageEventStub,
|
room::message::{MessageEventContent, TextMessageEventContent},
|
||||||
|
AnyMessageEventStub, AnyRoomEventStub, MessageEventStub,
|
||||||
|
},
|
||||||
identifiers::RoomId,
|
identifiers::RoomId,
|
||||||
Client, ClientConfig, SyncSettings,
|
Client, ClientConfig, SyncSettings,
|
||||||
};
|
};
|
||||||
|
@ -43,7 +45,9 @@ impl WasmBot {
|
||||||
for (room_id, room) in response.rooms.join {
|
for (room_id, room) in response.rooms.join {
|
||||||
for event in room.timeline.events {
|
for event in room.timeline.events {
|
||||||
if let Ok(event) = event.deserialize() {
|
if let Ok(event) = event.deserialize() {
|
||||||
self.on_room_message(&room_id, event).await
|
if let AnyRoomEventStub::Message(AnyMessageEventStub::RoomMessage(ev)) = event {
|
||||||
|
self.on_room_message(&room_id, ev).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1639,8 +1639,8 @@ mod test {
|
||||||
client.restore_login(session).await.unwrap();
|
client.restore_login(session).await.unwrap();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
.add_state_event(EventsFile::PowerLevels)
|
.add_state_event(EventsJson::PowerLevels)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client
|
client
|
||||||
|
@ -2406,6 +2406,8 @@ mod test {
|
||||||
base_client.sync_token().await,
|
base_client.sync_token().await,
|
||||||
Some("s526_47314_0_7_1_1_1_11444_1".to_string())
|
Some("s526_47314_0_7_1_1_1_11444_1".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// This is commented out because this field is private...
|
||||||
// assert_eq!(
|
// assert_eq!(
|
||||||
// *base_client.ignored_users.read().await,
|
// *base_client.ignored_users.read().await,
|
||||||
// vec![UserId::try_from("@someone:example.org").unwrap()]
|
// vec![UserId::try_from("@someone:example.org").unwrap()]
|
||||||
|
|
|
@ -11,7 +11,10 @@ use matrix_sdk_common::{
|
||||||
},
|
},
|
||||||
uiaa::AuthData,
|
uiaa::AuthData,
|
||||||
},
|
},
|
||||||
events::{room::power_levels::PowerLevelsEventContent, EventJson},
|
events::{
|
||||||
|
room::{create::PreviousRoom, power_levels::PowerLevelsEventContent},
|
||||||
|
EventJson,
|
||||||
|
},
|
||||||
identifiers::{DeviceId, RoomId, UserId},
|
identifiers::{DeviceId, RoomId, UserId},
|
||||||
js_int::UInt,
|
js_int::UInt,
|
||||||
};
|
};
|
||||||
|
@ -267,7 +270,7 @@ impl Into<get_message_events::Request> for MessagesRequestBuilder {
|
||||||
from: self.from,
|
from: self.from,
|
||||||
to: self.to,
|
to: self.to,
|
||||||
dir: self.direction.unwrap_or(Direction::Backward),
|
dir: self.direction.unwrap_or(Direction::Backward),
|
||||||
limit: self.limit.map(UInt::from),
|
limit: self.limit.map(UInt::from).unwrap_or_default(),
|
||||||
filter: self.filter,
|
filter: self.filter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ use crate::session::Session;
|
||||||
use crate::state::{AllRooms, ClientState, StateStore};
|
use crate::state::{AllRooms, ClientState, StateStore};
|
||||||
use crate::EventEmitter;
|
use crate::EventEmitter;
|
||||||
use matrix_sdk_common::events::{
|
use matrix_sdk_common::events::{
|
||||||
AnyBasicEvent, AnyEphemeralRoomEvent, AnyMessageEventStub, AnyRoomEventStub, AnyStateEventStub,
|
AnyBasicEvent, AnyEphemeralRoomEventStub, AnyMessageEventStub, AnyRoomEventStub,
|
||||||
AnyStrippedStateEventStub, EventJson,
|
AnyStateEventStub, AnyStrippedStateEventStub, EventJson,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
|
@ -105,7 +105,9 @@ fn hoist_room_event_prev_content(
|
||||||
let mut ev = event.deserialize().ok()?;
|
let mut ev = event.deserialize().ok()?;
|
||||||
|
|
||||||
match &mut ev {
|
match &mut ev {
|
||||||
RoomEvent::RoomMember(ref mut member) if member.prev_content.is_none() => {
|
AnyRoomEventStub::State(AnyStateEventStub::RoomMember(ref mut member))
|
||||||
|
if member.prev_content.is_none() =>
|
||||||
|
{
|
||||||
if let Ok(prev) = prev_content.deserialize() {
|
if let Ok(prev) = prev_content.deserialize() {
|
||||||
member.prev_content = Some(prev)
|
member.prev_content = Some(prev)
|
||||||
}
|
}
|
||||||
|
@ -130,9 +132,7 @@ fn hoist_state_event_prev_content(
|
||||||
|
|
||||||
let mut ev = event.deserialize().ok()?;
|
let mut ev = event.deserialize().ok()?;
|
||||||
match &mut ev {
|
match &mut ev {
|
||||||
AnyRoomEventStub::State(AnyStateEventStub::RoomMember(ref mut member))
|
AnyStateEventStub::RoomMember(ref mut member) if member.prev_content.is_none() => {
|
||||||
if member.prev_content.is_none() =>
|
|
||||||
{
|
|
||||||
member.prev_content = Some(prev_content.deserialize().ok()?);
|
member.prev_content = Some(prev_content.deserialize().ok()?);
|
||||||
Some(EventJson::from(ev))
|
Some(EventJson::from(ev))
|
||||||
}
|
}
|
||||||
|
@ -907,12 +907,12 @@ impl BaseClient {
|
||||||
pub async fn receive_ephemeral_event(
|
pub async fn receive_ephemeral_event(
|
||||||
&self,
|
&self,
|
||||||
_room_id: &RoomId,
|
_room_id: &RoomId,
|
||||||
event: &AnyEphemeralRoomEvent,
|
event: &AnyEphemeralRoomEventStub,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match &event {
|
match &event {
|
||||||
AnyEphemeralRoomEvent::FullyRead(_) => {}
|
AnyEphemeralRoomEventStub::FullyRead(_) => {}
|
||||||
AnyEphemeralRoomEvent::Receipt(_) => {}
|
AnyEphemeralRoomEventStub::Receipt(_) => {}
|
||||||
AnyEphemeralRoomEvent::Typing(_) => {}
|
AnyEphemeralRoomEventStub::Typing(_) => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
false
|
false
|
||||||
|
@ -1724,7 +1724,7 @@ impl BaseClient {
|
||||||
pub(crate) async fn emit_ephemeral_event(
|
pub(crate) async fn emit_ephemeral_event(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: &AnyEphemeralRoomEvent,
|
event: &AnyEphemeralRoomEventStub,
|
||||||
room_state: RoomStateType,
|
room_state: RoomStateType,
|
||||||
) {
|
) {
|
||||||
let lock = self.event_emitter.read().await;
|
let lock = self.event_emitter.read().await;
|
||||||
|
@ -1759,13 +1759,13 @@ impl BaseClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
AnyEphemeralRoomEvent::FullyRead(full_read) => {
|
AnyEphemeralRoomEventStub::FullyRead(full_read) => {
|
||||||
event_emitter.on_non_room_fully_read(room, &full_read).await
|
event_emitter.on_non_room_fully_read(room, &full_read).await
|
||||||
}
|
}
|
||||||
AnyEphemeralRoomEvent::Typing(typing) => {
|
AnyEphemeralRoomEventStub::Typing(typing) => {
|
||||||
event_emitter.on_non_room_typing(room, &typing).await
|
event_emitter.on_non_room_typing(room, &typing).await
|
||||||
}
|
}
|
||||||
AnyEphemeralRoomEvent::Receipt(receipt) => {
|
AnyEphemeralRoomEventStub::Receipt(receipt) => {
|
||||||
event_emitter.on_non_room_receipt(room, &receipt).await
|
event_emitter.on_non_room_receipt(room, &receipt).await
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -1887,7 +1887,7 @@ mod test {
|
||||||
#[async_test]
|
#[async_test]
|
||||||
async fn test_joined_room_creation() {
|
async fn test_joined_room_creation() {
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
let client = get_client().await;
|
let client = get_client().await;
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
@ -1907,7 +1907,7 @@ mod test {
|
||||||
assert!(room.is_some());
|
assert!(room.is_some());
|
||||||
|
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_left_event(&room_id, member_event(), AnyRoomEventStub::State)
|
.add_custom_left_event(&room_id, member_event())
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
sync_response.next_batch = "Hello".to_owned();
|
sync_response.next_batch = "Hello".to_owned();
|
||||||
|
@ -1928,7 +1928,7 @@ mod test {
|
||||||
async fn test_left_room_creation() {
|
async fn test_left_room_creation() {
|
||||||
let room_id = RoomId::try_from("!left_room:localhost").unwrap();
|
let room_id = RoomId::try_from("!left_room:localhost").unwrap();
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_left_event(&room_id, member_event(), AnyRoomEventStub::State)
|
.add_custom_left_event(&room_id, member_event())
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
let client = get_client().await;
|
let client = get_client().await;
|
||||||
|
@ -1944,8 +1944,10 @@ mod test {
|
||||||
let room = client.get_left_room(&room_id).await;
|
let room = client.get_left_room(&room_id).await;
|
||||||
assert!(room.is_some());
|
assert!(room.is_some());
|
||||||
|
|
||||||
|
let mem = member_event();
|
||||||
|
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_joined_event(&room_id, member_event(), AnyRoomEventStub::State)
|
.add_custom_joined_event(&room_id, mem)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
sync_response.next_batch = "Hello".to_owned();
|
sync_response.next_batch = "Hello".to_owned();
|
||||||
|
@ -1983,7 +1985,7 @@ mod test {
|
||||||
assert!(room.is_some());
|
assert!(room.is_some());
|
||||||
|
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_joined_event(&room_id, member_event(), AnyRoomEventStub::State)
|
.add_custom_joined_event(&room_id, member_event())
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
sync_response.next_batch = "Hello".to_owned();
|
sync_response.next_batch = "Hello".to_owned();
|
||||||
|
@ -2355,7 +2357,7 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client
|
client
|
||||||
|
|
|
@ -7,12 +7,12 @@ use std::cmp::Ordering;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::vec::IntoIter;
|
use std::vec::IntoIter;
|
||||||
|
|
||||||
use crate::events::room::message::MessageEventContent;
|
use crate::events::AnyMessageEventStub;
|
||||||
use crate::events::MessageEventStub;
|
|
||||||
|
|
||||||
use serde::{de, ser, Serialize};
|
use serde::{de, ser, Serialize};
|
||||||
|
|
||||||
type MessageEvent = MessageEventStub<MessageEventContent>;
|
const MESSAGE_QUEUE_CAP: usize = 35;
|
||||||
|
|
||||||
/// A queue that holds the 10 most recent messages received from the server.
|
/// A queue that holds the 10 most recent messages received from the server.
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct MessageQueue {
|
pub struct MessageQueue {
|
||||||
|
@ -20,10 +20,10 @@ pub struct MessageQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct MessageWrapper(MessageEvent);
|
pub struct MessageWrapper(pub AnyMessageEventStub);
|
||||||
|
|
||||||
impl Deref for MessageWrapper {
|
impl Deref for MessageWrapper {
|
||||||
type Target = MessageEvent;
|
type Target = AnyMessageEventStub;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -38,7 +38,7 @@ impl DerefMut for MessageWrapper {
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl Eq for MessageWrapper {}
|
||||||
|
|
||||||
impl PartialOrd for MessageWrapper {
|
impl PartialOrd for MessageWrapper {
|
||||||
fn partial_cmp(&self, other: &MessageWrapper) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &MessageWrapper) -> Option<Ordering> {
|
||||||
Some(self.0.origin_server_ts.cmp(&other.0.origin_server_ts))
|
Some(self.0.origin_server_ts().cmp(&other.0.origin_server_ts()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ impl PartialEq for MessageQueue {
|
||||||
.msgs
|
.msgs
|
||||||
.iter()
|
.iter()
|
||||||
.zip(other.msgs.iter())
|
.zip(other.msgs.iter())
|
||||||
.all(|(msg_a, msg_b)| msg_a.event_id == msg_b.event_id)
|
.all(|(msg_a, msg_b)| msg_a.event_id() == msg_b.event_id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,17 +71,17 @@ impl MessageQueue {
|
||||||
/// Create a new empty `MessageQueue`.
|
/// Create a new empty `MessageQueue`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
msgs: Vec::with_capacity(20),
|
msgs: Vec::with_capacity(45),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts a `MessageEvent` into `MessageQueue`, sorted by by `origin_server_ts`.
|
/// Inserts a `MessageEvent` into `MessageQueue`, sorted by by `origin_server_ts`.
|
||||||
///
|
///
|
||||||
/// Removes the oldest element in the queue if there are more than 10 elements.
|
/// Removes the oldest element in the queue if there are more than 10 elements.
|
||||||
pub fn push(&mut self, msg: MessageEvent) -> bool {
|
pub fn push(&mut self, msg: AnyMessageEventStub) -> bool {
|
||||||
// only push new messages into the queue
|
// only push new messages into the queue
|
||||||
if let Some(latest) = self.msgs.last() {
|
if let Some(latest) = self.msgs.last() {
|
||||||
if msg.origin_server_ts < latest.origin_server_ts && self.msgs.len() >= 10 {
|
if msg.origin_server_ts() < latest.origin_server_ts() && self.msgs.len() >= 10 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl MessageQueue {
|
||||||
}
|
}
|
||||||
Err(pos) => self.msgs.insert(pos, message),
|
Err(pos) => self.msgs.insert(pos, message),
|
||||||
}
|
}
|
||||||
if self.msgs.len() > 10 {
|
if self.msgs.len() > MESSAGE_QUEUE_CAP {
|
||||||
self.msgs.remove(0);
|
self.msgs.remove(0);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -126,7 +126,7 @@ pub(crate) mod ser_deser {
|
||||||
where
|
where
|
||||||
D: de::Deserializer<'de>,
|
D: de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let messages: Vec<MessageEvent> = de::Deserialize::deserialize(deserializer)?;
|
let messages: Vec<AnyMessageEventStub> = de::Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let mut msgs = vec![];
|
let mut msgs = vec![];
|
||||||
for msg in messages {
|
for msg in messages {
|
||||||
|
@ -156,7 +156,6 @@ mod test {
|
||||||
|
|
||||||
use matrix_sdk_test::test_json;
|
use matrix_sdk_test::test_json;
|
||||||
|
|
||||||
use crate::events::{collections::all::RoomEvent, EventJson};
|
|
||||||
use crate::identifiers::{RoomId, UserId};
|
use crate::identifiers::{RoomId, UserId};
|
||||||
use crate::Room;
|
use crate::Room;
|
||||||
|
|
||||||
|
@ -168,7 +167,7 @@ mod test {
|
||||||
let mut room = Room::new(&id, &user);
|
let mut room = Room::new(&id, &user);
|
||||||
|
|
||||||
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
|
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
|
||||||
let msg = serde_json::from_value::<MessageEvent>(json.clone()).unwrap();
|
let msg = serde_json::from_value::<AnyMessageEventStub>(json.clone()).unwrap();
|
||||||
|
|
||||||
let mut msgs = MessageQueue::new();
|
let mut msgs = MessageQueue::new();
|
||||||
msgs.push(msg.clone());
|
msgs.push(msg.clone());
|
||||||
|
@ -214,7 +213,7 @@ mod test {
|
||||||
let mut room = Room::new(&id, &user);
|
let mut room = Room::new(&id, &user);
|
||||||
|
|
||||||
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
|
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
|
||||||
let msg = serde_json::from_value::<MessageEvent>(json.clone()).unwrap();
|
let msg = serde_json::from_value::<AnyMessageEventStub>(json.clone()).unwrap();
|
||||||
|
|
||||||
let mut msgs = MessageQueue::new();
|
let mut msgs = MessageQueue::new();
|
||||||
msgs.push(msg.clone());
|
msgs.push(msg.clone());
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::collections::{BTreeMap, HashMap};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
use super::message::MessageQueue;
|
use super::message::{MessageQueue, MessageWrapper};
|
||||||
use super::RoomMember;
|
use super::RoomMember;
|
||||||
|
|
||||||
use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount};
|
use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount};
|
||||||
|
@ -30,28 +30,23 @@ 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,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::events::{
|
use crate::events::{
|
||||||
Algorithm, AnyMessageEventStub, AnyRoomEventStub, AnyStateEventStub, AnyStrippedStateEventStub,
|
Algorithm, AnyRoomEventStub, AnyStateEventStub, AnyStrippedStateEventStub, EventType,
|
||||||
EventType, StateEventStub, StrippedStateEventStub,
|
StateEventStub, StrippedStateEventStub,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
use crate::events::{
|
use crate::events::{room::redaction::RedactionEventStub, AnyMessageEventStub};
|
||||||
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};
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||||
#[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 {
|
||||||
/// The displayed name of the room.
|
/// The displayed name of the room.
|
||||||
|
@ -73,7 +68,7 @@ pub struct RoomName {
|
||||||
pub invited_member_count: Option<UInt>,
|
pub invited_member_count: Option<UInt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct PowerLevels {
|
pub struct PowerLevels {
|
||||||
/// The level required to ban a user.
|
/// The level required to ban a user.
|
||||||
pub ban: Int,
|
pub ban: Int,
|
||||||
|
@ -99,7 +94,7 @@ pub struct PowerLevels {
|
||||||
pub notifications: Int,
|
pub notifications: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
/// Encryption info of the room.
|
/// Encryption info of the room.
|
||||||
pub struct EncryptionInfo {
|
pub struct EncryptionInfo {
|
||||||
/// The encryption algorithm that should be used to encrypt messages in the
|
/// The encryption algorithm that should be used to encrypt messages in the
|
||||||
|
@ -144,7 +139,7 @@ impl From<&StateEventStub<EncryptionEventContent>> for EncryptionInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Tombstone {
|
pub struct Tombstone {
|
||||||
/// A server-defined message.
|
/// A server-defined message.
|
||||||
body: String,
|
body: String,
|
||||||
|
@ -158,7 +153,7 @@ enum MemberDirection {
|
||||||
Exiting,
|
Exiting,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
/// A Matrix room.
|
/// A Matrix room.
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
/// The unique id of the room.
|
/// The unique id of the room.
|
||||||
|
@ -361,14 +356,15 @@ impl Room {
|
||||||
member.name().into()
|
member.name().into()
|
||||||
} else {
|
} else {
|
||||||
// There is no member with the requested MXID in the room. We still return the MXID.
|
// There is no member with the requested MXID in the room. We still return the MXID.
|
||||||
id.as_ref().into()
|
id.as_str().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_member(&mut self, event: &StateEventStub<MemberEventContent>, room_id: &RoomId) -> bool {
|
fn add_member(&mut self, event: &StateEventStub<MemberEventContent>, room_id: &RoomId) -> bool {
|
||||||
if self
|
let new_member = RoomMember::new(event, room_id);
|
||||||
.members
|
|
||||||
.contains_key(&UserId::try_from(event.state_key.as_str()).unwrap())
|
if self.joined_members.contains_key(&new_member.user_id)
|
||||||
|
|| self.invited_members.contains_key(&new_member.user_id)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -390,8 +386,12 @@ impl Room {
|
||||||
/// Process the member event of a leaving user.
|
/// Process the member event of a leaving user.
|
||||||
///
|
///
|
||||||
/// Returns true if this made a change to the room's state, false otherwise.
|
/// Returns true if this made a change to the room's state, false otherwise.
|
||||||
fn remove_member(&mut self, event: &StateEventStub<MemberEventContent>) -> bool {
|
fn remove_member(
|
||||||
let leaving_member = RoomMember::new(event);
|
&mut self,
|
||||||
|
event: &StateEventStub<MemberEventContent>,
|
||||||
|
room_id: &RoomId,
|
||||||
|
) -> bool {
|
||||||
|
let leaving_member = RoomMember::new(event, room_id);
|
||||||
|
|
||||||
// Perform display name disambiguations, if necessary.
|
// Perform display name disambiguations, if necessary.
|
||||||
let disambiguations =
|
let disambiguations =
|
||||||
|
@ -587,12 +587,12 @@ impl Room {
|
||||||
// TODO: This would not be handled correctly as all the MemberEvents have the `prev_content`
|
// TODO: This would not be handled correctly as all the MemberEvents have the `prev_content`
|
||||||
// inside of `unsigned` field.
|
// inside of `unsigned` field.
|
||||||
match event.membership_change() {
|
match event.membership_change() {
|
||||||
Invited | Joined => self.add_member(event),
|
Invited | Joined => self.add_member(event, room_id),
|
||||||
Kicked | Banned | KickedAndBanned | InvitationRejected | Left => {
|
Kicked | Banned | KickedAndBanned | InvitationRejected | Left => {
|
||||||
self.remove_member(event)
|
self.remove_member(event, room_id)
|
||||||
}
|
}
|
||||||
ProfileChanged => {
|
ProfileChanged { .. } => {
|
||||||
let user = if let Ok(id) = UserId::try_from(event.state_key.as_str()) {
|
let user_id = if let Ok(id) = UserId::try_from(event.state_key.as_str()) {
|
||||||
id
|
id
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -615,7 +615,7 @@ 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: &MessageEventStub<MessageEventContent>) -> bool {
|
pub fn handle_message(&mut self, event: &AnyMessageEventStub) -> bool {
|
||||||
self.messages.push(event.clone())
|
self.messages.push(event.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,10 +628,10 @@ impl Room {
|
||||||
if let Some(msg) = self
|
if let Some(msg) = self
|
||||||
.messages
|
.messages
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|msg| event.redacts == msg.event_id)
|
.find(|msg| &event.redacts == msg.event_id())
|
||||||
{
|
{
|
||||||
// TODO make msg an enum or use AnyMessageEventStub enum to represent
|
// TODO make msg an enum or use AnyMessageEventStub enum to represent
|
||||||
msg.content = MessageEventContent::Text(TextMessageEventContent::new_plain("Redacted"));
|
*msg = MessageWrapper(AnyMessageEventStub::RoomRedaction(event.clone()));
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -741,7 +741,9 @@ 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),
|
// We ignore this variants event because `handle_message` takes the enum
|
||||||
|
// to store AnyMessageEventStub events in the `MessageQueue`.
|
||||||
|
AnyMessageEventStub::RoomMessage(_) => self.handle_message(&event),
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
AnyMessageEventStub::RoomRedaction(event) => self.handle_redaction(&event),
|
AnyMessageEventStub::RoomRedaction(event) => self.handle_redaction(&event),
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -968,23 +970,23 @@ mod test {
|
||||||
let mut event_builder = EventBuilder::new();
|
let mut event_builder = EventBuilder::new();
|
||||||
|
|
||||||
let mut member1_join_sync_response = event_builder
|
let mut member1_join_sync_response = event_builder
|
||||||
.add_room_event(EventsJson::Member, RoomEvent::RoomMember)
|
.add_room_event(EventsJson::Member)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
let mut member2_join_sync_response = event_builder
|
let mut member2_join_sync_response = event_builder
|
||||||
.add_custom_joined_event(&room_id, member2_join_event, RoomEvent::RoomMember)
|
.add_custom_joined_event(&room_id, member2_join_event)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
let mut member3_join_sync_response = event_builder
|
let mut member3_join_sync_response = event_builder
|
||||||
.add_custom_joined_event(&room_id, member3_join_event, RoomEvent::RoomMember)
|
.add_custom_joined_event(&room_id, member3_join_event)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
let mut member2_leave_sync_response = event_builder
|
let mut member2_leave_sync_response = event_builder
|
||||||
.add_custom_joined_event(&room_id, member2_leave_event, RoomEvent::RoomMember)
|
.add_custom_joined_event(&room_id, member2_leave_event)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
let mut member3_leave_sync_response = event_builder
|
let mut member3_leave_sync_response = event_builder
|
||||||
.add_custom_joined_event(&room_id, member3_leave_event, RoomEvent::RoomMember)
|
.add_custom_joined_event(&room_id, member3_leave_event)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
// First member with display name "example" joins
|
// First member with display name "example" joins
|
||||||
|
@ -1052,8 +1054,8 @@ mod test {
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = UserId::try_from("@example:localhost").unwrap();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
.add_state_event(EventsFile::PowerLevels)
|
.add_state_event(EventsJson::PowerLevels)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client.receive_sync_response(&mut response).await.unwrap();
|
client.receive_sync_response(&mut response).await.unwrap();
|
||||||
|
@ -1081,7 +1083,7 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Aliases)
|
.add_state_event(EventsJson::Aliases)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client.receive_sync_response(&mut response).await.unwrap();
|
client.receive_sync_response(&mut response).await.unwrap();
|
||||||
|
@ -1099,7 +1101,7 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Alias)
|
.add_state_event(EventsJson::Alias)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client.receive_sync_response(&mut response).await.unwrap();
|
client.receive_sync_response(&mut response).await.unwrap();
|
||||||
|
@ -1117,7 +1119,7 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Name)
|
.add_state_event(EventsJson::Name)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client.receive_sync_response(&mut response).await.unwrap();
|
client.receive_sync_response(&mut response).await.unwrap();
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub struct RoomMember {
|
||||||
/// If the user should be considered active.
|
/// If the user should be considered active.
|
||||||
pub currently_active: Option<bool>,
|
pub currently_active: Option<bool>,
|
||||||
/// The unique id of the room.
|
/// The unique id of the room.
|
||||||
pub room_id: Option<RoomId>,
|
pub room_id: RoomId,
|
||||||
/// If the member is typing.
|
/// If the member is typing.
|
||||||
pub typing: Option<bool>,
|
pub typing: Option<bool>,
|
||||||
/// The presence of the user, if found.
|
/// The presence of the user, if found.
|
||||||
|
@ -76,7 +76,7 @@ impl RoomMember {
|
||||||
pub fn new(event: &StateEventStub<MemberEventContent>, room_id: &RoomId) -> Self {
|
pub fn new(event: &StateEventStub<MemberEventContent>, room_id: &RoomId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: event.state_key.clone(),
|
name: event.state_key.clone(),
|
||||||
room_id: Some(room_id.clone()),
|
room_id: room_id.clone(),
|
||||||
user_id: UserId::try_from(event.state_key.as_str()).unwrap(),
|
user_id: UserId::try_from(event.state_key.as_str()).unwrap(),
|
||||||
display_name: event.content.displayname.clone(),
|
display_name: event.content.displayname.clone(),
|
||||||
avatar_url: event.content.avatar_url.clone(),
|
avatar_url: event.content.avatar_url.clone(),
|
||||||
|
@ -117,7 +117,8 @@ impl RoomMember {
|
||||||
use MembershipChange::*;
|
use MembershipChange::*;
|
||||||
|
|
||||||
match event.membership_change() {
|
match event.membership_change() {
|
||||||
ProfileChanged => {
|
// we assume that the profile has changed
|
||||||
|
ProfileChanged { .. } => {
|
||||||
self.display_name = event.content.displayname.clone();
|
self.display_name = event.content.displayname.clone();
|
||||||
self.avatar_url = event.content.avatar_url.clone();
|
self.avatar_url = event.content.avatar_url.clone();
|
||||||
true
|
true
|
||||||
|
@ -212,7 +213,6 @@ impl RoomMember {
|
||||||
mod test {
|
mod test {
|
||||||
use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
|
use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
|
||||||
|
|
||||||
use crate::events::room::member::MembershipState;
|
|
||||||
use crate::identifiers::{RoomId, UserId};
|
use crate::identifiers::{RoomId, UserId};
|
||||||
use crate::{BaseClient, Session};
|
use crate::{BaseClient, Session};
|
||||||
|
|
||||||
|
@ -245,8 +245,8 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
.add_state_event(EventsFile::PowerLevels)
|
.add_state_event(EventsJson::PowerLevels)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client.receive_sync_response(&mut response).await.unwrap();
|
client.receive_sync_response(&mut response).await.unwrap();
|
||||||
|
@ -268,9 +268,9 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsFile::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
.add_state_event(EventsFile::PowerLevels)
|
.add_state_event(EventsJson::PowerLevels)
|
||||||
.add_presence_event(EventsFile::Presence)
|
.add_presence_event(EventsJson::Presence)
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
client.receive_sync_response(&mut response).await.unwrap();
|
client.receive_sync_response(&mut response).await.unwrap();
|
||||||
|
|
|
@ -13,7 +13,7 @@ version = "0.1.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
js_int = "0.1.5"
|
js_int = "0.1.5"
|
||||||
|
|
||||||
ruma = { git = "https://github.com/ruma/ruma", features = ["client-api", "rand"] }
|
ruma = { git = "https://github.com/ruma/ruma", features = ["client-api"] }
|
||||||
|
|
||||||
instant = { version = "0.1.4", features = ["wasm-bindgen", "now"] }
|
instant = { version = "0.1.4", features = ["wasm-bindgen", "now"] }
|
||||||
|
|
||||||
|
|
|
@ -73,76 +73,53 @@ impl EventBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an event to the room events `Vec`.
|
/// Add an event to the room events `Vec`.
|
||||||
pub fn add_ephemeral<Ev: serde::de::DeserializeOwned>(
|
pub fn add_ephemeral(&mut self, json: EventsJson) -> &mut Self {
|
||||||
mut self,
|
|
||||||
file: EventsFile,
|
|
||||||
variant: fn(Ev) -> AnyEphemeralRoomEventStub,
|
|
||||||
) -> Self {
|
|
||||||
let val: &JsonValue = match json {
|
let val: &JsonValue = match json {
|
||||||
EventsJson::Typing => &test_json::TYPING,
|
EventsJson::Typing => &test_json::TYPING,
|
||||||
_ => panic!("unknown ephemeral event {:?}", json),
|
_ => panic!("unknown ephemeral event {:?}", json),
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = serde_json::from_value::<EventJson<Ev>>(val.clone())
|
let event = serde_json::from_value::<AnyEphemeralRoomEventStub>(val.clone()).unwrap();
|
||||||
.unwrap()
|
self.ephemeral.push(event);
|
||||||
.deserialize()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
self.ephemeral.push(variant(event));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an event to the room events `Vec`.
|
/// Add an event to the room events `Vec`.
|
||||||
#[allow(clippy::match_single_binding, unused)]
|
#[allow(clippy::match_single_binding, unused)]
|
||||||
pub fn add_account<Ev: TryFromRaw>(
|
pub fn add_account(&mut self, json: EventsJson) -> &mut Self {
|
||||||
&mut self,
|
|
||||||
json: EventsJson,
|
|
||||||
variant: fn(Ev) -> Event,
|
|
||||||
) -> &mut Self {
|
|
||||||
let val: &JsonValue = match json {
|
let val: &JsonValue = match json {
|
||||||
_ => panic!("unknown account event {:?}", json),
|
_ => panic!("unknown account event {:?}", json),
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = serde_json::from_value::<EventJson<Ev>>(val.clone())
|
let event = serde_json::from_value::<AnyBasicEvent>(val.clone()).unwrap();
|
||||||
.unwrap()
|
self.account_data.push(event);
|
||||||
.deserialize()
|
|
||||||
.unwrap();
|
|
||||||
self.account_data.push(variant(event));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Add an event to the room events `Vec`.
|
/// Add an event to the room events `Vec`.
|
||||||
// pub fn add_room_event<Ev: TryFromRaw>(
|
pub fn add_room_event(&mut self, json: EventsJson) -> &mut Self {
|
||||||
// &mut self,
|
let val: &JsonValue = match json {
|
||||||
// json: EventsJson,
|
EventsJson::Member => &test_json::MEMBER,
|
||||||
// variant: fn(Ev) -> AnyRoomEventStub,
|
EventsJson::PowerLevels => &test_json::POWER_LEVELS,
|
||||||
// ) -> &mut Self {
|
_ => panic!("unknown room event json {:?}", json),
|
||||||
// let val: &JsonValue = match json {
|
};
|
||||||
// EventsJson::Member => &test_json::MEMBER,
|
|
||||||
// EventsJson::PowerLevels => &test_json::POWER_LEVELS,
|
|
||||||
// _ => panic!("unknown room event json {:?}", json),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let event = serde_json::from_value::<EventJson<Ev>>(val.clone())
|
let event = serde_json::from_value::<AnyRoomEventStub>(val.clone()).unwrap();
|
||||||
// .unwrap()
|
|
||||||
// .deserialize()
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
// self.add_joined_event(
|
self.add_joined_event(
|
||||||
// &RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
|
&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
|
||||||
// variant(event),
|
event,
|
||||||
// );
|
);
|
||||||
// self
|
self
|
||||||
// }
|
}
|
||||||
|
|
||||||
pub fn add_custom_joined_event<Ev: serde::de::DeserializeOwned>(
|
pub fn add_custom_joined_event(
|
||||||
mut self,
|
&mut self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: serde_json::Value,
|
event: serde_json::Value,
|
||||||
variant: fn(Ev) -> AnyRoomEventStub,
|
) -> &mut Self {
|
||||||
) -> Self {
|
let event = serde_json::from_value::<AnyRoomEventStub>(event).unwrap();
|
||||||
let event = serde_json::from_value::<Ev>(event).unwrap();
|
self.add_joined_event(room_id, event);
|
||||||
self.add_joined_event(room_id, variant(event));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +130,11 @@ impl EventBuilder {
|
||||||
.push(event);
|
.push(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_custom_invited_event(mut self, room_id: &RoomId, event: serde_json::Value) -> Self {
|
pub fn add_custom_invited_event(
|
||||||
|
&mut self,
|
||||||
|
room_id: &RoomId,
|
||||||
|
event: serde_json::Value,
|
||||||
|
) -> &mut Self {
|
||||||
let event = serde_json::from_value::<AnyStateEventStub>(event).unwrap();
|
let event = serde_json::from_value::<AnyStateEventStub>(event).unwrap();
|
||||||
self.invited_room_events
|
self.invited_room_events
|
||||||
.entry(room_id.clone())
|
.entry(room_id.clone())
|
||||||
|
@ -162,35 +143,32 @@ impl EventBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_custom_left_event<Ev: serde::de::DeserializeOwned>(
|
pub fn add_custom_left_event(
|
||||||
mut self,
|
&mut self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: serde_json::Value,
|
event: serde_json::Value,
|
||||||
variant: fn(Ev) -> AnyRoomEventStub,
|
) -> &mut Self {
|
||||||
) -> Self {
|
let event = serde_json::from_value::<AnyRoomEventStub>(event).unwrap();
|
||||||
let event = serde_json::from_value::<Ev>(event).unwrap();
|
|
||||||
self.left_room_events
|
self.left_room_events
|
||||||
.entry(room_id.clone())
|
.entry(room_id.clone())
|
||||||
.or_insert_with(Vec::new)
|
.or_insert_with(Vec::new)
|
||||||
.push(variant(event));
|
.push(event);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a state event to the state events `Vec`.
|
/// Add a state event to the state events `Vec`.
|
||||||
pub fn add_state_event<Ev: TryFromRaw>(
|
pub fn add_state_event(&mut self, json: EventsJson) -> &mut Self {
|
||||||
&mut self,
|
|
||||||
json: EventsJson,
|
|
||||||
) -> &mut Self {
|
|
||||||
let val: &JsonValue = match json {
|
let val: &JsonValue = match json {
|
||||||
EventsJson::Alias => &test_json::ALIAS,
|
EventsJson::Alias => &test_json::ALIAS,
|
||||||
EventsJson::Aliases => &test_json::ALIASES,
|
EventsJson::Aliases => &test_json::ALIASES,
|
||||||
EventsJson::Name => &test_json::NAME,
|
EventsJson::Name => &test_json::NAME,
|
||||||
|
EventsJson::Member => &test_json::MEMBER,
|
||||||
|
EventsJson::PowerLevels => &test_json::POWER_LEVELS,
|
||||||
_ => panic!("unknown state event {:?}", json),
|
_ => panic!("unknown state event {:?}", json),
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = serde_json::from_value::<AnyStateEventStub>(val.clone())
|
let event = serde_json::from_value::<AnyStateEventStub>(val.clone()).unwrap();
|
||||||
.unwrap();
|
self.state_events.push(event);
|
||||||
self.state_events.push(variant(event));
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,8 +179,7 @@ impl EventBuilder {
|
||||||
_ => panic!("unknown presence event {:?}", json),
|
_ => panic!("unknown presence event {:?}", json),
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = serde_json::from_value::<PresenceEvent>(val.clone())
|
let event = serde_json::from_value::<PresenceEvent>(val.clone()).unwrap();
|
||||||
.unwrap();
|
|
||||||
self.presence_events.push(event);
|
self.presence_events.push(event);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,6 @@ lazy_static! {
|
||||||
"summary": {},
|
"summary": {},
|
||||||
"account_data": {
|
"account_data": {
|
||||||
"events": [
|
"events": [
|
||||||
{
|
|
||||||
"content": {
|
|
||||||
"event_id": "$someplace:example.org"
|
|
||||||
},
|
|
||||||
"room_id": "!roomid:room.com",
|
|
||||||
"type": "m.fully_read"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"content": {
|
"content": {
|
||||||
"ignored_users": {
|
"ignored_users": {
|
||||||
|
@ -47,7 +40,15 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"room_id": "!SVkFJHzfwvuaIEawgC:localhost",
|
||||||
"type": "m.receipt"
|
"type": "m.receipt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"event_id": "$someplace:example.org"
|
||||||
|
},
|
||||||
|
"room_id": "!roomid:room.com",
|
||||||
|
"type": "m.fully_read"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -305,13 +306,6 @@ lazy_static! {
|
||||||
},
|
},
|
||||||
"account_data": {
|
"account_data": {
|
||||||
"events": [
|
"events": [
|
||||||
{
|
|
||||||
"content": {
|
|
||||||
"event_id": "$someplace:example.org"
|
|
||||||
},
|
|
||||||
"room_id": "!roomid:room.com",
|
|
||||||
"type": "m.fully_read"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"content": {
|
"content": {
|
||||||
"ignored_users": {
|
"ignored_users": {
|
||||||
|
@ -335,6 +329,13 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "m.receipt"
|
"type": "m.receipt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"event_id": "$someplace:example.org"
|
||||||
|
},
|
||||||
|
"room_id": "!roomid:room.com",
|
||||||
|
"type": "m.fully_read"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -570,6 +571,7 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||||
"type": "m.receipt"
|
"type": "m.receipt"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -771,13 +773,6 @@ lazy_static! {
|
||||||
"summary": {},
|
"summary": {},
|
||||||
"account_data": {
|
"account_data": {
|
||||||
"events": [
|
"events": [
|
||||||
{
|
|
||||||
"content": {
|
|
||||||
"event_id": "$someplace:example.org"
|
|
||||||
},
|
|
||||||
"room_id": "!roomid:room.com",
|
|
||||||
"type": "m.fully_read"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"content": {
|
"content": {
|
||||||
"ignored_users": {
|
"ignored_users": {
|
||||||
|
@ -801,6 +796,13 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "m.receipt"
|
"type": "m.receipt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"event_id": "$someplace:example.org"
|
||||||
|
},
|
||||||
|
"room_id": "!roomid:room.com",
|
||||||
|
"type": "m.fully_read"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue