From ef41c0bd485cda4ffd82d5119c91f10c9efd86fa Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 10 May 2024 22:18:45 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20events=20shared=20by=20Matrix?= =?UTF-8?q?=20client=20and=20Requester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../messaging/matrix/account_event.rs | 51 ++++++++++++++++ src/infrastructure/messaging/matrix/mod.rs | 2 + .../messaging/matrix/room_event.rs | 58 +++++++++++++++++++ src/utils.rs | 1 + 4 files changed, 112 insertions(+) create mode 100644 src/infrastructure/messaging/matrix/account_event.rs create mode 100644 src/infrastructure/messaging/matrix/room_event.rs diff --git a/src/infrastructure/messaging/matrix/account_event.rs b/src/infrastructure/messaging/matrix/account_event.rs new file mode 100644 index 0000000..fecddf4 --- /dev/null +++ b/src/infrastructure/messaging/matrix/account_event.rs @@ -0,0 +1,51 @@ +use std::fmt::{Debug, Formatter}; + +use matrix_sdk::{ruma::OwnedRoomId, RoomState}; + +use super::room_event::RoomEventsReceiver; +use crate::{domain::model::space::SpaceId, utils::Sender}; + +#[derive(Clone)] +pub enum AccountEvent { + NewRoom( + OwnedRoomId, + Vec, + Option, + Option, + Option, + RoomState, + RoomEventsReceiver, + Sender, + ), + + NewSpace( + OwnedRoomId, + Option, + Option, + RoomEventsReceiver, + Sender, + ), +} + +impl Debug for AccountEvent { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Self::NewRoom(id, spaces, name, topic, is_direct, state, _events_receiver, _sender) => { + f.debug_tuple("AccountEvent::NewRoom") + .field(id) + .field(spaces) + .field(name) + .field(topic) + .field(is_direct) + .field(state) + .finish() + } + Self::NewSpace(id, name, topic, _events_receiver, _sender) => f + .debug_tuple("AccountEvent::NewSpace") + .field(id) + .field(name) + .field(topic) + .finish(), + } + } +} diff --git a/src/infrastructure/messaging/matrix/mod.rs b/src/infrastructure/messaging/matrix/mod.rs index e0e9b7d..0856f53 100644 --- a/src/infrastructure/messaging/matrix/mod.rs +++ b/src/infrastructure/messaging/matrix/mod.rs @@ -1,3 +1,5 @@ +pub(crate) mod account_event; pub(crate) mod client; pub(crate) mod requester; +pub(crate) mod room_event; pub(crate) mod worker_tasks; diff --git a/src/infrastructure/messaging/matrix/room_event.rs b/src/infrastructure/messaging/matrix/room_event.rs new file mode 100644 index 0000000..ca6690e --- /dev/null +++ b/src/infrastructure/messaging/matrix/room_event.rs @@ -0,0 +1,58 @@ +use std::fmt::{Debug, Formatter}; + +use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId}; +use tokio::sync::broadcast::Receiver; + +#[derive(Clone)] +pub enum RoomEvent { + Invitation(), + + #[allow(dead_code)] + Membership(OwnedUserId, bool), + + NewTopic(Option), + NewName(Option), + NewChild(OwnedRoomId), +} + +impl Debug for RoomEvent { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { + match self { + Self::Invitation() => f + .debug_tuple("RoomEvent::Invitation") + .field(&format_args!("_")) + .finish(), + Self::Membership(user_id, is_account_user) => f + .debug_tuple("RoomEvent::Membership") + .field(user_id) + .field(is_account_user) + .finish(), + Self::NewTopic(topic) => f.debug_tuple("RoomEvent::NewTopic").field(topic).finish(), + Self::NewName(name) => f.debug_tuple("RoomEvent::NewName").field(name).finish(), + Self::NewChild(room_id) => f + .debug_tuple("SpaceEvent::NewChild") + .field(room_id) + .finish(), + } + } +} + +pub struct RoomEventsReceiver(Receiver); + +impl Clone for RoomEventsReceiver { + fn clone(&self) -> Self { + Self(self.0.resubscribe()) + } +} + +impl RoomEventsReceiver { + pub fn new(inner: Receiver) -> Self { + Self(inner) + } +} + +impl From for Receiver { + fn from(val: RoomEventsReceiver) -> Self { + val.0 + } +} diff --git a/src/utils.rs b/src/utils.rs index 64baf06..c612e1f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,6 +8,7 @@ impl Receiver { } } +#[derive(Clone)] pub struct Sender(_Sender); // TODO: Handle error