72 lines
2.2 KiB
Rust
72 lines
2.2 KiB
Rust
use std::fmt::{Debug, Formatter};
|
|
|
|
use matrix_sdk::ruma::{OwnedMxcUri, OwnedRoomId, OwnedUserId};
|
|
use tokio::sync::broadcast::Receiver;
|
|
use tracing::Span;
|
|
|
|
use crate::domain::model::common::Avatar;
|
|
|
|
#[derive(Clone)]
|
|
pub enum RoomEvent {
|
|
Invitation(OwnedUserId, OwnedUserId, bool, Span),
|
|
Join(OwnedUserId, Option<String>, Option<OwnedMxcUri>, bool, Span),
|
|
|
|
NewTopic(Option<String>, Span),
|
|
NewName(Option<String>, Span),
|
|
NewAvatar(Option<Avatar>, Span),
|
|
NewChild(OwnedRoomId, Span),
|
|
}
|
|
|
|
impl Debug for RoomEvent {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
|
match self {
|
|
Self::Invitation(invitee_id, sender_id, is_account_user, _span) => f
|
|
.debug_tuple("RoomEvent::Invitation")
|
|
.field(invitee_id)
|
|
.field(sender_id)
|
|
.field(is_account_user)
|
|
.finish(),
|
|
Self::Join(user_id, user_name, avatar_url, is_account_user, _span) => f
|
|
.debug_tuple("RoomEvent::Join")
|
|
.field(user_id)
|
|
.field(user_name)
|
|
.field(avatar_url)
|
|
.field(is_account_user)
|
|
.finish(),
|
|
Self::NewTopic(topic, _span) => {
|
|
f.debug_tuple("RoomEvent::NewTopic").field(topic).finish()
|
|
}
|
|
Self::NewName(name, _span) => f.debug_tuple("RoomEvent::NewName").field(name).finish(),
|
|
Self::NewAvatar(avatar, _span) => f
|
|
// Self::NewAvatar(avatar) => f
|
|
.debug_tuple("RoomEvent::NewAvatar")
|
|
.field(&format!("is_some: {}", &avatar.is_some()))
|
|
.finish(),
|
|
Self::NewChild(room_id, _span) => 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
|
|
}
|
|
}
|