Add events shared by Matrix client and Requester

This commit is contained in:
2024-05-10 22:18:45 +02:00
parent e3a6ec9858
commit ef41c0bd48
4 changed files with 112 additions and 0 deletions

View 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
}
}