Merge branch 'messages'
commit
b97e67c404
|
@ -12,6 +12,7 @@ version = "0.1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["encryption", "sqlite-cryptostore"]
|
default = ["encryption", "sqlite-cryptostore"]
|
||||||
|
messages = []
|
||||||
encryption = ["matrix-sdk-crypto"]
|
encryption = ["matrix-sdk-crypto"]
|
||||||
sqlite-cryptostore = ["matrix-sdk-crypto/sqlite-cryptostore"]
|
sqlite-cryptostore = ["matrix-sdk-crypto/sqlite-cryptostore"]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,325 @@
|
||||||
|
//! A queue that holds at most ten of the most recent messages.
|
||||||
|
//!
|
||||||
|
//! The `Room` struct optionally holds a `MessageQueue` if the "messages"
|
||||||
|
//! feature is enabled.
|
||||||
|
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::vec::IntoIter;
|
||||||
|
|
||||||
|
use crate::events::room::message::MessageEvent;
|
||||||
|
use crate::events::EventJson;
|
||||||
|
|
||||||
|
use serde::{de, ser, Serialize};
|
||||||
|
|
||||||
|
/// A queue that holds the 10 most recent messages received from the server.
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct MessageQueue {
|
||||||
|
msgs: Vec<MessageWrapper>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
pub struct MessageWrapper(MessageEvent);
|
||||||
|
|
||||||
|
impl Deref for MessageWrapper {
|
||||||
|
type Target = MessageEvent;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for MessageWrapper {
|
||||||
|
fn eq(&self, other: &MessageWrapper) -> bool {
|
||||||
|
self.0.event_id == other.0.event_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eq for MessageWrapper {}
|
||||||
|
|
||||||
|
impl PartialOrd for MessageWrapper {
|
||||||
|
fn partial_cmp(&self, other: &MessageWrapper) -> Option<Ordering> {
|
||||||
|
Some(self.0.origin_server_ts.cmp(&other.0.origin_server_ts))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for MessageWrapper {
|
||||||
|
fn cmp(&self, other: &MessageWrapper) -> Ordering {
|
||||||
|
self.partial_cmp(other).unwrap_or(Ordering::Equal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for MessageQueue {
|
||||||
|
fn eq(&self, other: &MessageQueue) -> bool {
|
||||||
|
self.msgs.len() == other.msgs.len()
|
||||||
|
&& self
|
||||||
|
.msgs
|
||||||
|
.iter()
|
||||||
|
.zip(other.msgs.iter())
|
||||||
|
.all(|(msg_a, msg_b)| msg_a.event_id == msg_b.event_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MessageQueue {
|
||||||
|
/// Create a new empty `MessageQueue`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
msgs: Vec::with_capacity(20),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
pub fn push(&mut self, msg: MessageEvent) -> bool {
|
||||||
|
// only push new messages into the queue
|
||||||
|
if let Some(latest) = self.msgs.last() {
|
||||||
|
if msg.origin_server_ts < latest.origin_server_ts && self.msgs.len() >= 10 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = MessageWrapper(msg);
|
||||||
|
match self.msgs.binary_search_by(|m| m.cmp(&message)) {
|
||||||
|
Ok(pos) => {
|
||||||
|
if self.msgs[pos] != message {
|
||||||
|
self.msgs.insert(pos, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(pos) => self.msgs.insert(pos, message),
|
||||||
|
}
|
||||||
|
if self.msgs.len() > 10 {
|
||||||
|
self.msgs.remove(0);
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn iter(&self) -> impl Iterator<Item = &MessageWrapper> {
|
||||||
|
self.msgs.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoIterator for MessageQueue {
|
||||||
|
type Item = MessageWrapper;
|
||||||
|
type IntoIter = IntoIter<Self::Item>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.msgs.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) mod ser_deser {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<MessageQueue, D::Error>
|
||||||
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
use serde::de::Error;
|
||||||
|
|
||||||
|
let messages: Vec<EventJson<MessageEvent>> = de::Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
let mut msgs = vec![];
|
||||||
|
for json in messages {
|
||||||
|
let msg = json.deserialize().map_err(D::Error::custom)?;
|
||||||
|
msgs.push(MessageWrapper(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(MessageQueue { msgs })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize<S>(msgs: &MessageQueue, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: ser::Serializer,
|
||||||
|
{
|
||||||
|
msgs.msgs.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use crate::events::{collections::all::RoomEvent, EventJson};
|
||||||
|
use crate::identifiers::{RoomId, UserId};
|
||||||
|
use crate::Room;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize() {
|
||||||
|
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
||||||
|
let user = UserId::try_from("@example:example.com").unwrap();
|
||||||
|
|
||||||
|
let mut room = Room::new(&id, &user);
|
||||||
|
|
||||||
|
let json = std::fs::read_to_string("../test_data/events/message_text.json").unwrap();
|
||||||
|
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
|
||||||
|
|
||||||
|
let mut msgs = MessageQueue::new();
|
||||||
|
if let Ok(ev) = event.deserialize() {
|
||||||
|
if let RoomEvent::RoomMessage(msg) = ev {
|
||||||
|
msgs.push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
room.messages = msgs;
|
||||||
|
|
||||||
|
let mut joined_rooms = HashMap::new();
|
||||||
|
joined_rooms.insert(id, room);
|
||||||
|
println!("{}", serde_json::to_string_pretty(&joined_rooms).unwrap());
|
||||||
|
// this is the correct JSON string changes to `ruma-events` have not been released
|
||||||
|
// that would fix the doubling of fields
|
||||||
|
// TODO uncomment when fixed
|
||||||
|
// assert_eq!(
|
||||||
|
// r#"{
|
||||||
|
// "!roomid:example.com": {
|
||||||
|
// "room_id": "!roomid:example.com",
|
||||||
|
// "room_name": {
|
||||||
|
// "name": null,
|
||||||
|
// "canonical_alias": null,
|
||||||
|
// "aliases": [],
|
||||||
|
// "heroes": [],
|
||||||
|
// "joined_member_count": null,
|
||||||
|
// "invited_member_count": null
|
||||||
|
// },
|
||||||
|
// "own_user_id": "@example:example.com",
|
||||||
|
// "creator": null,
|
||||||
|
// "members": {},
|
||||||
|
// "messages": [
|
||||||
|
// {
|
||||||
|
// "type": "m.room.message",
|
||||||
|
// "content": {
|
||||||
|
// "body": "is dancing",
|
||||||
|
// "format": "org.matrix.custom.html",
|
||||||
|
// "formatted_body": "<strong>is dancing</strong>",
|
||||||
|
// "msgtype": "m.text"
|
||||||
|
// },
|
||||||
|
// "event_id": "$152037280074GZeOm:localhost",
|
||||||
|
// "origin_server_ts": 1520372800469,
|
||||||
|
// "sender": "@example:localhost",
|
||||||
|
// "unsigned": {
|
||||||
|
// "age": 598971425
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// "typing_users": [],
|
||||||
|
// "power_levels": null,
|
||||||
|
// "encrypted": false,
|
||||||
|
// "unread_highlight": null,
|
||||||
|
// "unread_notifications": null,
|
||||||
|
// "tombstone": null
|
||||||
|
// }
|
||||||
|
// }"#,
|
||||||
|
// serde_json::to_string_pretty(&joined_rooms).unwrap()
|
||||||
|
// );
|
||||||
|
assert_eq!(
|
||||||
|
r#"{
|
||||||
|
"!roomid:example.com": {
|
||||||
|
"room_id": "!roomid:example.com",
|
||||||
|
"room_name": {
|
||||||
|
"name": null,
|
||||||
|
"canonical_alias": null,
|
||||||
|
"aliases": [],
|
||||||
|
"heroes": [],
|
||||||
|
"joined_member_count": null,
|
||||||
|
"invited_member_count": null
|
||||||
|
},
|
||||||
|
"own_user_id": "@example:example.com",
|
||||||
|
"creator": null,
|
||||||
|
"members": {},
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "is dancing",
|
||||||
|
"format": "org.matrix.custom.html",
|
||||||
|
"formatted_body": "<strong>is dancing</strong>"
|
||||||
|
},
|
||||||
|
"event_id": "$152037280074GZeOm:localhost",
|
||||||
|
"origin_server_ts": 1520372800469,
|
||||||
|
"sender": "@example:localhost",
|
||||||
|
"unsigned": {
|
||||||
|
"age": 598971425
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typing_users": [],
|
||||||
|
"power_levels": null,
|
||||||
|
"encrypted": false,
|
||||||
|
"unread_highlight": null,
|
||||||
|
"unread_notifications": null,
|
||||||
|
"tombstone": null
|
||||||
|
}
|
||||||
|
}"#,
|
||||||
|
serde_json::to_string_pretty(&joined_rooms).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize() {
|
||||||
|
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
||||||
|
let user = UserId::try_from("@example:example.com").unwrap();
|
||||||
|
|
||||||
|
let mut room = Room::new(&id, &user);
|
||||||
|
|
||||||
|
let json = std::fs::read_to_string("../test_data/events/message_text.json").unwrap();
|
||||||
|
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
|
||||||
|
|
||||||
|
let mut msgs = MessageQueue::new();
|
||||||
|
if let Ok(ev) = event.deserialize() {
|
||||||
|
if let RoomEvent::RoomMessage(msg) = ev {
|
||||||
|
msgs.push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
room.messages = msgs;
|
||||||
|
|
||||||
|
let mut joined_rooms = HashMap::new();
|
||||||
|
joined_rooms.insert(id, room.clone());
|
||||||
|
|
||||||
|
let json = r#"{
|
||||||
|
"!roomid:example.com": {
|
||||||
|
"room_id": "!roomid:example.com",
|
||||||
|
"room_name": {
|
||||||
|
"name": null,
|
||||||
|
"canonical_alias": null,
|
||||||
|
"aliases": [],
|
||||||
|
"heroes": [],
|
||||||
|
"joined_member_count": null,
|
||||||
|
"invited_member_count": null
|
||||||
|
},
|
||||||
|
"own_user_id": "@example:example.com",
|
||||||
|
"creator": null,
|
||||||
|
"members": {},
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"type": "m.room.message",
|
||||||
|
"content": {
|
||||||
|
"body": "is dancing",
|
||||||
|
"format": "org.matrix.custom.html",
|
||||||
|
"formatted_body": "<strong>is dancing</strong>",
|
||||||
|
"msgtype": "m.text"
|
||||||
|
},
|
||||||
|
"event_id": "$152037280074GZeOm:localhost",
|
||||||
|
"origin_server_ts": 1520372800469,
|
||||||
|
"sender": "@example:localhost",
|
||||||
|
"unsigned": {
|
||||||
|
"age": 598971425
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typing_users": [],
|
||||||
|
"power_levels": null,
|
||||||
|
"encrypted": false,
|
||||||
|
"unread_highlight": null,
|
||||||
|
"unread_notifications": null,
|
||||||
|
"tombstone": null
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
assert_eq!(
|
||||||
|
joined_rooms,
|
||||||
|
serde_json::from_str::<HashMap<RoomId, Room>>(json).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
mod event_deser;
|
mod event_deser;
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
|
||||||
|
mod message;
|
||||||
mod room;
|
mod room;
|
||||||
mod room_member;
|
mod room_member;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
use super::message::MessageQueue;
|
||||||
use super::RoomMember;
|
use super::RoomMember;
|
||||||
|
|
||||||
use crate::api::r0::sync::sync_events::RoomSummary;
|
use crate::api::r0::sync::sync_events::RoomSummary;
|
||||||
|
@ -31,11 +33,16 @@ use crate::events::room::{
|
||||||
tombstone::TombstoneEvent,
|
tombstone::TombstoneEvent,
|
||||||
};
|
};
|
||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
|
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
use crate::events::room::message::MessageEvent;
|
||||||
|
|
||||||
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(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.
|
||||||
|
@ -58,6 +65,7 @@ pub struct RoomName {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(Clone))]
|
||||||
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,
|
||||||
|
@ -84,6 +92,7 @@ pub struct PowerLevels {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(Clone))]
|
||||||
pub struct Tombstone {
|
pub struct Tombstone {
|
||||||
/// A server-defined message.
|
/// A server-defined message.
|
||||||
body: String,
|
body: String,
|
||||||
|
@ -92,6 +101,7 @@ pub struct Tombstone {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(Clone))]
|
||||||
/// A Matrix room.
|
/// A Matrix room.
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
/// The unique id of the room.
|
/// The unique id of the room.
|
||||||
|
@ -104,6 +114,14 @@ pub struct Room {
|
||||||
pub creator: Option<UserId>,
|
pub creator: Option<UserId>,
|
||||||
/// The map of room members.
|
/// The map of room members.
|
||||||
pub members: HashMap<UserId, RoomMember>,
|
pub members: HashMap<UserId, RoomMember>,
|
||||||
|
/// A queue of messages, holds no more than 10 of the most recent messages.
|
||||||
|
///
|
||||||
|
/// This is helpful when using a `StateStore` to avoid multiple requests
|
||||||
|
/// to the server for messages.
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
|
||||||
|
#[serde(with = "super::message::ser_deser")]
|
||||||
|
pub messages: MessageQueue,
|
||||||
/// A list of users that are currently typing.
|
/// A list of users that are currently typing.
|
||||||
pub typing_users: Vec<UserId>,
|
pub typing_users: Vec<UserId>,
|
||||||
/// The power level requirements for specific actions in this room
|
/// The power level requirements for specific actions in this room
|
||||||
|
@ -207,6 +225,8 @@ impl Room {
|
||||||
own_user_id: own_user_id.clone(),
|
own_user_id: own_user_id.clone(),
|
||||||
creator: None,
|
creator: None,
|
||||||
members: HashMap::new(),
|
members: HashMap::new(),
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
messages: MessageQueue::new(),
|
||||||
typing_users: Vec::new(),
|
typing_users: Vec::new(),
|
||||||
power_levels: None,
|
power_levels: None,
|
||||||
encrypted: false,
|
encrypted: false,
|
||||||
|
@ -320,6 +340,15 @@ impl Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle a room.message event and update the `MessageQueue` if necessary.
|
||||||
|
///
|
||||||
|
/// Returns true if `MessageQueue` was added to.
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
|
||||||
|
pub fn handle_message(&mut self, event: &MessageEvent) -> bool {
|
||||||
|
self.messages.push(event.clone())
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -396,15 +425,17 @@ impl Room {
|
||||||
pub fn receive_timeline_event(&mut self, event: &RoomEvent) -> bool {
|
pub fn receive_timeline_event(&mut self, event: &RoomEvent) -> bool {
|
||||||
match event {
|
match event {
|
||||||
// update to the current members of the room
|
// update to the current members of the room
|
||||||
RoomEvent::RoomMember(m) => self.handle_membership(m),
|
RoomEvent::RoomMember(member) => self.handle_membership(member),
|
||||||
// finds all events related to the name of the room for later use
|
// finds all events related to the name of the room for later use
|
||||||
RoomEvent::RoomName(n) => self.handle_room_name(n),
|
RoomEvent::RoomName(name) => self.handle_room_name(name),
|
||||||
RoomEvent::RoomCanonicalAlias(ca) => self.handle_canonical(ca),
|
RoomEvent::RoomCanonicalAlias(c_alias) => self.handle_canonical(c_alias),
|
||||||
RoomEvent::RoomAliases(a) => self.handle_room_aliases(a),
|
RoomEvent::RoomAliases(alias) => self.handle_room_aliases(alias),
|
||||||
// power levels of the room members
|
// power levels of the room members
|
||||||
RoomEvent::RoomPowerLevels(p) => self.handle_power_level(p),
|
RoomEvent::RoomPowerLevels(power) => self.handle_power_level(power),
|
||||||
RoomEvent::RoomTombstone(t) => self.handle_tombstone(t),
|
RoomEvent::RoomTombstone(tomb) => self.handle_tombstone(tomb),
|
||||||
RoomEvent::RoomEncryption(e) => self.handle_encryption_event(e),
|
RoomEvent::RoomEncryption(encrypt) => self.handle_encryption_event(encrypt),
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
RoomEvent::RoomMessage(msg) => self.handle_message(msg),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,13 +449,16 @@ impl Room {
|
||||||
/// * `event` - The event of the room.
|
/// * `event` - The event of the room.
|
||||||
pub fn receive_state_event(&mut self, event: &StateEvent) -> bool {
|
pub fn receive_state_event(&mut self, event: &StateEvent) -> bool {
|
||||||
match event {
|
match event {
|
||||||
StateEvent::RoomMember(m) => self.handle_membership(m),
|
// update to the current members of the room
|
||||||
StateEvent::RoomName(n) => self.handle_room_name(n),
|
StateEvent::RoomMember(member) => self.handle_membership(member),
|
||||||
StateEvent::RoomCanonicalAlias(ca) => self.handle_canonical(ca),
|
// finds all events related to the name of the room for later use
|
||||||
StateEvent::RoomAliases(a) => self.handle_room_aliases(a),
|
StateEvent::RoomName(name) => self.handle_room_name(name),
|
||||||
StateEvent::RoomPowerLevels(p) => self.handle_power_level(p),
|
StateEvent::RoomCanonicalAlias(c_alias) => self.handle_canonical(c_alias),
|
||||||
StateEvent::RoomTombstone(t) => self.handle_tombstone(t),
|
StateEvent::RoomAliases(alias) => self.handle_room_aliases(alias),
|
||||||
StateEvent::RoomEncryption(e) => self.handle_encryption_event(e),
|
// power levels of the room members
|
||||||
|
StateEvent::RoomPowerLevels(power) => self.handle_power_level(power),
|
||||||
|
StateEvent::RoomTombstone(tomb) => self.handle_tombstone(tomb),
|
||||||
|
StateEvent::RoomEncryption(encrypt) => self.handle_encryption_event(encrypt),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ use serde::{Deserialize, Serialize};
|
||||||
// Notes: if Alice invites Bob into a room we will get an event with the sender as Alice and the state key as Bob.
|
// Notes: if Alice invites Bob into a room we will get an event with the sender as Alice and the state key as Bob.
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(Clone))]
|
||||||
/// A Matrix room member.
|
/// A Matrix room member.
|
||||||
///
|
///
|
||||||
pub struct RoomMember {
|
pub struct RoomMember {
|
||||||
|
|
|
@ -106,6 +106,8 @@ mod test {
|
||||||
|
|
||||||
let mut joined_rooms = HashMap::new();
|
let mut joined_rooms = HashMap::new();
|
||||||
joined_rooms.insert(id, room);
|
joined_rooms.insert(id, room);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "messages"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r#"{
|
r#"{
|
||||||
"!roomid:example.com": {
|
"!roomid:example.com": {
|
||||||
|
@ -128,6 +130,34 @@ mod test {
|
||||||
"unread_notifications": null,
|
"unread_notifications": null,
|
||||||
"tombstone": null
|
"tombstone": null
|
||||||
}
|
}
|
||||||
|
}"#,
|
||||||
|
serde_json::to_string_pretty(&joined_rooms).unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "messages")]
|
||||||
|
assert_eq!(
|
||||||
|
r#"{
|
||||||
|
"!roomid:example.com": {
|
||||||
|
"room_id": "!roomid:example.com",
|
||||||
|
"room_name": {
|
||||||
|
"name": null,
|
||||||
|
"canonical_alias": null,
|
||||||
|
"aliases": [],
|
||||||
|
"heroes": [],
|
||||||
|
"joined_member_count": null,
|
||||||
|
"invited_member_count": null
|
||||||
|
},
|
||||||
|
"own_user_id": "@example:example.com",
|
||||||
|
"creator": null,
|
||||||
|
"members": {},
|
||||||
|
"messages": [],
|
||||||
|
"typing_users": [],
|
||||||
|
"power_levels": null,
|
||||||
|
"encrypted": false,
|
||||||
|
"unread_highlight": null,
|
||||||
|
"unread_notifications": null,
|
||||||
|
"tombstone": null
|
||||||
|
}
|
||||||
}"#,
|
}"#,
|
||||||
serde_json::to_string_pretty(&joined_rooms).unwrap()
|
serde_json::to_string_pretty(&joined_rooms).unwrap()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue