2 extern crate strum_macros;
4 use crate::chat_server::ChatServer;
6 use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
9 rate_limit::RateLimitCell,
10 settings::{structs::Settings, SETTINGS},
12 use reqwest_middleware::ClientWithMiddleware;
21 pub struct LemmyContext {
23 chat_server: Addr<ChatServer>,
24 client: ClientWithMiddleware,
27 rate_limit_cell: RateLimitCell,
33 chat_server: Addr<ChatServer>,
34 client: ClientWithMiddleware,
37 settings_updated_channel: RateLimitCell,
45 rate_limit_cell: settings_updated_channel,
48 pub fn pool(&self) -> &DbPool {
51 pub fn chat_server(&self) -> &Addr<ChatServer> {
54 pub fn client(&self) -> &ClientWithMiddleware {
57 pub fn settings(&self) -> &'static Settings {
60 pub fn secret(&self) -> &Secret {
63 pub fn settings_updated_channel(&self) -> &RateLimitCell {
68 impl Clone for LemmyContext {
69 fn clone(&self) -> Self {
71 pool: self.pool.clone(),
72 chat_server: self.chat_server.clone(),
73 client: self.client.clone(),
74 settings: self.settings.clone(),
75 secret: self.secret.clone(),
76 rate_limit_cell: self.rate_limit_cell.clone(),
82 struct WebsocketResponse<T> {
87 pub fn serialize_websocket_message<OP, Response>(
90 ) -> Result<String, LemmyError>
95 let response = WebsocketResponse {
99 Ok(serde_json::to_string(&response)?)
102 #[derive(EnumString, Display, Debug, Clone)]
103 pub enum UserOperation {
109 ResolveCommentReport,
125 MarkPersonMentionAsRead,
126 MarkCommentReplyAsRead,
131 GetUnreadRegistrationApplicationCount,
132 ListRegistrationApplications,
133 ApproveRegistrationApplication,
144 MarkPrivateMessageAsRead,
145 CreatePrivateMessageReport,
146 ResolvePrivateMessageReport,
147 ListPrivateMessageReports,
162 #[derive(EnumString, Display, Debug, Clone)]
163 pub enum UserOperationCrud {
194 CreatePrivateMessage,
197 DeletePrivateMessage,
200 pub trait OperationType {}
202 impl OperationType for UserOperationCrud {}
204 impl OperationType for UserOperation {}