🔊 Trace events from Matrix client callbacks to domain methods

This commit is contained in:
2024-05-21 12:22:04 +02:00
parent b5da0ee992
commit cd6506fb03
11 changed files with 405 additions and 163 deletions

View File

@@ -1,7 +1,7 @@
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use async_trait::async_trait;
use tracing::error;
use tracing::{error, instrument, trace};
use super::{
common::PresenceState,
@@ -95,7 +95,10 @@ impl Account {
#[async_trait(?Send)]
impl AccountMessagingConsumerInterface for Account {
#[instrument(name = "Account", skip_all)]
async fn on_new_room(&self, room: Rc<Room>) -> Rc<dyn RoomMessagingConsumerInterface> {
trace!("on_new_room");
let room_id = room.id().clone();
self.by_id_rooms
@@ -111,7 +114,10 @@ impl AccountMessagingConsumerInterface for Account {
room
}
#[instrument(name = "Account", skip_all)]
async fn on_new_space(&self, space: Rc<Space>) -> Rc<dyn SpaceMessagingConsumerInterface> {
trace!("on_new_space");
let space_id = space.id().clone();
self.by_id_spaces

View File

@@ -9,7 +9,7 @@ use async_trait::async_trait;
use futures::future::{join, join_all};
use matrix_sdk::ruma::OwnedRoomId;
use matrix_sdk::RoomState as MatrixRoomState;
use tracing::{debug, error, trace};
use tracing::{debug, debug_span, error, instrument, trace};
use super::{
common::{Avatar, UserId},
@@ -18,7 +18,6 @@ use super::{
space::SpaceId,
store_interface::{RoomStoreConsumerInterface, RoomStoreProviderInterface},
};
use crate::infrastructure::services::mozaik_builder::create_mozaik;
pub type RoomId = OwnedRoomId;
@@ -150,6 +149,7 @@ impl Room {
self.state.map(|state| state == MatrixRoomState::Invited)
}
#[instrument(name = "Room", skip_all)]
fn add_invitation(&self, invitation: Invitation) {
self.members.borrow_mut().remove(&invitation.invitee_id);
@@ -240,17 +240,44 @@ impl Room {
#[async_trait(?Send)]
impl RoomMessagingConsumerInterface for Room {
#[instrument(name = "Room", skip_all)]
async fn on_invitation(&self, invitation: Invitation) {
trace!("on_invitation");
let sender_id = invitation.sender_id.clone();
self.add_invitation(invitation);
if self.is_direct.unwrap_or(false) {
debug!("1to1 conversation, using the {} avatar", &sender_id);
if let Ok(avatar) = self.gen_room_avatar_with_members().await {
debug!("Avatar successfully generated");
self.avatar.borrow_mut().clone_from(&avatar);
if let Some(store) = self.store.borrow().as_ref() {
store.on_new_avatar(avatar);
}
}
}
}
#[instrument(name = "Room", skip_all)]
async fn on_membership(&self, member: RoomMember) {
trace!("Room::on_membership({:?})", member);
trace!("on_membership");
self.add_member(member);
}
async fn on_new_topic(&self, topic: Option<String>) {
trace!("Room::on_new_topic({:?})", topic);
#[instrument(name = "Room", skip_all)]
async fn on_new_topic(&self, _topic: Option<String>) {
trace!("on_new_topic");
}
async fn on_new_name(&self, name: Option<String>) {
trace!("Room::on_new_name({:?})", name);
#[instrument(name = "Room", skip_all)]
async fn on_new_name(&self, _name: Option<String>) {
trace!("on_new_name");
}
#[instrument(name = "Room", skip_all)]
async fn on_new_avatar(&self, avatar: Option<Avatar>) {
trace!("on_new_avatar");
}
}

View File

@@ -2,7 +2,7 @@ use std::{cell::RefCell, collections::HashSet, rc::Rc};
use async_trait::async_trait;
use matrix_sdk::ruma::OwnedRoomId;
use tracing::error;
use tracing::{instrument, trace};
use super::{
common::Avatar,
@@ -72,16 +72,21 @@ impl Space {
#[async_trait(?Send)]
impl SpaceMessagingConsumerInterface for Space {
#[instrument(name = "Space", skip_all)]
async fn on_child(&self, room_id: RoomId) {
error!("Space::on_child({room_id})");
trace!("on_child");
self.children.borrow_mut().insert(room_id);
}
#[instrument(name = "Space", skip_all)]
async fn on_new_topic(&self, topic: Option<String>) {
error!("Space::on_new_topic({:?})", topic);
trace!("on_new_topic");
*self.topic.borrow_mut() = topic;
}
#[instrument(name = "Space", skip_all)]
async fn on_new_name(&self, name: Option<String>) {
error!("Space::on_new_name({:?})", name);
trace!("on_new_name");
self.name.borrow_mut().clone_from(&name);
if let Some(store) = self.store.borrow().as_ref() {