✨ Add events shared by Matrix client and Requester
This commit is contained in:
51
src/infrastructure/messaging/matrix/account_event.rs
Normal file
51
src/infrastructure/messaging/matrix/account_event.rs
Normal file
@@ -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<SpaceId>,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
Option<bool>,
|
||||||
|
RoomState,
|
||||||
|
RoomEventsReceiver,
|
||||||
|
Sender<bool>,
|
||||||
|
),
|
||||||
|
|
||||||
|
NewSpace(
|
||||||
|
OwnedRoomId,
|
||||||
|
Option<String>,
|
||||||
|
Option<String>,
|
||||||
|
RoomEventsReceiver,
|
||||||
|
Sender<bool>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +1,5 @@
|
|||||||
|
pub(crate) mod account_event;
|
||||||
pub(crate) mod client;
|
pub(crate) mod client;
|
||||||
pub(crate) mod requester;
|
pub(crate) mod requester;
|
||||||
|
pub(crate) mod room_event;
|
||||||
pub(crate) mod worker_tasks;
|
pub(crate) mod worker_tasks;
|
||||||
|
58
src/infrastructure/messaging/matrix/room_event.rs
Normal file
58
src/infrastructure/messaging/matrix/room_event.rs
Normal file
@@ -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<String>),
|
||||||
|
NewName(Option<String>),
|
||||||
|
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<RoomEvent>);
|
||||||
|
|
||||||
|
impl Clone for RoomEventsReceiver {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self(self.0.resubscribe())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomEventsReceiver {
|
||||||
|
pub fn new(inner: Receiver<RoomEvent>) -> Self {
|
||||||
|
Self(inner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RoomEventsReceiver> for Receiver<RoomEvent> {
|
||||||
|
fn from(val: RoomEventsReceiver) -> Self {
|
||||||
|
val.0
|
||||||
|
}
|
||||||
|
}
|
@@ -8,6 +8,7 @@ impl<T> Receiver<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Sender<T>(_Sender<T>);
|
pub struct Sender<T>(_Sender<T>);
|
||||||
|
|
||||||
// TODO: Handle error
|
// TODO: Handle error
|
||||||
|
Reference in New Issue
Block a user