mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 22:01:19 +00:00
Move comment, post definitions into lemmy_db_schema
This commit is contained in:
parent
089d812dc8
commit
114f3cbfb5
58 changed files with 642 additions and 574 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -1718,6 +1718,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lemmy_apub",
|
"lemmy_apub",
|
||||||
"lemmy_db",
|
"lemmy_db",
|
||||||
|
"lemmy_db_schema",
|
||||||
"lemmy_rate_limit",
|
"lemmy_rate_limit",
|
||||||
"lemmy_structs",
|
"lemmy_structs",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
|
@ -1762,6 +1763,7 @@ dependencies = [
|
||||||
"itertools",
|
"itertools",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lemmy_db",
|
"lemmy_db",
|
||||||
|
"lemmy_db_schema",
|
||||||
"lemmy_structs",
|
"lemmy_structs",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
"lemmy_websocket",
|
||||||
|
@ -1805,7 +1807,12 @@ dependencies = [
|
||||||
name = "lemmy_db_schema"
|
name = "lemmy_db_schema"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
|
"log",
|
||||||
|
"serde 1.0.118",
|
||||||
|
"serde_json",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1868,6 +1875,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
"lemmy_db",
|
"lemmy_db",
|
||||||
|
"lemmy_db_schema",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"log",
|
"log",
|
||||||
"serde 1.0.118",
|
"serde 1.0.118",
|
||||||
|
@ -1909,6 +1917,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
"lemmy_db",
|
"lemmy_db",
|
||||||
|
"lemmy_db_schema",
|
||||||
"lemmy_rate_limit",
|
"lemmy_rate_limit",
|
||||||
"lemmy_structs",
|
"lemmy_structs",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
|
|
|
@ -12,6 +12,7 @@ path = "src/lib.rs"
|
||||||
lemmy_apub = { path = "../lemmy_apub" }
|
lemmy_apub = { path = "../lemmy_apub" }
|
||||||
lemmy_utils = { path = "../lemmy_utils" }
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
lemmy_db = { path = "../lemmy_db" }
|
lemmy_db = { path = "../lemmy_db" }
|
||||||
|
lemmy_db_schema = { path = "../lemmy_db_schema" }
|
||||||
lemmy_structs = { path = "../lemmy_structs" }
|
lemmy_structs = { path = "../lemmy_structs" }
|
||||||
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
|
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
|
||||||
lemmy_websocket = { path = "../lemmy_websocket" }
|
lemmy_websocket = { path = "../lemmy_websocket" }
|
||||||
|
|
|
@ -11,10 +11,8 @@ use actix_web::web::Data;
|
||||||
use lemmy_apub::{ApubLikeableType, ApubObjectType};
|
use lemmy_apub::{ApubLikeableType, ApubObjectType};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{
|
source::{
|
||||||
comment::*,
|
|
||||||
comment_report::{CommentReport, CommentReportForm},
|
comment_report::{CommentReport, CommentReportForm},
|
||||||
moderator::*,
|
moderator::*,
|
||||||
post::*,
|
|
||||||
user::*,
|
user::*,
|
||||||
},
|
},
|
||||||
views::{
|
views::{
|
||||||
|
@ -29,6 +27,10 @@ use lemmy_db::{
|
||||||
Saveable,
|
Saveable,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{
|
||||||
|
comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm},
|
||||||
|
post::Post,
|
||||||
|
};
|
||||||
use lemmy_structs::{blocking, comment::*, send_local_notifs};
|
use lemmy_structs::{blocking, comment::*, send_local_notifs};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::{make_apub_endpoint, EndpointType},
|
apub::{make_apub_endpoint, EndpointType},
|
||||||
|
|
|
@ -11,8 +11,7 @@ use anyhow::Context;
|
||||||
use lemmy_apub::ActorType;
|
use lemmy_apub::ActorType;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
diesel_option_overwrite,
|
diesel_option_overwrite,
|
||||||
naive_now,
|
source::{community::*, moderator::*, site::*},
|
||||||
source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
|
|
||||||
views::{
|
views::{
|
||||||
comment_view::CommentQueryBuilder,
|
comment_view::CommentQueryBuilder,
|
||||||
community::{
|
community::{
|
||||||
|
@ -29,6 +28,10 @@ use lemmy_db::{
|
||||||
Joinable,
|
Joinable,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
source::{comment::Comment, post::Post},
|
||||||
|
};
|
||||||
use lemmy_structs::{blocking, community::*};
|
use lemmy_structs::{blocking, community::*};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
||||||
|
|
|
@ -3,13 +3,13 @@ use actix_web::{web, web::Data};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityModerator},
|
community::{Community, CommunityModerator},
|
||||||
post::Post,
|
|
||||||
user::User_,
|
user::User_,
|
||||||
},
|
},
|
||||||
views::community::community_user_ban_view::CommunityUserBanView,
|
views::community::community_user_ban_view::CommunityUserBanView,
|
||||||
Crud,
|
Crud,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::post::Post;
|
||||||
use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
|
use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
|
||||||
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
|
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
|
||||||
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
|
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
|
||||||
|
|
|
@ -10,10 +10,8 @@ use crate::{
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_apub::{ApubLikeableType, ApubObjectType};
|
use lemmy_apub::{ApubLikeableType, ApubObjectType};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
naive_now,
|
|
||||||
source::{
|
source::{
|
||||||
moderator::*,
|
moderator::*,
|
||||||
post::*,
|
|
||||||
post_report::{PostReport, PostReportForm},
|
post_report::{PostReport, PostReportForm},
|
||||||
},
|
},
|
||||||
views::{
|
views::{
|
||||||
|
@ -30,6 +28,10 @@ use lemmy_db::{
|
||||||
Saveable,
|
Saveable,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
source::post::{Post, PostForm, PostLike, PostLikeForm, PostSaved, PostSavedForm},
|
||||||
|
};
|
||||||
use lemmy_structs::{blocking, post::*};
|
use lemmy_structs::{blocking, post::*};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::{make_apub_endpoint, EndpointType},
|
apub::{make_apub_endpoint, EndpointType},
|
||||||
|
|
|
@ -12,7 +12,6 @@ use lemmy_apub::fetcher::search_by_apub_id;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
aggregates::site_aggregates::SiteAggregates,
|
aggregates::site_aggregates::SiteAggregates,
|
||||||
diesel_option_overwrite,
|
diesel_option_overwrite,
|
||||||
naive_now,
|
|
||||||
source::{category::*, moderator::*, site::*},
|
source::{category::*, moderator::*, site::*},
|
||||||
views::{
|
views::{
|
||||||
comment_view::CommentQueryBuilder,
|
comment_view::CommentQueryBuilder,
|
||||||
|
@ -36,6 +35,7 @@ use lemmy_db::{
|
||||||
SearchType,
|
SearchType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::naive_now;
|
||||||
use lemmy_structs::{blocking, site::*, user::Register};
|
use lemmy_structs::{blocking, site::*, user::Register};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
|
|
|
@ -16,13 +16,10 @@ use chrono::Duration;
|
||||||
use lemmy_apub::ApubObjectType;
|
use lemmy_apub::ApubObjectType;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
diesel_option_overwrite,
|
diesel_option_overwrite,
|
||||||
naive_now,
|
|
||||||
source::{
|
source::{
|
||||||
comment::*,
|
|
||||||
community::*,
|
community::*,
|
||||||
moderator::*,
|
moderator::*,
|
||||||
password_reset_request::*,
|
password_reset_request::*,
|
||||||
post::*,
|
|
||||||
private_message::*,
|
private_message::*,
|
||||||
site::*,
|
site::*,
|
||||||
user::*,
|
user::*,
|
||||||
|
@ -48,6 +45,10 @@ use lemmy_db::{
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
source::{comment::Comment, post::Post},
|
||||||
|
};
|
||||||
use lemmy_structs::{blocking, send_email_to_user, user::*};
|
use lemmy_structs::{blocking, send_email_to_user, user::*};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
||||||
|
|
|
@ -11,6 +11,7 @@ path = "src/lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_utils = { path = "../lemmy_utils" }
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
lemmy_db = { path = "../lemmy_db" }
|
lemmy_db = { path = "../lemmy_db" }
|
||||||
|
lemmy_db_schema = { path = "../lemmy_db_schema" }
|
||||||
lemmy_structs = { path = "../lemmy_structs" }
|
lemmy_structs = { path = "../lemmy_structs" }
|
||||||
lemmy_websocket = { path = "../lemmy_websocket" }
|
lemmy_websocket = { path = "../lemmy_websocket" }
|
||||||
diesel = "1.4.5"
|
diesel = "1.4.5"
|
||||||
|
|
|
@ -4,13 +4,10 @@ use activitystreams::{
|
||||||
base::ExtendsExt,
|
base::ExtendsExt,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{views::comment_view::CommentView, Likeable};
|
||||||
source::{
|
use lemmy_db_schema::source::{
|
||||||
comment::{Comment, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentLike, CommentLikeForm},
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
|
||||||
views::comment_view::CommentView,
|
|
||||||
Likeable,
|
|
||||||
};
|
};
|
||||||
use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
|
use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
|
||||||
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
|
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use crate::activities::receive::get_actor_as_user;
|
use crate::activities::receive::get_actor_as_user;
|
||||||
use activitystreams::activity::{Dislike, Like};
|
use activitystreams::activity::{Dislike, Like};
|
||||||
use lemmy_db::{
|
use lemmy_db::{views::comment_view::CommentView, Likeable};
|
||||||
source::comment::{Comment, CommentLike},
|
use lemmy_db_schema::source::comment::{Comment, CommentLike};
|
||||||
views::comment_view::CommentView,
|
|
||||||
Likeable,
|
|
||||||
};
|
|
||||||
use lemmy_structs::{blocking, comment::CommentResponse};
|
use lemmy_structs::{blocking, comment::CommentResponse};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
|
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
|
||||||
|
|
|
@ -4,11 +4,8 @@ use activitystreams::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{views::post_view::PostView, Likeable};
|
||||||
source::post::{Post, PostLike, PostLikeForm},
|
use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm};
|
||||||
views::post_view::PostView,
|
|
||||||
Likeable,
|
|
||||||
};
|
|
||||||
use lemmy_structs::{blocking, post::PostResponse};
|
use lemmy_structs::{blocking, post::PostResponse};
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
|
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use crate::activities::receive::get_actor_as_user;
|
use crate::activities::receive::get_actor_as_user;
|
||||||
use activitystreams::activity::{Dislike, Like};
|
use activitystreams::activity::{Dislike, Like};
|
||||||
use lemmy_db::{
|
use lemmy_db::{views::post_view::PostView, Likeable};
|
||||||
source::post::{Post, PostLike},
|
use lemmy_db_schema::source::post::{Post, PostLike};
|
||||||
views::post_view::PostView,
|
|
||||||
Likeable,
|
|
||||||
};
|
|
||||||
use lemmy_structs::{blocking, post::PostResponse};
|
use lemmy_structs::{blocking, post::PostResponse};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
|
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
|
||||||
|
|
|
@ -27,10 +27,11 @@ use activitystreams::{
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{comment::Comment, community::Community, post::Post, user::User_},
|
source::{community::Community, user::User_},
|
||||||
Crud,
|
Crud,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::Comment, post::Post};
|
||||||
use lemmy_structs::{blocking, WebFingerResponse};
|
use lemmy_structs::{blocking, WebFingerResponse};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
request::{retry, RecvError},
|
request::{retry, RecvError},
|
||||||
|
|
|
@ -22,9 +22,10 @@ use activitystreams::{
|
||||||
public,
|
public,
|
||||||
};
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{community::Community, post::Post, user::User_},
|
source::{community::Community, user::User_},
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::post::Post;
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
|
|
@ -13,11 +13,8 @@ use anyhow::{anyhow, Context};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
naive_now,
|
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
|
||||||
community::{Community, CommunityModerator, CommunityModeratorForm},
|
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||||
post::Post,
|
|
||||||
user::User_,
|
user::User_,
|
||||||
},
|
},
|
||||||
views::{
|
views::{
|
||||||
|
@ -30,6 +27,10 @@ use lemmy_db::{
|
||||||
Joinable,
|
Joinable,
|
||||||
SearchType,
|
SearchType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
source::{comment::Comment, post::Post},
|
||||||
|
};
|
||||||
use lemmy_structs::{blocking, site::SearchResponse};
|
use lemmy_structs::{blocking, site::SearchResponse};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
|
|
|
@ -4,7 +4,8 @@ use crate::{
|
||||||
};
|
};
|
||||||
use actix_web::{body::Body, web, web::Path, HttpResponse};
|
use actix_web::{body::Body, web, web::Path, HttpResponse};
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
use lemmy_db::{source::comment::Comment, Crud};
|
use lemmy_db::Crud;
|
||||||
|
use lemmy_db_schema::source::comment::Comment;
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
|
|
@ -10,9 +10,10 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use actix_web::{body::Body, web, HttpResponse};
|
use actix_web::{body::Body, web, HttpResponse};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{community::Community, post::Post},
|
source::community::Community,
|
||||||
views::community::community_follower_view::CommunityFollowerView,
|
views::community::community_follower_view::CommunityFollowerView,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::post::Post;
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use actix_web::{body::Body, web, HttpResponse};
|
use actix_web::{body::Body, web, HttpResponse};
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
use lemmy_db::source::post::Post;
|
use lemmy_db_schema::source::post::Post;
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
|
|
@ -41,11 +41,8 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
use lemmy_db::{
|
use lemmy_db::{source::site::Site, ApubObject, Crud};
|
||||||
source::{comment::Comment, post::Post, site::Site},
|
use lemmy_db_schema::source::{comment::Comment, post::Post};
|
||||||
ApubObject,
|
|
||||||
Crud,
|
|
||||||
};
|
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
|
|
@ -24,15 +24,14 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{
|
source::{community::Community, user::User_},
|
||||||
comment::{Comment, CommentForm},
|
|
||||||
community::Community,
|
|
||||||
post::Post,
|
|
||||||
user::User_,
|
|
||||||
},
|
|
||||||
Crud,
|
Crud,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{
|
||||||
|
comment::{Comment, CommentForm},
|
||||||
|
post::Post,
|
||||||
|
};
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
|
|
|
@ -23,11 +23,11 @@ use activitystreams::{
|
||||||
use activitystreams_ext::Ext2;
|
use activitystreams_ext::Ext2;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
naive_now,
|
|
||||||
source::community::{Community, CommunityForm},
|
source::community::{Community, CommunityForm},
|
||||||
views::community::community_moderator_view::CommunityModeratorView,
|
views::community::community_moderator_view::CommunityModeratorView,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::naive_now;
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
|
|
|
@ -21,14 +21,11 @@ use activitystreams::{
|
||||||
use activitystreams_ext::Ext1;
|
use activitystreams_ext::Ext1;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{
|
source::{community::Community, user::User_},
|
||||||
community::Community,
|
|
||||||
post::{Post, PostForm},
|
|
||||||
user::User_,
|
|
||||||
},
|
|
||||||
Crud,
|
Crud,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::post::{Post, PostForm};
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
|
|
|
@ -19,11 +19,11 @@ use activitystreams::{
|
||||||
use activitystreams_ext::Ext1;
|
use activitystreams_ext::Ext1;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
naive_now,
|
|
||||||
source::user::{UserForm, User_},
|
source::user::{UserForm, User_},
|
||||||
ApubObject,
|
ApubObject,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::naive_now;
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
location_info,
|
location_info,
|
||||||
|
|
|
@ -25,9 +25,7 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::community_aggregates::CommunityAggregates,
|
aggregates::community_aggregates::CommunityAggregates,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentForm},
|
|
||||||
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
|
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
|
||||||
post::{Post, PostForm},
|
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
},
|
},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
|
@ -36,6 +34,10 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{
|
||||||
|
comment::{Comment, CommentForm},
|
||||||
|
post::{Post, PostForm},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -27,9 +27,7 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::post_aggregates::PostAggregates,
|
aggregates::post_aggregates::PostAggregates,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentForm},
|
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
},
|
},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
|
@ -38,6 +36,10 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{
|
||||||
|
comment::{Comment, CommentForm},
|
||||||
|
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -23,9 +23,7 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::site_aggregates::SiteAggregates,
|
aggregates::site_aggregates::SiteAggregates,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentForm},
|
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm},
|
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
},
|
},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
|
@ -33,6 +31,10 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{
|
||||||
|
comment::{Comment, CommentForm},
|
||||||
|
post::{Post, PostForm},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -26,9 +26,7 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::user_aggregates::UserAggregates,
|
aggregates::user_aggregates::UserAggregates,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
},
|
},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
|
@ -37,6 +35,10 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{
|
||||||
|
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||||
|
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -5,7 +5,6 @@ extern crate strum_macros;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -181,10 +180,6 @@ pub fn limit_and_offset(page: Option<i64>, limit: Option<i64>) -> (i64, i64) {
|
||||||
(limit, offset)
|
(limit, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn naive_now() -> NaiveDateTime {
|
|
||||||
chrono::prelude::Utc::now().naive_utc()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_email_regex(test: &str) -> bool {
|
pub fn is_email_regex(test: &str) -> bool {
|
||||||
EMAIL_REGEX.is_match(test)
|
EMAIL_REGEX.is_match(test)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,74 +1,13 @@
|
||||||
use super::post::Post;
|
use crate::{ApubObject, Crud, Likeable, Saveable};
|
||||||
use crate::{naive_now, ApubObject, Crud, Likeable, Saveable};
|
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::{comment, comment_alias_1, comment_like, comment_saved};
|
use lemmy_db_schema::source::comment::{
|
||||||
use serde::Serialize;
|
Comment,
|
||||||
use url::{ParseError, Url};
|
CommentForm,
|
||||||
|
CommentLike,
|
||||||
// WITH RECURSIVE MyTree AS (
|
CommentLikeForm,
|
||||||
// SELECT * FROM comment WHERE parent_id IS NULL
|
CommentSaved,
|
||||||
// UNION ALL
|
CommentSavedForm,
|
||||||
// SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
|
};
|
||||||
// )
|
|
||||||
// SELECT * FROM MyTree;
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[belongs_to(Post)]
|
|
||||||
#[table_name = "comment"]
|
|
||||||
pub struct Comment {
|
|
||||||
pub id: i32,
|
|
||||||
pub creator_id: i32,
|
|
||||||
pub post_id: i32,
|
|
||||||
pub parent_id: Option<i32>,
|
|
||||||
pub content: String,
|
|
||||||
pub removed: bool,
|
|
||||||
pub read: bool, // Whether the recipient has read the comment or not
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub deleted: bool,
|
|
||||||
pub ap_id: String,
|
|
||||||
pub local: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[belongs_to(Post)]
|
|
||||||
#[table_name = "comment_alias_1"]
|
|
||||||
pub struct CommentAlias1 {
|
|
||||||
pub id: i32,
|
|
||||||
pub creator_id: i32,
|
|
||||||
pub post_id: i32,
|
|
||||||
pub parent_id: Option<i32>,
|
|
||||||
pub content: String,
|
|
||||||
pub removed: bool,
|
|
||||||
pub read: bool, // Whether the recipient has read the comment or not
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub deleted: bool,
|
|
||||||
pub ap_id: String,
|
|
||||||
pub local: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
|
||||||
#[table_name = "comment"]
|
|
||||||
pub struct CommentForm {
|
|
||||||
pub creator_id: i32,
|
|
||||||
pub post_id: i32,
|
|
||||||
pub parent_id: Option<i32>,
|
|
||||||
pub content: String,
|
|
||||||
pub removed: Option<bool>,
|
|
||||||
pub read: Option<bool>,
|
|
||||||
pub published: Option<chrono::NaiveDateTime>,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub deleted: Option<bool>,
|
|
||||||
pub ap_id: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommentForm {
|
|
||||||
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
|
|
||||||
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Crud<CommentForm> for Comment {
|
impl Crud<CommentForm> for Comment {
|
||||||
fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
|
fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
|
||||||
|
@ -117,106 +56,6 @@ impl ApubObject<CommentForm> for Comment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Comment {
|
|
||||||
pub fn update_ap_id(
|
|
||||||
conn: &PgConnection,
|
|
||||||
comment_id: i32,
|
|
||||||
apub_id: String,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
|
|
||||||
diesel::update(comment.find(comment_id))
|
|
||||||
.set(ap_id.eq(apub_id))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn permadelete_for_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
for_creator_id: i32,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
|
||||||
.set((
|
|
||||||
content.eq("*Permananently Deleted*"),
|
|
||||||
deleted.eq(true),
|
|
||||||
updated.eq(naive_now()),
|
|
||||||
))
|
|
||||||
.get_results::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_deleted(
|
|
||||||
conn: &PgConnection,
|
|
||||||
comment_id: i32,
|
|
||||||
new_deleted: bool,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
diesel::update(comment.find(comment_id))
|
|
||||||
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_removed(
|
|
||||||
conn: &PgConnection,
|
|
||||||
comment_id: i32,
|
|
||||||
new_removed: bool,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
diesel::update(comment.find(comment_id))
|
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_removed_for_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
for_creator_id: i32,
|
|
||||||
new_removed: bool,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
|
||||||
.get_results::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
diesel::update(comment.find(comment_id))
|
|
||||||
.set(read.eq(new_read))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_content(
|
|
||||||
conn: &PgConnection,
|
|
||||||
comment_id: i32,
|
|
||||||
new_content: &str,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::comment::dsl::*;
|
|
||||||
diesel::update(comment.find(comment_id))
|
|
||||||
.set((content.eq(new_content), updated.eq(naive_now())))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
|
|
||||||
#[belongs_to(Comment)]
|
|
||||||
#[table_name = "comment_like"]
|
|
||||||
pub struct CommentLike {
|
|
||||||
pub id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
pub comment_id: i32,
|
|
||||||
pub post_id: i32, // TODO this is redundant
|
|
||||||
pub score: i16,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
|
||||||
#[table_name = "comment_like"]
|
|
||||||
pub struct CommentLikeForm {
|
|
||||||
pub user_id: i32,
|
|
||||||
pub comment_id: i32,
|
|
||||||
pub post_id: i32, // TODO this is redundant
|
|
||||||
pub score: i16,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Likeable<CommentLikeForm> for CommentLike {
|
impl Likeable<CommentLikeForm> for CommentLike {
|
||||||
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
|
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::comment_like::dsl::*;
|
use lemmy_db_schema::schema::comment_like::dsl::*;
|
||||||
|
@ -238,23 +77,6 @@ impl Likeable<CommentLikeForm> for CommentLike {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
|
||||||
#[belongs_to(Comment)]
|
|
||||||
#[table_name = "comment_saved"]
|
|
||||||
pub struct CommentSaved {
|
|
||||||
pub id: i32,
|
|
||||||
pub comment_id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
|
||||||
#[table_name = "comment_saved"]
|
|
||||||
pub struct CommentSavedForm {
|
|
||||||
pub comment_id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Saveable<CommentSavedForm> for CommentSaved {
|
impl Saveable<CommentSavedForm> for CommentSaved {
|
||||||
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
|
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::comment_saved::dsl::*;
|
use lemmy_db_schema::schema::comment_saved::dsl::*;
|
||||||
|
@ -279,12 +101,15 @@ impl Saveable<CommentSavedForm> for CommentSaved {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
source::{comment::*, community::*, post::*, user::*},
|
source::{community::*, user::*},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
Crud,
|
Crud,
|
||||||
|
Likeable,
|
||||||
ListingType,
|
ListingType,
|
||||||
|
Saveable,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::*, post::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{naive_now, source::comment::Comment, Reportable};
|
use crate::Reportable;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::comment_report;
|
use lemmy_db_schema::{naive_now, schema::comment_report, source::comment::Comment};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
naive_now,
|
|
||||||
views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
|
views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
|
||||||
ApubObject,
|
ApubObject,
|
||||||
Bannable,
|
Bannable,
|
||||||
|
@ -8,11 +7,9 @@ use crate::{
|
||||||
Joinable,
|
Joinable,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::{
|
use lemmy_db_schema::{
|
||||||
community,
|
naive_now,
|
||||||
community_follower,
|
schema::{community, community_follower, community_moderator, community_user_ban},
|
||||||
community_moderator,
|
|
||||||
community_user_ban,
|
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
|
|
@ -391,11 +391,12 @@ impl Crud<ModAddForm> for ModAdd {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
source::{comment::*, community::*, moderator::*, post::*, user::*},
|
source::{community::*, moderator::*, user::*},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::*, post::*};
|
||||||
|
|
||||||
// use Crud;
|
// use Crud;
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,61 +1,15 @@
|
||||||
use crate::{naive_now, ApubObject, Crud, Likeable, Readable, Saveable};
|
use crate::{ApubObject, Crud, Likeable, Readable, Saveable};
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::{post, post_like, post_read, post_saved};
|
use lemmy_db_schema::source::post::{
|
||||||
use serde::Serialize;
|
Post,
|
||||||
use url::{ParseError, Url};
|
PostForm,
|
||||||
|
PostLike,
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
PostLikeForm,
|
||||||
#[table_name = "post"]
|
PostRead,
|
||||||
pub struct Post {
|
PostReadForm,
|
||||||
pub id: i32,
|
PostSaved,
|
||||||
pub name: String,
|
PostSavedForm,
|
||||||
pub url: Option<String>,
|
};
|
||||||
pub body: Option<String>,
|
|
||||||
pub creator_id: i32,
|
|
||||||
pub community_id: i32,
|
|
||||||
pub removed: bool,
|
|
||||||
pub locked: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub deleted: bool,
|
|
||||||
pub nsfw: bool,
|
|
||||||
pub stickied: bool,
|
|
||||||
pub embed_title: Option<String>,
|
|
||||||
pub embed_description: Option<String>,
|
|
||||||
pub embed_html: Option<String>,
|
|
||||||
pub thumbnail_url: Option<String>,
|
|
||||||
pub ap_id: String,
|
|
||||||
pub local: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
|
||||||
#[table_name = "post"]
|
|
||||||
pub struct PostForm {
|
|
||||||
pub name: String,
|
|
||||||
pub url: Option<String>,
|
|
||||||
pub body: Option<String>,
|
|
||||||
pub creator_id: i32,
|
|
||||||
pub community_id: i32,
|
|
||||||
pub removed: Option<bool>,
|
|
||||||
pub locked: Option<bool>,
|
|
||||||
pub published: Option<chrono::NaiveDateTime>,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub deleted: Option<bool>,
|
|
||||||
pub nsfw: bool,
|
|
||||||
pub stickied: Option<bool>,
|
|
||||||
pub embed_title: Option<String>,
|
|
||||||
pub embed_description: Option<String>,
|
|
||||||
pub embed_html: Option<String>,
|
|
||||||
pub thumbnail_url: Option<String>,
|
|
||||||
pub ap_id: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PostForm {
|
|
||||||
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
|
|
||||||
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Crud<PostForm> for Post {
|
impl Crud<PostForm> for Post {
|
||||||
fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
|
fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
|
||||||
|
@ -98,137 +52,6 @@ impl ApubObject<PostForm> for Post {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post {
|
|
||||||
pub fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
post.filter(id.eq(post_id)).first::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn list_for_community(
|
|
||||||
conn: &PgConnection,
|
|
||||||
the_community_id: i32,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
post
|
|
||||||
.filter(community_id.eq(the_community_id))
|
|
||||||
.then_order_by(published.desc())
|
|
||||||
.then_order_by(stickied.desc())
|
|
||||||
.limit(20)
|
|
||||||
.load::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
|
|
||||||
diesel::update(post.find(post_id))
|
|
||||||
.set(ap_id.eq(apub_id))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn permadelete_for_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
for_creator_id: i32,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
|
|
||||||
let perma_deleted = "*Permananently Deleted*";
|
|
||||||
let perma_deleted_url = "https://deleted.com";
|
|
||||||
|
|
||||||
diesel::update(post.filter(creator_id.eq(for_creator_id)))
|
|
||||||
.set((
|
|
||||||
name.eq(perma_deleted),
|
|
||||||
url.eq(perma_deleted_url),
|
|
||||||
body.eq(perma_deleted),
|
|
||||||
deleted.eq(true),
|
|
||||||
updated.eq(naive_now()),
|
|
||||||
))
|
|
||||||
.get_results::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_deleted(
|
|
||||||
conn: &PgConnection,
|
|
||||||
post_id: i32,
|
|
||||||
new_deleted: bool,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
diesel::update(post.find(post_id))
|
|
||||||
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_removed(
|
|
||||||
conn: &PgConnection,
|
|
||||||
post_id: i32,
|
|
||||||
new_removed: bool,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
diesel::update(post.find(post_id))
|
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_removed_for_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
for_creator_id: i32,
|
|
||||||
for_community_id: Option<i32>,
|
|
||||||
new_removed: bool,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
|
|
||||||
let mut update = diesel::update(post).into_boxed();
|
|
||||||
update = update.filter(creator_id.eq(for_creator_id));
|
|
||||||
|
|
||||||
if let Some(for_community_id) = for_community_id {
|
|
||||||
update = update.filter(community_id.eq(for_community_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
update
|
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
|
||||||
.get_results::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
diesel::update(post.find(post_id))
|
|
||||||
.set(locked.eq(new_locked))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_stickied(
|
|
||||||
conn: &PgConnection,
|
|
||||||
post_id: i32,
|
|
||||||
new_stickied: bool,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::post::dsl::*;
|
|
||||||
diesel::update(post.find(post_id))
|
|
||||||
.set(stickied.eq(new_stickied))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
|
|
||||||
user_id == post_creator_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
|
||||||
#[belongs_to(Post)]
|
|
||||||
#[table_name = "post_like"]
|
|
||||||
pub struct PostLike {
|
|
||||||
pub id: i32,
|
|
||||||
pub post_id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
pub score: i16,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
|
||||||
#[table_name = "post_like"]
|
|
||||||
pub struct PostLikeForm {
|
|
||||||
pub post_id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
pub score: i16,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Likeable<PostLikeForm> for PostLike {
|
impl Likeable<PostLikeForm> for PostLike {
|
||||||
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
|
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::post_like::dsl::*;
|
use lemmy_db_schema::schema::post_like::dsl::*;
|
||||||
|
@ -250,23 +73,6 @@ impl Likeable<PostLikeForm> for PostLike {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
|
||||||
#[belongs_to(Post)]
|
|
||||||
#[table_name = "post_saved"]
|
|
||||||
pub struct PostSaved {
|
|
||||||
pub id: i32,
|
|
||||||
pub post_id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
|
||||||
#[table_name = "post_saved"]
|
|
||||||
pub struct PostSavedForm {
|
|
||||||
pub post_id: i32,
|
|
||||||
pub user_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Saveable<PostSavedForm> for PostSaved {
|
impl Saveable<PostSavedForm> for PostSaved {
|
||||||
fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
|
fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::post_saved::dsl::*;
|
use lemmy_db_schema::schema::post_saved::dsl::*;
|
||||||
|
@ -288,27 +94,6 @@ impl Saveable<PostSavedForm> for PostSaved {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
|
||||||
#[belongs_to(Post)]
|
|
||||||
#[table_name = "post_read"]
|
|
||||||
pub struct PostRead {
|
|
||||||
pub id: i32,
|
|
||||||
|
|
||||||
pub post_id: i32,
|
|
||||||
|
|
||||||
pub user_id: i32,
|
|
||||||
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
|
||||||
#[table_name = "post_read"]
|
|
||||||
pub struct PostReadForm {
|
|
||||||
pub post_id: i32,
|
|
||||||
|
|
||||||
pub user_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Readable<PostReadForm> for PostRead {
|
impl Readable<PostReadForm> for PostRead {
|
||||||
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
|
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::post_read::dsl::*;
|
use lemmy_db_schema::schema::post_read::dsl::*;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{naive_now, source::post::Post, Reportable};
|
use crate::Reportable;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::post_report;
|
use lemmy_db_schema::{naive_now, schema::post_report, source::post::Post};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{naive_now, ApubObject, Crud};
|
use crate::{ApubObject, Crud};
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::private_message;
|
use lemmy_db_schema::{naive_now, schema::private_message};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{naive_now, Crud};
|
use crate::Crud;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::site;
|
use lemmy_db_schema::{naive_now, schema::site};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
|
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::{is_email_regex, naive_now, ApubObject, Crud};
|
use crate::{is_email_regex, ApubObject, Crud};
|
||||||
use bcrypt::{hash, DEFAULT_COST};
|
use bcrypt::{hash, DEFAULT_COST};
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::{user_, user_::dsl::*, user_alias_1, user_alias_2};
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
schema::{user_, user_::dsl::*, user_alias_1, user_alias_2},
|
||||||
|
};
|
||||||
use lemmy_utils::settings::Settings;
|
use lemmy_utils::settings::Settings;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use super::comment::Comment;
|
|
||||||
use crate::Crud;
|
use crate::Crud;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::schema::user_mention;
|
use lemmy_db_schema::{schema::user_mention, source::comment::Comment};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
@ -80,11 +79,12 @@ impl UserMention {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
source::{comment::*, community::*, post::*, user::*, user_mention::*},
|
source::{community::*, user::*, user_mention::*},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::*, post::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
|
||||||
comment_report::CommentReport,
|
comment_report::CommentReport,
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
post::Post,
|
|
||||||
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
|
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
|
@ -12,14 +10,9 @@ use crate::{
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{
|
use lemmy_db_schema::{
|
||||||
comment,
|
schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
|
||||||
comment_report,
|
source::{comment::Comment, post::Post},
|
||||||
community,
|
|
||||||
post,
|
|
||||||
user_,
|
|
||||||
user_alias_1,
|
|
||||||
user_alias_2,
|
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,7 @@ use crate::{
|
||||||
fuzzy_search,
|
fuzzy_search,
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentAlias1, CommentSaved},
|
|
||||||
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
||||||
post::Post,
|
|
||||||
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
|
@ -16,18 +14,24 @@ use crate::{
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{
|
use lemmy_db_schema::{
|
||||||
comment,
|
schema::{
|
||||||
comment_aggregates,
|
comment,
|
||||||
comment_alias_1,
|
comment_aggregates,
|
||||||
comment_like,
|
comment_alias_1,
|
||||||
comment_saved,
|
comment_like,
|
||||||
community,
|
comment_saved,
|
||||||
community_follower,
|
community,
|
||||||
community_user_ban,
|
community_follower,
|
||||||
post,
|
community_user_ban,
|
||||||
user_,
|
post,
|
||||||
user_alias_1,
|
user_,
|
||||||
|
user_alias_1,
|
||||||
|
},
|
||||||
|
source::{
|
||||||
|
comment::{Comment, CommentAlias1, CommentSaved},
|
||||||
|
post::Post,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -408,13 +412,14 @@ impl ViewToVec for CommentView {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
source::{comment::*, community::*, post::*, user::*},
|
source::{community::*, user::*},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
views::comment_view::*,
|
views::comment_view::*,
|
||||||
Crud,
|
Crud,
|
||||||
Likeable,
|
Likeable,
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::*, post::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -3,14 +3,16 @@ use crate::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModLockPost,
|
moderator::ModLockPost,
|
||||||
post::Post,
|
|
||||||
user::{UserSafe, User_},
|
user::{UserSafe, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{community, mod_lock_post, post, user_};
|
use lemmy_db_schema::{
|
||||||
|
schema::{community, mod_lock_post, post, user_},
|
||||||
|
source::post::Post,
|
||||||
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModRemoveComment,
|
moderator::ModRemoveComment,
|
||||||
post::Post,
|
|
||||||
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{comment, community, mod_remove_comment, post, user_, user_alias_1};
|
use lemmy_db_schema::{
|
||||||
|
schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
|
||||||
|
source::{comment::Comment, post::Post},
|
||||||
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
|
|
@ -3,14 +3,16 @@ use crate::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModRemovePost,
|
moderator::ModRemovePost,
|
||||||
post::Post,
|
|
||||||
user::{UserSafe, User_},
|
user::{UserSafe, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{community, mod_remove_post, post, user_};
|
use lemmy_db_schema::{
|
||||||
|
schema::{community, mod_remove_post, post, user_},
|
||||||
|
source::post::Post,
|
||||||
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
|
|
@ -3,14 +3,16 @@ use crate::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModStickyPost,
|
moderator::ModStickyPost,
|
||||||
post::Post,
|
|
||||||
user::{UserSafe, User_},
|
user::{UserSafe, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{community, mod_sticky_post, post, user_};
|
use lemmy_db_schema::{
|
||||||
|
schema::{community, mod_sticky_post, post, user_},
|
||||||
|
source::post::Post,
|
||||||
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
|
|
@ -2,7 +2,6 @@ use crate::{
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
post::Post,
|
|
||||||
post_report::PostReport,
|
post_report::PostReport,
|
||||||
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
|
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
|
||||||
},
|
},
|
||||||
|
@ -11,7 +10,10 @@ use crate::{
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{community, post, post_report, user_, user_alias_1, user_alias_2};
|
use lemmy_db_schema::{
|
||||||
|
schema::{community, post, post_report, user_, user_alias_1, user_alias_2},
|
||||||
|
source::post::Post,
|
||||||
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Clone)]
|
#[derive(Debug, PartialEq, Serialize, Clone)]
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::{
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
||||||
post::{Post, PostRead, PostSaved},
|
|
||||||
user::{UserSafe, User_},
|
user::{UserSafe, User_},
|
||||||
},
|
},
|
||||||
views::ViewToVec,
|
views::ViewToVec,
|
||||||
|
@ -15,16 +14,19 @@ use crate::{
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{
|
use lemmy_db_schema::{
|
||||||
community,
|
schema::{
|
||||||
community_follower,
|
community,
|
||||||
community_user_ban,
|
community_follower,
|
||||||
post,
|
community_user_ban,
|
||||||
post_aggregates,
|
post,
|
||||||
post_like,
|
post_aggregates,
|
||||||
post_read,
|
post_like,
|
||||||
post_saved,
|
post_read,
|
||||||
user_,
|
post_saved,
|
||||||
|
user_,
|
||||||
|
},
|
||||||
|
source::post::{Post, PostRead, PostSaved},
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -406,13 +408,14 @@ impl ViewToVec for PostView {
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::post_aggregates::PostAggregates,
|
aggregates::post_aggregates::PostAggregates,
|
||||||
source::{community::*, post::*, user::*},
|
source::{community::*, user::*},
|
||||||
tests::establish_unpooled_connection,
|
tests::establish_unpooled_connection,
|
||||||
views::post_view::{PostQueryBuilder, PostView},
|
views::post_view::{PostQueryBuilder, PostView},
|
||||||
Crud,
|
Crud,
|
||||||
Likeable,
|
Likeable,
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::post::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
|
|
|
@ -3,9 +3,7 @@ use crate::{
|
||||||
functions::hot_rank,
|
functions::hot_rank,
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentSaved},
|
|
||||||
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
||||||
post::Post,
|
|
||||||
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
||||||
user_mention::UserMention,
|
user_mention::UserMention,
|
||||||
},
|
},
|
||||||
|
@ -15,18 +13,24 @@ use crate::{
|
||||||
ToSafe,
|
ToSafe,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::{
|
use lemmy_db_schema::{
|
||||||
comment,
|
schema::{
|
||||||
comment_aggregates,
|
comment,
|
||||||
comment_like,
|
comment_aggregates,
|
||||||
comment_saved,
|
comment_like,
|
||||||
community,
|
comment_saved,
|
||||||
community_follower,
|
community,
|
||||||
community_user_ban,
|
community_follower,
|
||||||
post,
|
community_user_ban,
|
||||||
user_,
|
post,
|
||||||
user_alias_1,
|
user_,
|
||||||
user_mention,
|
user_alias_1,
|
||||||
|
user_mention,
|
||||||
|
},
|
||||||
|
source::{
|
||||||
|
comment::{Comment, CommentSaved},
|
||||||
|
post::Post,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,8 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
|
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
|
||||||
|
chrono = { version = "0.4.19", features = ["serde"] }
|
||||||
|
serde = { version = "1.0.118", features = ["derive"] }
|
||||||
|
serde_json = { version = "1.0.60", features = ["preserve_order"] }
|
||||||
|
log = "0.4.11"
|
||||||
|
url = { version = "2.2.0", features = ["serde"] }
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
|
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
|
pub mod source;
|
||||||
|
|
||||||
|
pub fn naive_now() -> NaiveDateTime {
|
||||||
|
chrono::prelude::Utc::now().naive_utc()
|
||||||
|
}
|
||||||
|
|
190
lemmy_db_schema/src/source/comment.rs
Normal file
190
lemmy_db_schema/src/source/comment.rs
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
use crate::{
|
||||||
|
naive_now,
|
||||||
|
schema::{comment, comment_alias_1, comment_like, comment_saved},
|
||||||
|
source::post::Post,
|
||||||
|
};
|
||||||
|
use diesel::{result::Error, PgConnection, *};
|
||||||
|
use serde::Serialize;
|
||||||
|
use url::{ParseError, Url};
|
||||||
|
|
||||||
|
// WITH RECURSIVE MyTree AS (
|
||||||
|
// SELECT * FROM comment WHERE parent_id IS NULL
|
||||||
|
// UNION ALL
|
||||||
|
// SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
|
||||||
|
// )
|
||||||
|
// SELECT * FROM MyTree;
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[belongs_to(Post)]
|
||||||
|
#[table_name = "comment"]
|
||||||
|
pub struct Comment {
|
||||||
|
pub id: i32,
|
||||||
|
pub creator_id: i32,
|
||||||
|
pub post_id: i32,
|
||||||
|
pub parent_id: Option<i32>,
|
||||||
|
pub content: String,
|
||||||
|
pub removed: bool,
|
||||||
|
pub read: bool, // Whether the recipient has read the comment or not
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub ap_id: String,
|
||||||
|
pub local: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[belongs_to(Post)]
|
||||||
|
#[table_name = "comment_alias_1"]
|
||||||
|
pub struct CommentAlias1 {
|
||||||
|
pub id: i32,
|
||||||
|
pub creator_id: i32,
|
||||||
|
pub post_id: i32,
|
||||||
|
pub parent_id: Option<i32>,
|
||||||
|
pub content: String,
|
||||||
|
pub removed: bool,
|
||||||
|
pub read: bool, // Whether the recipient has read the comment or not
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub ap_id: String,
|
||||||
|
pub local: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
|
#[table_name = "comment"]
|
||||||
|
pub struct CommentForm {
|
||||||
|
pub creator_id: i32,
|
||||||
|
pub post_id: i32,
|
||||||
|
pub parent_id: Option<i32>,
|
||||||
|
pub content: String,
|
||||||
|
pub removed: Option<bool>,
|
||||||
|
pub read: Option<bool>,
|
||||||
|
pub published: Option<chrono::NaiveDateTime>,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub deleted: Option<bool>,
|
||||||
|
pub ap_id: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Comment {
|
||||||
|
pub fn update_ap_id(
|
||||||
|
conn: &PgConnection,
|
||||||
|
comment_id: i32,
|
||||||
|
apub_id: String,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
|
||||||
|
diesel::update(comment.find(comment_id))
|
||||||
|
.set(ap_id.eq(apub_id))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn permadelete_for_creator(
|
||||||
|
conn: &PgConnection,
|
||||||
|
for_creator_id: i32,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||||
|
.set((
|
||||||
|
content.eq("*Permananently Deleted*"),
|
||||||
|
deleted.eq(true),
|
||||||
|
updated.eq(naive_now()),
|
||||||
|
))
|
||||||
|
.get_results::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_deleted(
|
||||||
|
conn: &PgConnection,
|
||||||
|
comment_id: i32,
|
||||||
|
new_deleted: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
diesel::update(comment.find(comment_id))
|
||||||
|
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_removed(
|
||||||
|
conn: &PgConnection,
|
||||||
|
comment_id: i32,
|
||||||
|
new_removed: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
diesel::update(comment.find(comment_id))
|
||||||
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_removed_for_creator(
|
||||||
|
conn: &PgConnection,
|
||||||
|
for_creator_id: i32,
|
||||||
|
new_removed: bool,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||||
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
|
.get_results::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
diesel::update(comment.find(comment_id))
|
||||||
|
.set(read.eq(new_read))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_content(
|
||||||
|
conn: &PgConnection,
|
||||||
|
comment_id: i32,
|
||||||
|
new_content: &str,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::comment::dsl::*;
|
||||||
|
diesel::update(comment.find(comment_id))
|
||||||
|
.set((content.eq(new_content), updated.eq(naive_now())))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommentForm {
|
||||||
|
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
|
||||||
|
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
|
||||||
|
#[belongs_to(Comment)]
|
||||||
|
#[table_name = "comment_like"]
|
||||||
|
pub struct CommentLike {
|
||||||
|
pub id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub comment_id: i32,
|
||||||
|
pub post_id: i32, // TODO this is redundant
|
||||||
|
pub score: i16,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
|
#[table_name = "comment_like"]
|
||||||
|
pub struct CommentLikeForm {
|
||||||
|
pub user_id: i32,
|
||||||
|
pub comment_id: i32,
|
||||||
|
pub post_id: i32, // TODO this is redundant
|
||||||
|
pub score: i16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
|
#[belongs_to(Comment)]
|
||||||
|
#[table_name = "comment_saved"]
|
||||||
|
pub struct CommentSaved {
|
||||||
|
pub id: i32,
|
||||||
|
pub comment_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset)]
|
||||||
|
#[table_name = "comment_saved"]
|
||||||
|
pub struct CommentSavedForm {
|
||||||
|
pub comment_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
}
|
2
lemmy_db_schema/src/source/mod.rs
Normal file
2
lemmy_db_schema/src/source/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod comment;
|
||||||
|
pub mod post;
|
229
lemmy_db_schema/src/source/post.rs
Normal file
229
lemmy_db_schema/src/source/post.rs
Normal file
|
@ -0,0 +1,229 @@
|
||||||
|
use crate::{
|
||||||
|
naive_now,
|
||||||
|
schema::{post, post_like, post_read, post_saved},
|
||||||
|
};
|
||||||
|
use diesel::{result::Error, *};
|
||||||
|
use serde::Serialize;
|
||||||
|
use url::{ParseError, Url};
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "post"]
|
||||||
|
pub struct Post {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub url: Option<String>,
|
||||||
|
pub body: Option<String>,
|
||||||
|
pub creator_id: i32,
|
||||||
|
pub community_id: i32,
|
||||||
|
pub removed: bool,
|
||||||
|
pub locked: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub stickied: bool,
|
||||||
|
pub embed_title: Option<String>,
|
||||||
|
pub embed_description: Option<String>,
|
||||||
|
pub embed_html: Option<String>,
|
||||||
|
pub thumbnail_url: Option<String>,
|
||||||
|
pub ap_id: String,
|
||||||
|
pub local: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset)]
|
||||||
|
#[table_name = "post"]
|
||||||
|
pub struct PostForm {
|
||||||
|
pub name: String,
|
||||||
|
pub url: Option<String>,
|
||||||
|
pub body: Option<String>,
|
||||||
|
pub creator_id: i32,
|
||||||
|
pub community_id: i32,
|
||||||
|
pub removed: Option<bool>,
|
||||||
|
pub locked: Option<bool>,
|
||||||
|
pub published: Option<chrono::NaiveDateTime>,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub deleted: Option<bool>,
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub stickied: Option<bool>,
|
||||||
|
pub embed_title: Option<String>,
|
||||||
|
pub embed_description: Option<String>,
|
||||||
|
pub embed_html: Option<String>,
|
||||||
|
pub thumbnail_url: Option<String>,
|
||||||
|
pub ap_id: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Post {
|
||||||
|
pub fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
post.filter(id.eq(post_id)).first::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_for_community(
|
||||||
|
conn: &PgConnection,
|
||||||
|
the_community_id: i32,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
post
|
||||||
|
.filter(community_id.eq(the_community_id))
|
||||||
|
.then_order_by(published.desc())
|
||||||
|
.then_order_by(stickied.desc())
|
||||||
|
.limit(20)
|
||||||
|
.load::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
|
||||||
|
diesel::update(post.find(post_id))
|
||||||
|
.set(ap_id.eq(apub_id))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn permadelete_for_creator(
|
||||||
|
conn: &PgConnection,
|
||||||
|
for_creator_id: i32,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
|
||||||
|
let perma_deleted = "*Permananently Deleted*";
|
||||||
|
let perma_deleted_url = "https://deleted.com";
|
||||||
|
|
||||||
|
diesel::update(post.filter(creator_id.eq(for_creator_id)))
|
||||||
|
.set((
|
||||||
|
name.eq(perma_deleted),
|
||||||
|
url.eq(perma_deleted_url),
|
||||||
|
body.eq(perma_deleted),
|
||||||
|
deleted.eq(true),
|
||||||
|
updated.eq(naive_now()),
|
||||||
|
))
|
||||||
|
.get_results::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_deleted(
|
||||||
|
conn: &PgConnection,
|
||||||
|
post_id: i32,
|
||||||
|
new_deleted: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
diesel::update(post.find(post_id))
|
||||||
|
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_removed(
|
||||||
|
conn: &PgConnection,
|
||||||
|
post_id: i32,
|
||||||
|
new_removed: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
diesel::update(post.find(post_id))
|
||||||
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_removed_for_creator(
|
||||||
|
conn: &PgConnection,
|
||||||
|
for_creator_id: i32,
|
||||||
|
for_community_id: Option<i32>,
|
||||||
|
new_removed: bool,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
|
||||||
|
let mut update = diesel::update(post).into_boxed();
|
||||||
|
update = update.filter(creator_id.eq(for_creator_id));
|
||||||
|
|
||||||
|
if let Some(for_community_id) = for_community_id {
|
||||||
|
update = update.filter(community_id.eq(for_community_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
update
|
||||||
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
|
.get_results::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
diesel::update(post.find(post_id))
|
||||||
|
.set(locked.eq(new_locked))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_stickied(
|
||||||
|
conn: &PgConnection,
|
||||||
|
post_id: i32,
|
||||||
|
new_stickied: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::post::dsl::*;
|
||||||
|
diesel::update(post.find(post_id))
|
||||||
|
.set(stickied.eq(new_stickied))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
|
||||||
|
user_id == post_creator_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostForm {
|
||||||
|
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
|
||||||
|
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
|
#[belongs_to(Post)]
|
||||||
|
#[table_name = "post_like"]
|
||||||
|
pub struct PostLike {
|
||||||
|
pub id: i32,
|
||||||
|
pub post_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub score: i16,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
|
#[table_name = "post_like"]
|
||||||
|
pub struct PostLikeForm {
|
||||||
|
pub post_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub score: i16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
|
#[belongs_to(Post)]
|
||||||
|
#[table_name = "post_saved"]
|
||||||
|
pub struct PostSaved {
|
||||||
|
pub id: i32,
|
||||||
|
pub post_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset)]
|
||||||
|
#[table_name = "post_saved"]
|
||||||
|
pub struct PostSavedForm {
|
||||||
|
pub post_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
|
#[belongs_to(Post)]
|
||||||
|
#[table_name = "post_read"]
|
||||||
|
pub struct PostRead {
|
||||||
|
pub id: i32,
|
||||||
|
|
||||||
|
pub post_id: i32,
|
||||||
|
|
||||||
|
pub user_id: i32,
|
||||||
|
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset)]
|
||||||
|
#[table_name = "post_read"]
|
||||||
|
pub struct PostReadForm {
|
||||||
|
pub post_id: i32,
|
||||||
|
|
||||||
|
pub user_id: i32,
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db = { path = "../lemmy_db" }
|
lemmy_db = { path = "../lemmy_db" }
|
||||||
|
lemmy_db_schema = { path = "../lemmy_db_schema" }
|
||||||
lemmy_utils = { path = "../lemmy_utils" }
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
serde = { version = "1.0.118", features = ["derive"] }
|
serde = { version = "1.0.118", features = ["derive"] }
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
|
|
|
@ -8,14 +8,13 @@ pub mod websocket;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
|
||||||
post::Post,
|
|
||||||
user::User_,
|
user::User_,
|
||||||
user_mention::{UserMention, UserMentionForm},
|
user_mention::{UserMention, UserMentionForm},
|
||||||
},
|
},
|
||||||
Crud,
|
Crud,
|
||||||
DbPool,
|
DbPool,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::Comment, post::Post};
|
||||||
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
|
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
|
||||||
use log::error;
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -12,6 +12,7 @@ path = "src/lib.rs"
|
||||||
lemmy_utils = { path = "../lemmy_utils" }
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
lemmy_structs = { path = "../lemmy_structs" }
|
lemmy_structs = { path = "../lemmy_structs" }
|
||||||
lemmy_db = { path = "../lemmy_db" }
|
lemmy_db = { path = "../lemmy_db" }
|
||||||
|
lemmy_db_schema = { path = "../lemmy_db_schema" }
|
||||||
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
|
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
|
||||||
reqwest = { version = "0.10.10", features = ["json"] }
|
reqwest = { version = "0.10.10", features = ["json"] }
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
messages::*,
|
messages::*,
|
||||||
};
|
};
|
||||||
use actix::{Actor, Context, Handler, ResponseFuture};
|
use actix::{Actor, Context, Handler, ResponseFuture};
|
||||||
use lemmy_db::naive_now;
|
use lemmy_db_schema::naive_now;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
|
@ -4,16 +4,17 @@ use diesel::{
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
naive_now,
|
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::Post,
|
|
||||||
private_message::PrivateMessage,
|
private_message::PrivateMessage,
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
},
|
},
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
source::{comment::Comment, post::Post},
|
||||||
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
|
|
Loading…
Reference in a new issue