✨ Add events shared by Matrix client and Requester
This commit is contained in:
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user