activity.find(activity_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
- use crate::schema::activity::dsl::*;
- diesel::delete(activity.find(activity_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
use crate::schema::activity::dsl::*;
insert_into(activity)
category.find(category_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, category_id: i32) -> Result<usize, Error> {
- diesel::delete(category.find(category_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> {
insert_into(category)
.values(new_category)
}
impl Likeable<CommentLikeForm> for CommentLike {
- fn read(conn: &PgConnection, comment_id_from: i32) -> Result<Vec<Self>, Error> {
- use crate::schema::comment_like::dsl::*;
- comment_like
- .filter(comment_id.eq(comment_id_from))
- .load::<Self>(conn)
- }
-
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
use crate::schema::comment_like::dsl::*;
insert_into(comment_like)
}
}
-impl CommentLike {
- pub fn from_post(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> {
- use crate::schema::comment_like::dsl::*;
- comment_like
- .filter(post_id.eq(post_id_from))
- .load::<Self>(conn)
- }
-}
-
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Comment)]
#[table_name = "comment_saved"]
.first::<Self>(conn)
}
- pub fn list_local(conn: &PgConnection) -> Result<Vec<Self>, Error> {
- use crate::schema::community::dsl::*;
- community.filter(local.eq(true)).load::<Community>(conn)
- }
-
pub fn update_deleted(
conn: &PgConnection,
community_id: i32,
}
impl CommunityUserBanView {
- pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
- use super::community_view::community_user_ban_view::dsl::*;
- community_user_ban_view
- .filter(community_id.eq(from_community_id))
- .load::<Self>(conn)
- }
-
- pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
- use super::community_view::community_user_ban_view::dsl::*;
- community_user_ban_view
- .filter(user_id.eq(from_user_id))
- .load::<Self>(conn)
- }
-
pub fn get(
conn: &PgConnection,
from_user_id: i32,
fn update(conn: &PgConnection, id: i32, form: &T) -> Result<Self, Error>
where
Self: Sized;
- fn delete(conn: &PgConnection, id: i32) -> Result<usize, Error>
+ fn delete(_conn: &PgConnection, _id: i32) -> Result<usize, Error>
where
- Self: Sized;
+ Self: Sized,
+ {
+ unimplemented!()
+ }
}
pub trait Followable<T> {
}
pub trait Likeable<T> {
- fn read(conn: &PgConnection, id: i32) -> Result<Vec<Self>, Error>
- where
- Self: Sized;
fn like(conn: &PgConnection, form: &T) -> Result<Self, Error>
where
Self: Sized;
mod_remove_post.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_remove_post::dsl::*;
- diesel::delete(mod_remove_post.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::*;
insert_into(mod_remove_post)
mod_lock_post.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_lock_post::dsl::*;
- diesel::delete(mod_lock_post.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::*;
insert_into(mod_lock_post)
mod_sticky_post.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_sticky_post::dsl::*;
- diesel::delete(mod_sticky_post.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
use crate::schema::mod_sticky_post::dsl::*;
insert_into(mod_sticky_post)
mod_remove_comment.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_remove_comment::dsl::*;
- diesel::delete(mod_remove_comment.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::*;
insert_into(mod_remove_comment)
mod_remove_community.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_remove_community::dsl::*;
- diesel::delete(mod_remove_community.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_remove_community::dsl::*;
insert_into(mod_remove_community)
mod_ban_from_community.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_ban_from_community::dsl::*;
- diesel::delete(mod_ban_from_community.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_ban_from_community::dsl::*;
insert_into(mod_ban_from_community)
mod_ban.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_ban::dsl::*;
- diesel::delete(mod_ban.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::*;
insert_into(mod_ban).values(form).get_result::<Self>(conn)
mod_add_community.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_add_community::dsl::*;
- diesel::delete(mod_add_community.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::*;
insert_into(mod_add_community)
mod_add.find(from_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
- use crate::schema::mod_add::dsl::*;
- diesel::delete(mod_add.find(from_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::*;
insert_into(mod_add).values(form).get_result::<Self>(conn)
.find(password_reset_request_id)
.first::<Self>(conn)
}
- fn delete(conn: &PgConnection, password_reset_request_id: i32) -> Result<usize, Error> {
- diesel::delete(password_reset_request.find(password_reset_request_id)).execute(conn)
- }
fn create(conn: &PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> {
insert_into(password_reset_request)
.values(form)
-use crate::{
- naive_now,
- schema::{post, post_like, post_read, post_saved},
- Crud,
- Likeable,
- Readable,
- Saveable,
-};
+use crate::{naive_now, schema::{post, post_like, post_read, post_saved}, Crud, Likeable, Saveable, Readable};
use diesel::{dsl::*, result::Error, *};
use serde::{Deserialize, Serialize};
use url::{ParseError, Url};
}
impl Likeable<PostLikeForm> for PostLike {
- fn read(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> {
- use crate::schema::post_like::dsl::*;
- post_like
- .filter(post_id.eq(post_id_from))
- .load::<Self>(conn)
- }
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use crate::schema::post_like::dsl::*;
insert_into(post_like)
#[table_name = "post_read"]
pub struct PostRead {
pub id: i32,
+
pub post_id: i32,
+
pub user_id: i32,
+
pub published: chrono::NaiveDateTime,
}
#[table_name = "post_read"]
pub struct PostReadForm {
pub post_id: i32,
+
pub user_id: i32,
}
.values(post_read_form)
.get_result::<Self>(conn)
}
+
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
use crate::schema::post_read::dsl::*;
diesel::delete(
// Post Read
let post_read_form = PostReadForm {
- post_id: inserted_post.id,
- user_id: inserted_user.id,
- };
+ post_id: inserted_post.id,
+ user_id: inserted_user.id,
+ };
let inserted_post_read = PostRead::mark_as_read(&conn, &post_read_form).unwrap();
let expected_post_read = PostRead {
- id: inserted_post_read.id,
- post_id: inserted_post.id,
- user_id: inserted_user.id,
- published: inserted_post_read.published,
+ id: inserted_post_read.id,
+ post_id: inserted_post.id,
+ user_id: inserted_user.id,
+ published: inserted_post_read.published,
};
let read_post = Post::read(&conn, inserted_post.id).unwrap();
self
}
- pub fn unread_only(mut self, unread_only: bool) -> Self {
- self.unread_only = unread_only;
- self
- }
-
pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
self.page = page.get_optional();
self
private_message.find(private_message_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, private_message_id: i32) -> Result<usize, Error> {
- use crate::schema::private_message::dsl::*;
- diesel::delete(private_message.find(private_message_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
use crate::schema::private_message::dsl::*;
insert_into(private_message)
site.first::<Self>(conn)
}
- fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
- use crate::schema::site::dsl::*;
- diesel::delete(site.find(site_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
use crate::schema::site::dsl::*;
insert_into(site).values(new_site).get_result::<Self>(conn)
user_mention.find(user_mention_id).first::<Self>(conn)
}
- fn delete(conn: &PgConnection, user_mention_id: i32) -> Result<usize, Error> {
- use crate::schema::user_mention::dsl::*;
- diesel::delete(user_mention.find(user_mention_id)).execute(conn)
- }
-
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
use crate::schema::user_mention::dsl::*;
insert_into(user_mention)
}
impl UserView {
- pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> {
- use super::user_view::user_fast::dsl::*;
- user_fast.find(from_user_id).first::<Self>(conn)
- }
-
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
use super::user_view::user_fast::dsl::*;
use diesel::sql_types::{Nullable, Text};
pub mod settings;
use crate::settings::Settings;
-use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, Utc};
+use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
use itertools::Itertools;
use lettre::{
smtp::{
};
}
-pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime<Utc> {
- DateTime::<Utc>::from_utc(ndt, Utc)
-}
-
pub fn naive_from_unix(time: i64) -> NaiveDateTime {
NaiveDateTime::from_timestamp(time, 0)
}
)
}
- pub fn api_endpoint(&self) -> String {
- format!("{}/api/v1", self.hostname)
- }
-
pub fn get_config_defaults_location() -> String {
env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE_DEFAULTS.to_string())
}
-use diesel::{result::Error, PgConnection};
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
-use lemmy_db::{user::User_, Crud};
+use lemmy_db::user::User_;
use lemmy_utils::settings::Settings;
use serde::{Deserialize, Serialize};
)
.unwrap()
}
-
- pub fn find_by_jwt(conn: &PgConnection, jwt: &str) -> Result<User_, Error> {
- let claims: Claims = Claims::decode(&jwt).expect("Invalid token").claims;
- User_::read(&conn, claims.id)
- }
}
},
blocking,
request::{retry, RecvError},
- routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
DbPool,
LemmyError,
};
static ACTOR_REFETCH_INTERVAL_SECONDS: i64 = 24 * 60 * 60;
static ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG: i64 = 10;
-// Fetch nodeinfo metadata from a remote instance.
-async fn _fetch_node_info(client: &Client, domain: &str) -> Result<NodeInfo, LemmyError> {
- let well_known_uri = Url::parse(&format!(
- "{}://{}/.well-known/nodeinfo",
- get_apub_protocol_string(),
- domain
- ))?;
-
- let well_known = fetch_remote_object::<NodeInfoWellKnown>(client, &well_known_uri).await?;
- let nodeinfo = fetch_remote_object::<NodeInfo>(client, &well_known.links.href).await?;
-
- Ok(nodeinfo)
-}
-
/// Fetch any type of ActivityPub object, handling things like HTTP headers, deserialisation,
/// timeouts etc.
pub async fn fetch_remote_object<Response>(
Err(e) => Err(e.into()),
}
}
-
-// TODO It should not be fetching data from a community outbox.
-// All posts, comments, comment likes, etc should be posts to our community_inbox
-// The only data we should be periodically fetching (if it hasn't been fetched in the last day
-// maybe), is community and user actors
-// and user actors
-// Fetch all posts in the outbox of the given user, and insert them into the database.
-// fn fetch_community_outbox(community: &Community, conn: &PgConnection) -> Result<Vec<Post>, LemmyError> {
-// let outbox_url = Url::parse(&community.get_outbox_url())?;
-// let outbox = fetch_remote_object::<OrderedCollection>(&outbox_url)?;
-// let items = outbox.collection_props.get_many_items_base_boxes();
-
-// Ok(
-// items
-// .context(location_info!())?
-// .map(|obox: &BaseBox| -> Result<PostForm, LemmyError> {
-// let page = obox.clone().to_concrete::<Page>()?;
-// PostForm::from_page(&page, conn)
-// })
-// .map(|pf| upsert_post(&pf?, conn))
-// .collect::<Result<Vec<Post>, LemmyError>>()?,
-// )
-// }
-extern crate lemmy_server;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
pub extern crate lazy_static;
-pub type DbPool = Pool<ConnectionManager<PgConnection>>;
-
-use crate::lemmy_server::actix_web::dev::Service;
use actix::prelude::*;
use actix_web::{
body::Body,
client::Client,
- dev::{ServiceRequest, ServiceResponse},
+ dev::{Service, ServiceRequest, ServiceResponse},
http::{
header::{CACHE_CONTROL, CONTENT_TYPE},
HeaderValue,
pub mod webfinger;
pub mod websocket;
-use crate::{rate_limit::rate_limiter::RateLimiter, websocket::server::ChatServer};
+use crate::websocket::server::ChatServer;
use actix::prelude::*;
use actix_web::*;
use diesel::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
-use std::sync::{Arc, Mutex};
pub type DbPoolParam = web::Data<Pool<ConnectionManager<PgConnection>>>;
-pub type RateLimitParam = web::Data<Arc<Mutex<RateLimiter>>>;
pub type ChatServerParam = web::Data<Addr<ChatServer>>;