"lazy_static",
"lemmy_apub",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
"itertools",
"lazy_static",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_structs",
"lemmy_utils",
"lemmy_websocket",
name = "lemmy_db_schema"
version = "0.1.0"
dependencies = [
+ "chrono",
"diesel",
+ "log",
+ "serde 1.0.118",
+ "serde_json",
+ "url",
]
[[package]]
"chrono",
"diesel",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_utils",
"log",
"serde 1.0.118",
"chrono",
"diesel",
"lemmy_db",
+ "lemmy_db_schema",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
lemmy_apub = { path = "../lemmy_apub" }
lemmy_utils = { path = "../lemmy_utils" }
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
lemmy_websocket = { path = "../lemmy_websocket" }
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
source::{
- comment::*,
comment_report::{CommentReport, CommentReportForm},
moderator::*,
- post::*,
user::*,
},
views::{
Saveable,
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_utils::{
apub::{make_apub_endpoint, EndpointType},
use lemmy_apub::ActorType;
use lemmy_db::{
diesel_option_overwrite,
- naive_now,
- source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
+ source::{community::*, moderator::*, site::*},
views::{
comment_view::CommentQueryBuilder,
community::{
Joinable,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{comment::Comment, post::Post},
+};
use lemmy_structs::{blocking, community::*};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
use lemmy_db::{
source::{
community::{Community, CommunityModerator},
- post::Post,
user::User_,
},
views::community::community_user_ban_view::CommunityUserBanView,
Crud,
DbPool,
};
+use lemmy_db_schema::source::post::Post;
use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
- naive_now,
source::{
moderator::*,
- post::*,
post_report::{PostReport, PostReportForm},
},
views::{
Saveable,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::post::{Post, PostForm, PostLike, PostLikeForm, PostSaved, PostSavedForm},
+};
use lemmy_structs::{blocking, post::*};
use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType},
use lemmy_db::{
aggregates::site_aggregates::SiteAggregates,
diesel_option_overwrite,
- naive_now,
source::{category::*, moderator::*, site::*},
views::{
comment_view::CommentQueryBuilder,
SearchType,
SortType,
};
+use lemmy_db_schema::naive_now;
use lemmy_structs::{blocking, site::*, user::Register};
use lemmy_utils::{
location_info,
use lemmy_apub::ApubObjectType;
use lemmy_db::{
diesel_option_overwrite,
- naive_now,
source::{
- comment::*,
community::*,
moderator::*,
password_reset_request::*,
- post::*,
private_message::*,
site::*,
user::*,
ListingType,
SortType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{comment::Comment, post::Post},
+};
use lemmy_structs::{blocking, send_email_to_user, user::*};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_websocket = { path = "../lemmy_websocket" }
diesel = "1.4.5"
base::ExtendsExt,
};
use anyhow::Context;
-use lemmy_db::{
- source::{
- comment::{Comment, CommentLike, CommentLikeForm},
- post::Post,
- },
- views::comment_view::CommentView,
- Likeable,
+use lemmy_db::{views::comment_view::CommentView, Likeable};
+use lemmy_db_schema::source::{
+ comment::{Comment, CommentLike, CommentLikeForm},
+ post::Post,
};
use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{
- source::comment::{Comment, CommentLike},
- views::comment_view::CommentView,
- Likeable,
-};
+use lemmy_db::{views::comment_view::CommentView, Likeable};
+use lemmy_db_schema::source::comment::{Comment, CommentLike};
use lemmy_structs::{blocking, comment::CommentResponse};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
prelude::*,
};
use anyhow::Context;
-use lemmy_db::{
- source::post::{Post, PostLike, PostLikeForm},
- views::post_view::PostView,
- Likeable,
-};
+use lemmy_db::{views::post_view::PostView, Likeable};
+use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm};
use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{
- source::post::{Post, PostLike},
- views::post_view::PostView,
- Likeable,
-};
+use lemmy_db::{views::post_view::PostView, Likeable};
+use lemmy_db_schema::source::post::{Post, PostLike};
use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
use anyhow::anyhow;
use itertools::Itertools;
use lemmy_db::{
- source::{comment::Comment, community::Community, post::Post, user::User_},
+ source::{community::Community, user::User_},
Crud,
DbPool,
};
+use lemmy_db_schema::source::{comment::Comment, post::Post};
use lemmy_structs::{blocking, WebFingerResponse};
use lemmy_utils::{
request::{retry, RecvError},
public,
};
use lemmy_db::{
- source::{community::Community, post::Post, user::User_},
+ source::{community::Community, user::User_},
Crud,
};
+use lemmy_db_schema::source::post::Post;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use chrono::NaiveDateTime;
use diesel::result::Error::NotFound;
use lemmy_db::{
- naive_now,
source::{
- comment::Comment,
community::{Community, CommunityModerator, CommunityModeratorForm},
- post::Post,
user::User_,
},
views::{
Joinable,
SearchType,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{comment::Comment, post::Post},
+};
use lemmy_structs::{blocking, site::SearchResponse};
use lemmy_utils::{
location_info,
};
use actix_web::{body::Body, web, web::Path, HttpResponse};
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_utils::LemmyError;
use lemmy_websocket::LemmyContext;
};
use actix_web::{body::Body, web, HttpResponse};
use lemmy_db::{
- source::{community::Community, post::Post},
+ source::community::Community,
views::community::community_follower_view::CommunityFollowerView,
};
+use lemmy_db_schema::source::post::Post;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
};
use actix_web::{body::Body, web, HttpResponse};
use diesel::result::Error::NotFound;
-use lemmy_db::source::post::Post;
+use lemmy_db_schema::source::post::Post;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
};
use anyhow::Context;
use diesel::result::Error::NotFound;
-use lemmy_db::{
- source::{comment::Comment, post::Post, site::Site},
- ApubObject,
- Crud,
-};
+use lemmy_db::{source::site::Site, ApubObject, Crud};
+use lemmy_db_schema::source::{comment::Comment, post::Post};
use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
};
use anyhow::{anyhow, Context};
use lemmy_db::{
- source::{
- comment::{Comment, CommentForm},
- community::Community,
- post::Post,
- user::User_,
- },
+ source::{community::Community, user::User_},
Crud,
DbPool,
};
+use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ post::Post,
+};
use lemmy_structs::blocking;
use lemmy_utils::{
location_info,
use activitystreams_ext::Ext2;
use anyhow::Context;
use lemmy_db::{
- naive_now,
source::community::{Community, CommunityForm},
views::community::community_moderator_view::CommunityModeratorView,
DbPool,
};
+use lemmy_db_schema::naive_now;
use lemmy_structs::blocking;
use lemmy_utils::{
location_info,
use activitystreams_ext::Ext1;
use anyhow::Context;
use lemmy_db::{
- source::{
- community::Community,
- post::{Post, PostForm},
- user::User_,
- },
+ source::{community::Community, user::User_},
Crud,
DbPool,
};
+use lemmy_db_schema::source::post::{Post, PostForm};
use lemmy_structs::blocking;
use lemmy_utils::{
location_info,
use activitystreams_ext::Ext1;
use anyhow::Context;
use lemmy_db::{
- naive_now,
source::user::{UserForm, User_},
ApubObject,
DbPool,
};
+use lemmy_db_schema::naive_now;
use lemmy_structs::blocking;
use lemmy_utils::{
location_info,
use crate::{
aggregates::community_aggregates::CommunityAggregates,
source::{
- comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
- post::{Post, PostForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ post::{Post, PostForm},
+ };
#[test]
fn test_crud() {
use crate::{
aggregates::post_aggregates::PostAggregates,
source::{
- comment::{Comment, CommentForm},
community::{Community, CommunityForm},
- post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ post::{Post, PostForm, PostLike, PostLikeForm},
+ };
#[test]
fn test_crud() {
use crate::{
aggregates::site_aggregates::SiteAggregates,
source::{
- comment::{Comment, CommentForm},
community::{Community, CommunityForm},
- post::{Post, PostForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm},
+ post::{Post, PostForm},
+ };
#[test]
fn test_crud() {
use crate::{
aggregates::user_aggregates::UserAggregates,
source::{
- comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
- post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+ post::{Post, PostForm, PostLike, PostLikeForm},
+ };
#[test]
fn test_crud() {
#[macro_use]
extern crate lazy_static;
-use chrono::NaiveDateTime;
use diesel::{result::Error, *};
use regex::Regex;
use serde::{Deserialize, Serialize};
(limit, offset)
}
-pub fn naive_now() -> NaiveDateTime {
- chrono::prelude::Utc::now().naive_utc()
-}
-
pub fn is_email_regex(test: &str) -> bool {
EMAIL_REGEX.is_match(test)
}
-use super::post::Post;
-use crate::{naive_now, ApubObject, Crud, Likeable, Saveable};
+use crate::{ApubObject, Crud, Likeable, Saveable};
use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::schema::{comment, comment_alias_1, comment_like, comment_saved};
-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 CommentForm {
- pub fn get_ap_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
- }
-}
+use lemmy_db_schema::source::comment::{
+ Comment,
+ CommentForm,
+ CommentLike,
+ CommentLikeForm,
+ CommentSaved,
+ CommentSavedForm,
+};
impl Crud<CommentForm> for Comment {
fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
}
}
-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 {
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::comment_like::dsl::*;
}
}
-#[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 {
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::comment_saved::dsl::*;
#[cfg(test)]
mod tests {
use crate::{
- source::{comment::*, community::*, post::*, user::*},
+ source::{community::*, user::*},
tests::establish_unpooled_connection,
Crud,
+ Likeable,
ListingType,
+ Saveable,
SortType,
};
+ use lemmy_db_schema::source::{comment::*, post::*};
#[test]
fn test_crud() {
-use crate::{naive_now, source::comment::Comment, Reportable};
+use crate::Reportable;
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};
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
use crate::{
- naive_now,
views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
ApubObject,
Bannable,
Joinable,
};
use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::schema::{
- community,
- community_follower,
- community_moderator,
- community_user_ban,
+use lemmy_db_schema::{
+ naive_now,
+ schema::{community, community_follower, community_moderator, community_user_ban},
};
use serde::Serialize;
#[cfg(test)]
mod tests {
use crate::{
- source::{comment::*, community::*, moderator::*, post::*, user::*},
+ source::{community::*, moderator::*, user::*},
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{comment::*, post::*};
// use Crud;
#[test]
-use crate::{naive_now, ApubObject, Crud, Likeable, Readable, Saveable};
+use crate::{ApubObject, Crud, Likeable, Readable, Saveable};
use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::schema::{post, post_like, post_read, post_saved};
-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 PostForm {
- pub fn get_ap_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
- }
-}
+use lemmy_db_schema::source::post::{
+ Post,
+ PostForm,
+ PostLike,
+ PostLikeForm,
+ PostRead,
+ PostReadForm,
+ PostSaved,
+ PostSavedForm,
+};
impl Crud<PostForm> for Post {
fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
}
}
-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 {
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::post_like::dsl::*;
}
}
-#[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 {
fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::post_saved::dsl::*;
}
}
-#[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 {
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::post_read::dsl::*;
-use crate::{naive_now, source::post::Post, Reportable};
+use crate::Reportable;
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};
#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
-use crate::{naive_now, ApubObject, Crud};
+use crate::{ApubObject, Crud};
use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::schema::private_message;
+use lemmy_db_schema::{naive_now, schema::private_message};
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-use crate::{naive_now, Crud};
+use crate::Crud;
use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::schema::site;
+use lemmy_db_schema::{naive_now, schema::site};
use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
-use crate::{is_email_regex, naive_now, ApubObject, Crud};
+use crate::{is_email_regex, ApubObject, Crud};
use bcrypt::{hash, DEFAULT_COST};
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 serde::Serialize;
-use super::comment::Comment;
use crate::Crud;
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;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
#[cfg(test)]
mod tests {
use crate::{
- source::{comment::*, community::*, post::*, user::*, user_mention::*},
+ source::{community::*, user::*, user_mention::*},
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::{comment::*, post::*};
#[test]
fn test_crud() {
use crate::{
limit_and_offset,
source::{
- comment::Comment,
comment_report::CommentReport,
community::{Community, CommunitySafe},
- post::Post,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
-use lemmy_db_schema::schema::{
- comment,
- comment_report,
- community,
- post,
- user_,
- user_alias_1,
- user_alias_2,
+use lemmy_db_schema::{
+ schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
+ source::{comment::Comment, post::Post},
};
use serde::Serialize;
fuzzy_search,
limit_and_offset,
source::{
- comment::{Comment, CommentAlias1, CommentSaved},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
- post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
-use lemmy_db_schema::schema::{
- comment,
- comment_aggregates,
- comment_alias_1,
- comment_like,
- comment_saved,
- community,
- community_follower,
- community_user_ban,
- post,
- user_,
- user_alias_1,
+use lemmy_db_schema::{
+ schema::{
+ comment,
+ comment_aggregates,
+ comment_alias_1,
+ comment_like,
+ comment_saved,
+ community,
+ community_follower,
+ community_user_ban,
+ post,
+ user_,
+ user_alias_1,
+ },
+ source::{
+ comment::{Comment, CommentAlias1, CommentSaved},
+ post::Post,
+ },
};
use serde::Serialize;
#[cfg(test)]
mod tests {
use crate::{
- source::{comment::*, community::*, post::*, user::*},
+ source::{community::*, user::*},
tests::establish_unpooled_connection,
views::comment_view::*,
Crud,
Likeable,
*,
};
+ use lemmy_db_schema::source::{comment::*, post::*};
#[test]
fn test_crud() {
source::{
community::{Community, CommunitySafe},
moderator::ModLockPost,
- post::Post,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
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;
#[derive(Debug, Serialize, Clone)]
use crate::{
limit_and_offset,
source::{
- comment::Comment,
community::{Community, CommunitySafe},
moderator::ModRemoveComment,
- post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
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;
#[derive(Debug, Serialize, Clone)]
source::{
community::{Community, CommunitySafe},
moderator::ModRemovePost,
- post::Post,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
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;
#[derive(Debug, Serialize, Clone)]
source::{
community::{Community, CommunitySafe},
moderator::ModStickyPost,
- post::Post,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
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;
#[derive(Debug, Serialize, Clone)]
limit_and_offset,
source::{
community::{Community, CommunitySafe},
- post::Post,
post_report::PostReport,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},
ToSafe,
};
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;
#[derive(Debug, PartialEq, Serialize, Clone)]
limit_and_offset,
source::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
- post::{Post, PostRead, PostSaved},
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
-use lemmy_db_schema::schema::{
- community,
- community_follower,
- community_user_ban,
- post,
- post_aggregates,
- post_like,
- post_read,
- post_saved,
- user_,
+use lemmy_db_schema::{
+ schema::{
+ community,
+ community_follower,
+ community_user_ban,
+ post,
+ post_aggregates,
+ post_like,
+ post_read,
+ post_saved,
+ user_,
+ },
+ source::post::{Post, PostRead, PostSaved},
};
use serde::Serialize;
mod tests {
use crate::{
aggregates::post_aggregates::PostAggregates,
- source::{community::*, post::*, user::*},
+ source::{community::*, user::*},
tests::establish_unpooled_connection,
views::post_view::{PostQueryBuilder, PostView},
Crud,
Likeable,
*,
};
+ use lemmy_db_schema::source::post::*;
#[test]
fn test_crud() {
functions::hot_rank,
limit_and_offset,
source::{
- comment::{Comment, CommentSaved},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
- post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
},
ToSafe,
};
use diesel::{result::Error, *};
-use lemmy_db_schema::schema::{
- comment,
- comment_aggregates,
- comment_like,
- comment_saved,
- community,
- community_follower,
- community_user_ban,
- post,
- user_,
- user_alias_1,
- user_mention,
+use lemmy_db_schema::{
+ schema::{
+ comment,
+ comment_aggregates,
+ comment_like,
+ comment_saved,
+ community,
+ community_follower,
+ community_user_ban,
+ post,
+ user_,
+ user_alias_1,
+ user_mention,
+ },
+ source::{
+ comment::{Comment, CommentSaved},
+ post::Post,
+ },
};
use serde::Serialize;
[dependencies]
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"] }
#[macro_use]
extern crate diesel;
+use chrono::NaiveDateTime;
+
pub mod schema;
+pub mod source;
+
+pub fn naive_now() -> NaiveDateTime {
+ chrono::prelude::Utc::now().naive_utc()
+}
--- /dev/null
+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,
+}
--- /dev/null
+pub mod comment;
+pub mod post;
--- /dev/null
+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,
+}
[dependencies]
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_utils = { path = "../lemmy_utils" }
serde = { version = "1.0.118", features = ["derive"] }
log = "0.4.11"
use diesel::PgConnection;
use lemmy_db::{
source::{
- comment::Comment,
- post::Post,
user::User_,
user_mention::{UserMention, UserMentionForm},
},
Crud,
DbPool,
};
+use lemmy_db_schema::source::{comment::Comment, post::Post};
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error;
use serde::{Deserialize, Serialize};
lemmy_utils = { path = "../lemmy_utils" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
reqwest = { version = "0.10.10", features = ["json"] }
log = "0.4.11"
messages::*,
};
use actix::{Actor, Context, Handler, ResponseFuture};
-use lemmy_db::naive_now;
+use lemmy_db_schema::naive_now;
use log::{error, info};
use rand::Rng;
use serde::Serialize;
*,
};
use lemmy_db::{
- naive_now,
source::{
- comment::Comment,
community::{Community, CommunityForm},
- post::Post,
private_message::PrivateMessage,
user::{UserForm, User_},
},
Crud,
};
+use lemmy_db_schema::{
+ naive_now,
+ source::{comment::Comment, post::Post},
+};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
settings::Settings,