2 extern crate strum_macros;
4 use crate::chat_server::ChatServer;
6 use background_jobs::QueueHandle;
7 use lemmy_db_schema::{source::secret::Secret, DbPool};
8 use lemmy_utils::{settings::structs::Settings, LemmyError};
9 use reqwest_middleware::ClientWithMiddleware;
18 pub struct LemmyContext {
20 chat_server: Addr<ChatServer>,
21 client: ClientWithMiddleware,
22 activity_queue: QueueHandle,
30 chat_server: Addr<ChatServer>,
31 client: ClientWithMiddleware,
32 activity_queue: QueueHandle,
45 pub fn pool(&self) -> &DbPool {
48 pub fn chat_server(&self) -> &Addr<ChatServer> {
51 pub fn client(&self) -> &ClientWithMiddleware {
54 pub fn activity_queue(&self) -> &QueueHandle {
57 pub fn settings(&self) -> Settings {
58 // TODO hacky solution to be able to hotload the settings.
61 pub fn secret(&self) -> &Secret {
66 impl Clone for LemmyContext {
67 fn clone(&self) -> Self {
69 pool: self.pool.clone(),
70 chat_server: self.chat_server.clone(),
71 client: self.client.clone(),
72 activity_queue: self.activity_queue.clone(),
73 settings: self.settings.clone(),
74 secret: self.secret.clone(),
80 struct WebsocketResponse<T> {
85 pub fn serialize_websocket_message<OP, Response>(
88 ) -> Result<String, LemmyError>
93 let response = WebsocketResponse {
97 Ok(serde_json::to_string(&response)?)
100 #[derive(EnumString, Display, Debug, Clone)]
101 pub enum UserOperation {
108 ResolveCommentReport,
124 MarkPersonMentionAsRead,
129 GetUnreadRegistrationApplicationCount,
130 ListRegistrationApplications,
131 ApproveRegistrationApplication,
142 MarkPrivateMessageAsRead,
155 #[derive(EnumString, Display, Debug, Clone)]
156 pub enum UserOperationCrud {
187 CreatePrivateMessage,
190 DeletePrivateMessage,
193 pub trait OperationType {}
195 impl OperationType for UserOperationCrud {}
197 impl OperationType for UserOperation {}