Remove dead code #81

Merged
dessalines merged 7 commits from remove-dead-code into main 2020-08-12 12:30:54 +00:00
10 changed files with 4 additions and 95 deletions
Showing only changes of commit 714b5173d5 - Show all commits

View File

@ -196,15 +196,6 @@ impl Likeable<CommentLikeForm> for CommentLike {
} }
} }
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)] #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Comment)] #[belongs_to(Comment)]
#[table_name = "comment_saved"] #[table_name = "comment_saved"]

View File

@ -99,11 +99,6 @@ impl Community {
.first::<Self>(conn) .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( pub fn update_deleted(
conn: &PgConnection, conn: &PgConnection,
community_id: i32, community_id: i32,

View File

@ -386,20 +386,6 @@ pub struct CommunityUserBanView {
} }
impl CommunityUserBanView { 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( pub fn get(
conn: &PgConnection, conn: &PgConnection,
from_user_id: i32, from_user_id: i32,

View File

@ -252,11 +252,6 @@ impl<'a> PostQueryBuilder<'a> {
self 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 { pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
self.page = page.get_optional(); self.page = page.get_optional();
self self

View File

@ -12,7 +12,7 @@ pub extern crate url;
pub mod settings; pub mod settings;
use crate::settings::Settings; use crate::settings::Settings;
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, Utc}; use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
use itertools::Itertools; use itertools::Itertools;
use lettre::{ use lettre::{
smtp::{ smtp::{
@ -43,10 +43,6 @@ macro_rules! location_info {
}; };
} }
pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime<Utc> {
DateTime::<Utc>::from_utc(ndt, Utc)
}
pub fn naive_from_unix(time: i64) -> NaiveDateTime { pub fn naive_from_unix(time: i64) -> NaiveDateTime {
NaiveDateTime::from_timestamp(time, 0) NaiveDateTime::from_timestamp(time, 0)
} }

View File

@ -121,10 +121,6 @@ impl Settings {
) )
} }
pub fn api_endpoint(&self) -> String {
format!("{}/api/v1", self.hostname)
}
dessalines marked this conversation as resolved
Review

Might be a good idea to use this, rather than the hardcoded v1 string in the api.... but I spose we can remove.

Might be a good idea to use this, rather than the hardcoded `v1` string in the api.... but I spose we can remove.
Review

We will only need that once we get a v2 api, and by then it needs to be rewritten anyway. No need to make things more complicated now.

We will only need that once we get a v2 api, and by then it needs to be rewritten anyway. No need to make things more complicated now.
Review

Sounds good.

Sounds good.
pub fn get_config_defaults_location() -> String { pub fn get_config_defaults_location() -> String {
env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE_DEFAULTS.to_string()) env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE_DEFAULTS.to_string())
} }

View File

@ -1,6 +1,5 @@
use diesel::{result::Error, PgConnection};
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; 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 lemmy_utils::settings::Settings;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -37,9 +36,4 @@ impl Claims {
) )
.unwrap() .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)
}
} }

View File

@ -11,7 +11,6 @@ use crate::{
}, },
blocking, blocking,
request::{retry, RecvError}, request::{retry, RecvError},
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
DbPool, DbPool,
LemmyError, LemmyError,
}; };
@ -43,20 +42,6 @@ use url::Url;
static ACTOR_REFETCH_INTERVAL_SECONDS: i64 = 24 * 60 * 60; static ACTOR_REFETCH_INTERVAL_SECONDS: i64 = 24 * 60 * 60;
static ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG: i64 = 10; 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, /// Fetch any type of ActivityPub object, handling things like HTTP headers, deserialisation,
/// timeouts etc. /// timeouts etc.
pub async fn fetch_remote_object<Response>( pub async fn fetch_remote_object<Response>(
@ -447,26 +432,3 @@ pub async fn get_or_fetch_and_insert_comment(
Err(e) => Err(e.into()), 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>>()?,
// )
// }

View File

@ -1,17 +1,13 @@
extern crate lemmy_server;
#[macro_use] #[macro_use]
extern crate diesel_migrations; extern crate diesel_migrations;
#[macro_use] #[macro_use]
pub extern crate lazy_static; pub extern crate lazy_static;
pub type DbPool = Pool<ConnectionManager<PgConnection>>;
use crate::lemmy_server::actix_web::dev::Service;
use actix::prelude::*; use actix::prelude::*;
use actix_web::{ use actix_web::{
body::Body, body::Body,
client::Client, client::Client,
dev::{ServiceRequest, ServiceResponse}, dev::{Service, ServiceRequest, ServiceResponse},
http::{ http::{
header::{CACHE_CONTROL, CONTENT_TYPE}, header::{CACHE_CONTROL, CONTENT_TYPE},
HeaderValue, HeaderValue,

View File

@ -7,15 +7,13 @@ pub mod nodeinfo;
pub mod webfinger; pub mod webfinger;
pub mod websocket; pub mod websocket;
use crate::{rate_limit::rate_limiter::RateLimiter, websocket::server::ChatServer}; use crate::websocket::server::ChatServer;
use actix::prelude::*; use actix::prelude::*;
use actix_web::*; use actix_web::*;
use diesel::{ use diesel::{
r2d2::{ConnectionManager, Pool}, r2d2::{ConnectionManager, Pool},
PgConnection, PgConnection,
}; };
use std::sync::{Arc, Mutex};
pub type DbPoolParam = web::Data<Pool<ConnectionManager<PgConnection>>>; pub type DbPoolParam = web::Data<Pool<ConnectionManager<PgConnection>>>;
pub type RateLimitParam = web::Data<Arc<Mutex<RateLimiter>>>;
pub type ChatServerParam = web::Data<Addr<ChatServer>>; pub type ChatServerParam = web::Data<Addr<ChatServer>>;