Compare commits

...

8 commits

25 changed files with 59 additions and 263 deletions

View file

@ -34,11 +34,6 @@ impl Crud<ActivityForm> for Activity {
activity.find(activity_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
use crate::schema::activity::dsl::*; use crate::schema::activity::dsl::*;
insert_into(activity) insert_into(activity)

View file

@ -23,10 +23,6 @@ impl Crud<CategoryForm> for Category {
category.find(category_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> {
insert_into(category) insert_into(category)
.values(new_category) .values(new_category)

View file

@ -172,13 +172,6 @@ pub struct CommentLikeForm {
} }
impl Likeable<CommentLikeForm> for CommentLike { 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> { fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
use crate::schema::comment_like::dsl::*; use crate::schema::comment_like::dsl::*;
insert_into(comment_like) insert_into(comment_like)
@ -196,15 +189,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

@ -50,9 +50,12 @@ pub trait Crud<T> {
fn update(conn: &PgConnection, id: i32, form: &T) -> Result<Self, Error> fn update(conn: &PgConnection, id: i32, form: &T) -> Result<Self, Error>
where where
Self: Sized; Self: Sized;
fn delete(conn: &PgConnection, id: i32) -> Result<usize, Error> fn delete(_conn: &PgConnection, _id: i32) -> Result<usize, Error>
where where
Self: Sized; Self: Sized,
{
unimplemented!()
}
} }
pub trait Followable<T> { pub trait Followable<T> {
@ -74,9 +77,6 @@ pub trait Joinable<T> {
} }
pub trait Likeable<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> fn like(conn: &PgConnection, form: &T) -> Result<Self, Error>
where where
Self: Sized; Self: Sized;

View file

@ -41,11 +41,6 @@ impl Crud<ModRemovePostForm> for ModRemovePost {
mod_remove_post.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::*; use crate::schema::mod_remove_post::dsl::*;
insert_into(mod_remove_post) insert_into(mod_remove_post)
@ -85,11 +80,6 @@ impl Crud<ModLockPostForm> for ModLockPost {
mod_lock_post.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::*; use crate::schema::mod_lock_post::dsl::*;
insert_into(mod_lock_post) insert_into(mod_lock_post)
@ -129,11 +119,6 @@ impl Crud<ModStickyPostForm> for ModStickyPost {
mod_sticky_post.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
use crate::schema::mod_sticky_post::dsl::*; use crate::schema::mod_sticky_post::dsl::*;
insert_into(mod_sticky_post) insert_into(mod_sticky_post)
@ -175,11 +160,6 @@ impl Crud<ModRemoveCommentForm> for ModRemoveComment {
mod_remove_comment.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::*; use crate::schema::mod_remove_comment::dsl::*;
insert_into(mod_remove_comment) insert_into(mod_remove_comment)
@ -223,11 +203,6 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
mod_remove_community.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_remove_community::dsl::*; use crate::schema::mod_remove_community::dsl::*;
insert_into(mod_remove_community) insert_into(mod_remove_community)
@ -277,11 +252,6 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
mod_ban_from_community.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_ban_from_community::dsl::*; use crate::schema::mod_ban_from_community::dsl::*;
insert_into(mod_ban_from_community) insert_into(mod_ban_from_community)
@ -329,11 +299,6 @@ impl Crud<ModBanForm> for ModBan {
mod_ban.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::*; use crate::schema::mod_ban::dsl::*;
insert_into(mod_ban).values(form).get_result::<Self>(conn) insert_into(mod_ban).values(form).get_result::<Self>(conn)
@ -373,11 +338,6 @@ impl Crud<ModAddCommunityForm> for ModAddCommunity {
mod_add_community.find(from_id).first::<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> { fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::*; use crate::schema::mod_add_community::dsl::*;
insert_into(mod_add_community) insert_into(mod_add_community)
@ -417,11 +377,6 @@ impl Crud<ModAddForm> for ModAdd {
mod_add.find(from_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::*; use crate::schema::mod_add::dsl::*;
insert_into(mod_add).values(form).get_result::<Self>(conn) insert_into(mod_add).values(form).get_result::<Self>(conn)

View file

@ -28,9 +28,6 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
.find(password_reset_request_id) .find(password_reset_request_id)
.first::<Self>(conn) .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> { fn create(conn: &PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> {
insert_into(password_reset_request) insert_into(password_reset_request)
.values(form) .values(form)

View file

@ -1,11 +1,4 @@
use crate::{ use crate::{naive_now, schema::{post, post_like, post_read, post_saved}, Crud, Likeable, Saveable, Readable};
naive_now,
schema::{post, post_like, post_read, post_saved},
Crud,
Likeable,
Readable,
Saveable,
};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::{ParseError, Url}; use url::{ParseError, Url};
@ -201,12 +194,6 @@ pub struct PostLikeForm {
} }
impl Likeable<PostLikeForm> for PostLike { 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> { fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use crate::schema::post_like::dsl::*; use crate::schema::post_like::dsl::*;
insert_into(post_like) insert_into(post_like)
@ -264,8 +251,11 @@ impl Saveable<PostSavedForm> for PostSaved {
#[table_name = "post_read"] #[table_name = "post_read"]
pub struct PostRead { pub struct PostRead {
pub id: i32, pub id: i32,
pub post_id: i32, pub post_id: i32,
pub user_id: i32, pub user_id: i32,
pub published: chrono::NaiveDateTime, pub published: chrono::NaiveDateTime,
} }
@ -273,6 +263,7 @@ pub struct PostRead {
#[table_name = "post_read"] #[table_name = "post_read"]
pub struct PostReadForm { pub struct PostReadForm {
pub post_id: i32, pub post_id: i32,
pub user_id: i32, pub user_id: i32,
} }
@ -283,6 +274,7 @@ impl Readable<PostReadForm> for PostRead {
.values(post_read_form) .values(post_read_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> { fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
use crate::schema::post_read::dsl::*; use crate::schema::post_read::dsl::*;
diesel::delete( diesel::delete(

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

@ -37,11 +37,6 @@ impl Crud<PrivateMessageForm> for PrivateMessage {
private_message.find(private_message_id).first::<Self>(conn) 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> { fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
use crate::schema::private_message::dsl::*; use crate::schema::private_message::dsl::*;
insert_into(private_message) insert_into(private_message)

View file

@ -39,11 +39,6 @@ impl Crud<SiteForm> for Site {
site.first::<Self>(conn) 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> { fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
use crate::schema::site::dsl::*; use crate::schema::site::dsl::*;
insert_into(site).values(new_site).get_result::<Self>(conn) insert_into(site).values(new_site).get_result::<Self>(conn)

View file

@ -28,11 +28,6 @@ impl Crud<UserMentionForm> for UserMention {
user_mention.find(user_mention_id).first::<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> { fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
use crate::schema::user_mention::dsl::*; use crate::schema::user_mention::dsl::*;
insert_into(user_mention) insert_into(user_mention)

View file

@ -159,11 +159,6 @@ impl<'a> UserQueryBuilder<'a> {
} }
impl UserView { 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> { pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
use super::user_view::user_fast::dsl::*; use super::user_view::user_fast::dsl::*;
use diesel::sql_types::{Nullable, Text}; use diesel::sql_types::{Nullable, Text};

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)
}
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

@ -297,7 +297,7 @@ impl ApubObjectType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -331,7 +331,7 @@ impl ApubObjectType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
@ -339,7 +339,7 @@ impl ApubObjectType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -372,7 +372,7 @@ impl ApubObjectType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&mod_, &mod_,
@ -406,7 +406,7 @@ impl ApubObjectType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@ -414,7 +414,7 @@ impl ApubObjectType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&mod_, &mod_,
@ -450,7 +450,7 @@ impl ApubLikeableType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(LikeType::Like)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -483,7 +483,7 @@ impl ApubLikeableType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?) .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -516,7 +516,7 @@ impl ApubLikeableType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?) .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
@ -524,7 +524,7 @@ impl ApubLikeableType for Comment {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -540,7 +540,7 @@ impl ApubLikeableType for Comment {
} }
struct MentionsAndAddresses { struct MentionsAndAddresses {
addressed_ccs: Vec<String>, addressed_ccs: Vec<Url>,
inboxes: Vec<Url>, inboxes: Vec<Url>,
tags: Vec<Mention>, tags: Vec<Mention>,
} }
@ -564,7 +564,7 @@ async fn collect_non_local_mentions_and_addresses(
client: &Client, client: &Client,
pool: &DbPool, pool: &DbPool,
) -> Result<MentionsAndAddresses, LemmyError> { ) -> Result<MentionsAndAddresses, LemmyError> {
let mut addressed_ccs = vec![community.get_followers_url()]; let mut addressed_ccs = vec![community.get_followers_url()?];
// Add the mention tag // Add the mention tag
let mut tags = Vec::new(); let mut tags = Vec::new();
@ -581,7 +581,7 @@ async fn collect_non_local_mentions_and_addresses(
// TODO should it be fetching it every time? // TODO should it be fetching it every time?
if let Ok(actor_id) = fetch_webfinger_url(mention, client).await { if let Ok(actor_id) = fetch_webfinger_url(mention, client).await {
debug!("mention actor_id: {}", actor_id); debug!("mention actor_id: {}", actor_id);
addressed_ccs.push(actor_id.to_owned().to_string()); addressed_ccs.push(actor_id.to_owned().to_string().parse()?);
let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?; let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?;
let shared_inbox = mention_user.get_shared_inbox_url()?; let shared_inbox = mention_user.get_shared_inbox_url()?;

View file

@ -95,7 +95,7 @@ impl ToApub for Community {
ap_actor ap_actor
.set_preferred_username(self.title.to_owned()) .set_preferred_username(self.title.to_owned())
.set_outbox(self.get_outbox_url()?) .set_outbox(self.get_outbox_url()?)
.set_followers(self.get_followers_url().parse()?) .set_followers(self.get_followers_url()?)
.set_following(self.get_following_url().parse()?) .set_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?) .set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints { .set_endpoints(Endpoints {
@ -174,7 +174,7 @@ impl ActorType for Community {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, delete.clone(), true, pool).await?; insert_activity(self.creator_id, delete.clone(), true, pool).await?;
@ -200,16 +200,14 @@ impl ActorType for Community {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()?]);
// TODO
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, undo.clone(), true, pool).await?; insert_activity(self.creator_id, undo.clone(), true, pool).await?;
@ -235,7 +233,7 @@ impl ActorType for Community {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, remove.clone(), true, pool).await?; insert_activity(mod_.id, remove.clone(), true, pool).await?;
@ -261,7 +259,7 @@ impl ActorType for Community {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@ -269,7 +267,7 @@ impl ActorType for Community {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(LikeType::Like)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, undo.clone(), true, pool).await?; insert_activity(mod_.id, undo.clone(), true, pool).await?;
@ -474,8 +472,7 @@ pub async fn get_apub_community_followers(
let mut collection = UnorderedCollection::new(); let mut collection = UnorderedCollection::new();
collection collection
.set_context(context()) .set_context(context())
// TODO: this needs its own ID .set_id(community.get_followers_url()?)
.set_id(community.actor_id.parse()?)
.set_total_items(community_followers.len() as u64); .set_total_items(community_followers.len() as u64);
Ok(create_apub_response(&collection)) Ok(create_apub_response(&collection))
} }
@ -522,7 +519,7 @@ pub async fn do_announce(
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(AnnounceType::Announce)?) .set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
insert_activity(community.creator_id, announce.clone(), true, pool).await?; insert_activity(community.creator_id, announce.clone(), true, pool).await?;

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>(
@ -161,8 +146,6 @@ pub async fn search_by_apub_id(
let community = get_or_fetch_and_upsert_community(community_uri, client, pool).await?; let community = get_or_fetch_and_upsert_community(community_uri, client, pool).await?;
// TODO Maybe at some point in the future, fetch all the history of a community
// fetch_community_outbox(&c, conn)?;
response.communities = vec![ response.communities = vec![
blocking(pool, move |conn| { blocking(pool, move |conn| {
CommunityView::read(conn, community.id, None) CommunityView::read(conn, community.id, None)
@ -181,24 +164,8 @@ pub async fn search_by_apub_id(
response response
} }
SearchAcceptedObjects::Comment(c) => { SearchAcceptedObjects::Comment(c) => {
let post_url = c
.in_reply_to()
.as_ref()
.context(location_info!())?
.as_many()
.context(location_info!())?;
// TODO: also fetch parent comments if any
let x = post_url
.first()
.context(location_info!())?
.as_xsd_any_uri()
.context(location_info!())?;
let post = fetch_remote_object(client, x).await?;
let post_form = PostForm::from_apub(&post, client, pool, Some(query_url.clone())).await?;
let comment_form = CommentForm::from_apub(&c, client, pool, Some(query_url)).await?; let comment_form = CommentForm::from_apub(&c, client, pool, Some(query_url)).await?;
blocking(pool, move |conn| upsert_post(&post_form, conn)).await??;
let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??; let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??;
response.comments = response.comments =
vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??]; vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??];
@ -447,26 +414,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

@ -328,8 +328,8 @@ pub trait ActorType {
Url::parse(&format!("{}/outbox", &self.actor_id_str())) Url::parse(&format!("{}/outbox", &self.actor_id_str()))
} }
fn get_followers_url(&self) -> String { fn get_followers_url(&self) -> Result<Url, ParseError> {
format!("{}/followers", &self.actor_id_str()) Url::parse(&format!("{}/followers", &self.actor_id_str()))
} }
fn get_following_url(&self) -> String { fn get_following_url(&self) -> String {

View file

@ -316,7 +316,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(CreateType::Create)?) .set_id(generate_activity_id(CreateType::Create)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
creator, creator,
@ -347,7 +347,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UpdateType::Update)?) .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
creator, creator,
@ -377,7 +377,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
creator, creator,
@ -407,7 +407,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
@ -415,7 +415,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
creator, creator,
@ -445,7 +445,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
mod_, mod_,
@ -475,7 +475,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@ -483,7 +483,7 @@ impl ApubObjectType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
mod_, mod_,
@ -516,7 +516,7 @@ impl ApubLikeableType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(LikeType::Like)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -546,7 +546,7 @@ impl ApubLikeableType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?) .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,
@ -576,7 +576,7 @@ impl ApubLikeableType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(LikeType::Like)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity // Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
@ -584,7 +584,7 @@ impl ApubLikeableType for Post {
.set_context(context()) .set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community( send_activity_to_community(
&creator, &creator,

View file

@ -80,7 +80,7 @@ impl ToApub for User_ {
let mut ap_actor = ApActor::new(self.get_inbox_url()?, person); let mut ap_actor = ApActor::new(self.get_inbox_url()?, person);
ap_actor ap_actor
.set_outbox(self.get_outbox_url()?) .set_outbox(self.get_outbox_url()?)
.set_followers(self.get_followers_url().parse()?) .set_followers(self.get_followers_url()?)
.set_following(self.get_following_url().parse()?) .set_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?) .set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints { .set_endpoints(Endpoints {

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>>;