2 extern crate strum_macros;
4 use crate::chat_server::ChatServer;
6 use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
7 use lemmy_utils::{error::LemmyError, settings::structs::Settings};
8 use reqwest_middleware::ClientWithMiddleware;
17 pub struct LemmyContext {
19 chat_server: Addr<ChatServer>,
20 client: ClientWithMiddleware,
28 chat_server: Addr<ChatServer>,
29 client: ClientWithMiddleware,
41 pub fn pool(&self) -> &DbPool {
44 pub fn chat_server(&self) -> &Addr<ChatServer> {
47 pub fn client(&self) -> &ClientWithMiddleware {
50 pub fn settings(&self) -> Settings {
51 // TODO hacky solution to be able to hotload the settings.
54 pub fn secret(&self) -> &Secret {
59 impl Clone for LemmyContext {
60 fn clone(&self) -> Self {
62 pool: self.pool.clone(),
63 chat_server: self.chat_server.clone(),
64 client: self.client.clone(),
65 settings: self.settings.clone(),
66 secret: self.secret.clone(),
72 struct WebsocketResponse<T> {
77 pub fn serialize_websocket_message<OP, Response>(
80 ) -> Result<String, LemmyError>
85 let response = WebsocketResponse {
89 Ok(serde_json::to_string(&response)?)
92 #[derive(EnumString, Display, Debug, Clone)]
93 pub enum UserOperation {
100 ResolveCommentReport,
116 MarkPersonMentionAsRead,
121 GetUnreadRegistrationApplicationCount,
122 ListRegistrationApplications,
123 ApproveRegistrationApplication,
134 MarkPrivateMessageAsRead,
147 #[derive(EnumString, Display, Debug, Clone)]
148 pub enum UserOperationCrud {
179 CreatePrivateMessage,
182 DeletePrivateMessage,
185 pub trait OperationType {}
187 impl OperationType for UserOperationCrud {}
189 impl OperationType for UserOperation {}