Skip to content

Commit

Permalink
refactor: Rename RoomInternals to Room and move Arc inside Room
Browse files Browse the repository at this point in the history
  • Loading branch information
nesium committed Jan 18, 2024
1 parent 3146d4d commit 49dc8cb
Show file tree
Hide file tree
Showing 19 changed files with 356 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Copyright: 2023, Marc Bauer <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::sync::{Arc, OnceLock, Weak};
use std::sync::{OnceLock, Weak};

use crate::app::deps::DynRoomFactory;
use crate::app::event_handlers::ClientEventDispatcherTrait;
use crate::client::ClientInner;
use crate::domain::rooms::models::RoomInternals;
use crate::domain::rooms::models::Room;
use crate::domain::shared::models::RoomType;
use crate::{ClientDelegate, ClientEvent, ClientRoomEventType};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl ClientEventDispatcherTrait for ClientEventDispatcher {
delegate.handle_event(client_inner.into(), event)
}

fn dispatch_room_event(&self, room: Arc<RoomInternals>, event: ClientRoomEventType) {
fn dispatch_room_event(&self, room: Room, event: ClientRoomEventType) {
// We're not sending events for rooms that are still pending…
if room.r#type == RoomType::Unknown {
return;
Expand Down
6 changes: 2 additions & 4 deletions crates/prose-core-client/src/app/event_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Copyright: 2023, Marc Bauer <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;

Expand All @@ -20,7 +18,7 @@ pub use rooms_event_handler::RoomsEventHandler;
pub use server_event::*;
pub use user_state_event_handler::UserStateEventHandler;

use crate::domain::rooms::models::RoomInternals;
use crate::domain::rooms::models::Room;
use crate::{ClientEvent, ClientRoomEventType};

mod bookmarks_event_handler;
Expand Down Expand Up @@ -49,5 +47,5 @@ pub trait ServerEventHandler: SendUnlessWasm + SyncUnlessWasm {
#[cfg_attr(feature = "test", mockall::automock)]
pub trait ClientEventDispatcherTrait: SendUnlessWasm + SyncUnlessWasm {
fn dispatch_event(&self, event: ClientEvent);
fn dispatch_room_event(&self, room: Arc<RoomInternals>, event: ClientRoomEventType);
fn dispatch_room_event(&self, room: Room, event: ClientRoomEventType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Copyright: 2023, Marc Bauer <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;
use tracing::info;
Expand All @@ -23,7 +21,7 @@ use crate::app::event_handlers::{
};
use crate::client_event::ClientRoomEventType;
use crate::domain::messaging::models::{MessageLike, MessageLikePayload};
use crate::domain::rooms::models::RoomInternals;
use crate::domain::rooms::models::Room;
use crate::domain::rooms::services::{
CreateOrEnterRoomRequest, JoinRoomBehavior, JoinRoomFailureBehavior, JoinRoomRedirectBehavior,
};
Expand Down Expand Up @@ -73,7 +71,7 @@ impl ServerEventHandler for RoomsEventHandler {
}

impl RoomsEventHandler {
fn get_room(&self, jid: &RoomId) -> Result<Arc<RoomInternals>> {
fn get_room(&self, jid: &RoomId) -> Result<Room> {
self.connected_rooms_repo
.get(jid)
.ok_or(anyhow::format_err!("Could not find room with jid {}", jid))
Expand Down
4 changes: 2 additions & 2 deletions crates/prose-core-client/src/app/services/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::app::deps::{
DynUserProfileRepository,
};
use crate::domain::messaging::models::{Emoji, Message, MessageId, MessageLike};
use crate::domain::rooms::models::{RoomAffiliation, RoomInternals, RoomSpec};
use crate::domain::rooms::models::{Room as DomainRoom, RoomAffiliation, RoomSpec};
use crate::domain::shared::models::{ParticipantId, ParticipantInfo, RoomId};
use crate::dtos::{Message as MessageDTO, MessageSender, RoomState, UserBasicInfo, UserId};
use crate::{ClientEvent, ClientRoomEventType};
Expand Down Expand Up @@ -55,7 +55,7 @@ impl HasMutableName for PublicChannel {}
impl HasMutableName for Generic {}

pub struct RoomInner {
pub(crate) data: Arc<RoomInternals>,
pub(crate) data: DomainRoom,

pub(crate) ctx: DynAppContext,
pub(crate) attributes_service: DynRoomAttributesService,
Expand Down
6 changes: 2 additions & 4 deletions crates/prose-core-client/src/app/services/sidebar_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Copyright: 2023, Marc Bauer <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::sync::Arc;

use anyhow::Result;

use prose_proc_macros::InjectDependencies;
Expand All @@ -13,7 +11,7 @@ use crate::app::deps::{
DynConnectedRoomsReadOnlyRepository, DynDraftsRepository, DynRoomFactory,
DynSidebarDomainService,
};
use crate::domain::rooms::models::{RoomInternals, RoomSidebarState};
use crate::domain::rooms::models::{Room, RoomSidebarState};
use crate::domain::shared::models::{RoomId, RoomType};
use crate::dtos::SidebarItem as SidebarItemDTO;

Expand All @@ -31,7 +29,7 @@ pub struct SidebarService {

impl SidebarService {
pub async fn sidebar_items(&self) -> Vec<SidebarItemDTO> {
let rooms: Vec<Arc<RoomInternals>> = self.connected_rooms_repo.get_all();
let rooms: Vec<Room> = self.connected_rooms_repo.get_all();
let mut item_dtos = vec![];

for room in rooms {
Expand Down
4 changes: 2 additions & 2 deletions crates/prose-core-client/src/domain/rooms/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
pub use compose_state::ComposeState;
pub use participant_list::{Participant, ParticipantList, RegisteredMember};
pub use public_room_info::PublicRoomInfo;
pub use room::{Room, RoomInfo, RoomSidebarState, RoomState};
pub use room_affiliation::RoomAffiliation;
pub use room_error::RoomError;
pub use room_internals::{RoomInfo, RoomInternals, RoomSidebarState, RoomState};
pub use room_session_info::{RoomConfig, RoomSessionInfo, RoomSessionMember};
pub use room_spec::RoomSpec;

mod compose_state;
pub mod constants;
mod participant_list;
mod public_room_info;
mod room;
mod room_affiliation;
mod room_error;
mod room_internals;
mod room_session_info;
mod room_spec;
Loading

0 comments on commit 49dc8cb

Please sign in to comment.