Compare commits

...

2 commits

14 changed files with 213 additions and 136 deletions

28
server/Cargo.lock generated vendored
View file

@ -1798,7 +1798,10 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
name = "lemmy_api_structs" name = "lemmy_api_structs"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-web",
"async-trait",
"lemmy_db", "lemmy_db",
"lemmy_utils",
"serde 1.0.114", "serde 1.0.114",
"thiserror", "thiserror",
] ]
@ -1868,6 +1871,7 @@ dependencies = [
"lemmy_db", "lemmy_db",
"lemmy_rate_limit", "lemmy_rate_limit",
"lemmy_utils", "lemmy_utils",
"lemmy_websocket",
"log", "log",
"openssl", "openssl",
"percent-encoding", "percent-encoding",
@ -1907,6 +1911,30 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "lemmy_websocket"
version = "0.1.0"
dependencies = [
"actix",
"actix-web",
"anyhow",
"async-trait",
"background-jobs",
"chrono",
"diesel",
"lemmy_api_structs",
"lemmy_db",
"lemmy_rate_limit",
"lemmy_utils",
"log",
"rand 0.7.3",
"reqwest",
"serde 1.0.114",
"serde_json",
"strum",
"strum_macros",
]
[[package]] [[package]]
name = "lettre" name = "lettre"
version = "0.9.3" version = "0.9.3"

2
server/Cargo.toml vendored
View file

@ -11,6 +11,7 @@ members = [
"lemmy_utils", "lemmy_utils",
"lemmy_db", "lemmy_db",
"lemmy_api_structs", "lemmy_api_structs",
"lemmy_websocket",
] ]
[dependencies] [dependencies]
@ -18,6 +19,7 @@ lemmy_utils = { path = "./lemmy_utils" }
lemmy_db = { path = "./lemmy_db" } lemmy_db = { path = "./lemmy_db" }
lemmy_api_structs = { path = "./lemmy_api_structs" } lemmy_api_structs = { path = "./lemmy_api_structs" }
lemmy_rate_limit = { path = "./lemmy_rate_limit" } lemmy_rate_limit = { path = "./lemmy_rate_limit" }
lemmy_websocket = { path = "./lemmy_websocket" }
diesel = "1.4.4" diesel = "1.4.4"
diesel_migrations = "1.4.0" diesel_migrations = "1.4.0"
dotenv = "0.15.0" dotenv = "0.15.0"

View file

@ -6,5 +6,8 @@ edition = "2018"
[dependencies] [dependencies]
lemmy_db = { path = "../lemmy_db" } lemmy_db = { path = "../lemmy_db" }
lemmy_utils = { path = "../lemmy_utils" }
serde = { version = "1.0.105", features = ["derive"] } serde = { version = "1.0.105", features = ["derive"] }
thiserror = "1.0.20" thiserror = "1.0.20"
async-trait = "0.1.36"
actix-web = "3.0.0-alpha.3"

View file

@ -1,5 +1,6 @@
pub extern crate serde; pub extern crate serde;
pub extern crate thiserror; pub extern crate thiserror;
pub extern crate actix_web;
pub mod comment; pub mod comment;
pub mod community; pub mod community;

View file

@ -40,6 +40,8 @@ pub mod user_mention;
pub mod user_mention_view; pub mod user_mention_view;
pub mod user_view; pub mod user_view;
pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
pub trait Crud<T> { pub trait Crud<T> {
fn create(conn: &PgConnection, form: &T) -> Result<Self, Error> fn create(conn: &PgConnection, form: &T) -> Result<Self, Error>
where where

25
server/lemmy_websocket/Cargo.toml vendored Normal file
View file

@ -0,0 +1,25 @@
[package]
name = "lemmy_websocket"
version = "0.1.0"
authors = ["Felix Ableitner <me@nutomic.com>"]
edition = "2018"
[dependencies]
lemmy_api_structs = { path = "../lemmy_api_structs" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
lemmy_utils = { path = "../lemmy_utils" }
lemmy_db = { path = "../lemmy_db" }
log = "0.4.0"
actix = "0.10.0-alpha.2"
actix-web = { version = "3.0.0-alpha.3", features = ["rustls"] }
anyhow = "1.0.32"
diesel = "1.4.4"
rand = "0.7.3"
serde = { version = "1.0.105", features = ["derive"] }
serde_json = { version = "1.0.52", features = ["preserve_order"]}
chrono = { version = "0.4.7", features = ["serde"] }
reqwest = { version = "0.10", features = ["json"] }
strum = "0.18.0"
strum_macros = "0.18.0"
async-trait = "0.1.36"
background-jobs = " 0.8.0-alpha.2"

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
websocket::{ {
handlers::{do_user_operation, to_json_string, Args}, handlers::{do_user_operation, to_json_string, Args},
messages::*, messages::*,
UserOperation, UserOperation,

View file

@ -1,12 +1,8 @@
use crate::{ use crate::{ {
api::Perform,
websocket::{
chat_server::{ChatServer, SessionInfo}, chat_server::{ChatServer, SessionInfo},
messages::*, messages::*,
UserOperation, UserOperation,
}, }, LemmyContext, Perform};
LemmyContext,
};
use actix::{Actor, Context, Handler, ResponseFuture}; use actix::{Actor, Context, Handler, ResponseFuture};
use actix_web::web; use actix_web::web;
use lemmy_db::naive_now; use lemmy_db::naive_now;

View file

@ -0,0 +1,144 @@
pub extern crate actix;
pub extern crate actix_web;
pub extern crate anyhow;
pub extern crate diesel;
pub extern crate rand;
pub extern crate serde;
pub extern crate serde_json;
pub extern crate chrono;
pub extern crate reqwest;
pub extern crate log;
#[macro_use]
pub extern crate strum_macros;
pub extern crate background_jobs;
use actix::Addr;
use crate::chat_server::ChatServer;
use reqwest::Client;
use lemmy_db::DbPool;
use background_jobs::QueueHandle;
use actix_web::web::Data;
use lemmy_utils::{ConnectionId, LemmyError};
pub mod chat_server;
pub mod handlers;
pub mod messages;
#[derive(EnumString, ToString, Debug, Clone)]
pub enum UserOperation {
Login,
Register,
GetCaptcha,
CreateCommunity,
CreatePost,
ListCommunities,
ListCategories,
GetPost,
GetCommunity,
CreateComment,
EditComment,
DeleteComment,
RemoveComment,
MarkCommentAsRead,
SaveComment,
CreateCommentLike,
GetPosts,
CreatePostLike,
EditPost,
DeletePost,
RemovePost,
LockPost,
StickyPost,
SavePost,
EditCommunity,
DeleteCommunity,
RemoveCommunity,
FollowCommunity,
GetFollowedCommunities,
GetUserDetails,
GetReplies,
GetUserMentions,
MarkUserMentionAsRead,
GetModlog,
BanFromCommunity,
AddModToCommunity,
CreateSite,
EditSite,
GetSite,
AddAdmin,
BanUser,
Search,
MarkAllAsRead,
SaveUserSettings,
TransferCommunity,
TransferSite,
DeleteAccount,
PasswordReset,
PasswordChange,
CreatePrivateMessage,
EditPrivateMessage,
DeletePrivateMessage,
MarkPrivateMessageAsRead,
GetPrivateMessages,
UserJoin,
GetComments,
GetSiteConfig,
SaveSiteConfig,
}
pub struct LemmyContext {
pub pool: DbPool,
pub chat_server: Addr<ChatServer>,
pub client: Client,
pub activity_queue: QueueHandle,
}
impl LemmyContext {
pub fn create(
pool: DbPool,
chat_server: Addr<ChatServer>,
client: Client,
activity_queue: QueueHandle,
) -> LemmyContext {
LemmyContext {
pool,
chat_server,
client,
activity_queue,
}
}
pub fn pool(&self) -> &DbPool {
&self.pool
}
pub fn chat_server(&self) -> &Addr<ChatServer> {
&self.chat_server
}
pub fn client(&self) -> &Client {
&self.client
}
pub fn activity_queue(&self) -> &QueueHandle {
&self.activity_queue
}
}
impl Clone for LemmyContext {
fn clone(&self) -> Self {
LemmyContext {
pool: self.pool.clone(),
chat_server: self.chat_server.clone(),
client: self.client.clone(),
activity_queue: self.activity_queue.clone(),
}
}
}
#[async_trait::async_trait(?Send)]
pub trait Perform {
type Response: serde::ser::Serialize + Send;
async fn perform(
&self,
context: &Data<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError>;
}

View file

@ -1,4 +1,4 @@
use crate::websocket::UserOperation; use crate::UserOperation;
use actix::{prelude::*, Recipient}; use actix::{prelude::*, Recipient};
use lemmy_api_structs::{comment::CommentResponse, post::PostResponse}; use lemmy_api_structs::{comment::CommentResponse, post::PostResponse};
use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId}; use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId};

View file

View file

@ -17,17 +17,6 @@ pub mod post;
pub mod site; pub mod site;
pub mod user; pub mod user;
#[async_trait::async_trait(?Send)]
pub trait Perform {
type Response: serde::ser::Serialize + Send;
async fn perform(
&self,
context: &Data<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError>;
}
pub(in crate::api) async fn is_mod_or_admin( pub(in crate::api) async fn is_mod_or_admin(
pool: &DbPool, pool: &DbPool,
user_id: i32, user_id: i32,

View file

@ -43,54 +43,6 @@ use reqwest::Client;
use serde::Deserialize; use serde::Deserialize;
use std::process::Command; use std::process::Command;
pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
pub struct LemmyContext {
pub pool: DbPool,
pub chat_server: Addr<ChatServer>,
pub client: Client,
pub activity_queue: QueueHandle,
}
impl LemmyContext {
pub fn create(
pool: DbPool,
chat_server: Addr<ChatServer>,
client: Client,
activity_queue: QueueHandle,
) -> LemmyContext {
LemmyContext {
pool,
chat_server,
client,
activity_queue,
}
}
pub fn pool(&self) -> &DbPool {
&self.pool
}
pub fn chat_server(&self) -> &Addr<ChatServer> {
&self.chat_server
}
pub fn client(&self) -> &Client {
&self.client
}
pub fn activity_queue(&self) -> &QueueHandle {
&self.activity_queue
}
}
impl Clone for LemmyContext {
fn clone(&self) -> Self {
LemmyContext {
pool: self.pool.clone(),
chat_server: self.chat_server.clone(),
client: self.client.clone(),
activity_queue: self.activity_queue.clone(),
}
}
}
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct IframelyResponse { pub struct IframelyResponse {
title: Option<String>, title: Option<String>,

View file

@ -1,65 +0,0 @@
pub mod chat_server;
pub mod handlers;
pub mod messages;
#[derive(EnumString, ToString, Debug, Clone)]
pub enum UserOperation {
Login,
Register,
GetCaptcha,
CreateCommunity,
CreatePost,
ListCommunities,
ListCategories,
GetPost,
GetCommunity,
CreateComment,
EditComment,
DeleteComment,
RemoveComment,
MarkCommentAsRead,
SaveComment,
CreateCommentLike,
GetPosts,
CreatePostLike,
EditPost,
DeletePost,
RemovePost,
LockPost,
StickyPost,
SavePost,
EditCommunity,
DeleteCommunity,
RemoveCommunity,
FollowCommunity,
GetFollowedCommunities,
GetUserDetails,
GetReplies,
GetUserMentions,
MarkUserMentionAsRead,
GetModlog,
BanFromCommunity,
AddModToCommunity,
CreateSite,
EditSite,
GetSite,
AddAdmin,
BanUser,
Search,
MarkAllAsRead,
SaveUserSettings,
TransferCommunity,
TransferSite,
DeleteAccount,
PasswordReset,
PasswordChange,
CreatePrivateMessage,
EditPrivateMessage,
DeletePrivateMessage,
MarkPrivateMessageAsRead,
GetPrivateMessages,
UserJoin,
GetComments,
GetSiteConfig,
SaveSiteConfig,
}