-use crate::websocket::chat_server::ChatServer;
-use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
+use lemmy_db_schema::{
+ source::secret::Secret,
+ utils::{ActualDbPool, DbPool},
+};
use lemmy_utils::{
rate_limit::RateLimitCell,
settings::{structs::Settings, SETTINGS},
use reqwest_middleware::ClientWithMiddleware;
use std::sync::Arc;
+#[derive(Clone)]
pub struct LemmyContext {
- pool: DbPool,
- chat_server: Arc<ChatServer>,
- client: ClientWithMiddleware,
- settings: Settings,
- secret: Secret,
+ pool: ActualDbPool,
+ client: Arc<ClientWithMiddleware>,
+ secret: Arc<Secret>,
rate_limit_cell: RateLimitCell,
}
impl LemmyContext {
pub fn create(
- pool: DbPool,
- chat_server: Arc<ChatServer>,
+ pool: ActualDbPool,
client: ClientWithMiddleware,
- settings: Settings,
secret: Secret,
rate_limit_cell: RateLimitCell,
) -> LemmyContext {
LemmyContext {
pool,
- chat_server,
- client,
- settings,
- secret,
+ client: Arc::new(client),
+ secret: Arc::new(secret),
rate_limit_cell,
}
}
- pub fn pool(&self) -> &DbPool {
- &self.pool
+ pub fn pool(&self) -> DbPool<'_> {
+ DbPool::Pool(&self.pool)
}
- pub fn chat_server(&self) -> &Arc<ChatServer> {
- &self.chat_server
+ pub fn inner_pool(&self) -> &ActualDbPool {
+ &self.pool
}
pub fn client(&self) -> &ClientWithMiddleware {
&self.client
&self.rate_limit_cell
}
}
-
-impl Clone for LemmyContext {
- fn clone(&self) -> Self {
- LemmyContext {
- pool: self.pool.clone(),
- chat_server: self.chat_server.clone(),
- client: self.client.clone(),
- settings: self.settings.clone(),
- secret: self.secret.clone(),
- rate_limit_cell: self.rate_limit_cell.clone(),
- }
- }
-}