]> Untitled Git - lemmy.git/commitdiff
Merge branch 'yerba_rework-imports' into federation
authorDessalines <tyhou13@gmx.com>
Sun, 17 May 2020 01:09:26 +0000 (21:09 -0400)
committerDessalines <tyhou13@gmx.com>
Sun, 17 May 2020 01:09:26 +0000 (21:09 -0400)
15 files changed:
1  2 
server/Cargo.lock
server/Cargo.toml
server/src/api/comment.rs
server/src/apub/activities.rs
server/src/apub/comment.rs
server/src/apub/community.rs
server/src/apub/extensions/signatures.rs
server/src/apub/mod.rs
server/src/apub/post.rs
server/src/apub/shared_inbox.rs
server/src/db/community.rs
server/src/lib.rs
server/src/routes/feeds.rs
server/src/routes/webfinger.rs
server/src/routes/websocket.rs

index c71b81905eea3030d22215c8f67df42c76d919c5,cc43028b58fc3b488e37b41ca5d438f25080e519..0a59a6092de32deff7880674a4ae80946dbeab88
@@@ -26,6 -26,17 +26,17 @@@ dependencies = 
   "syn",
  ]
  
 -source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#3f75e56190bd2e942621e8265435c74132639a47"
+ [[package]]
+ name = "activitystreams-new"
+ version = "0.1.0"
 - "serde 1.0.106",
 - "serde_json 1.0.51",
++source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#2fb52d32bbce9716c76e08579cf5c716366945fe"
+ dependencies = [
+  "activitystreams",
++ "serde 1.0.110",
++ "serde_json 1.0.53",
+  "typed-builder",
+ ]
  [[package]]
  name = "actix"
  version = "0.9.0"
@@@ -864,9 -875,9 +875,9 @@@ dependencies = 
  
  [[package]]
  name = "derive_more"
- version = "0.99.6"
 -version = "0.99.5"
++version = "0.99.7"
  source = "registry+https://github.com/rust-lang/crates.io-index"
- checksum = "46b046a346c374c6c3c84d2070bfe33904504686bdf949c2d8eb22edad3f270c"
 -checksum = "e2323f3f47db9a0e77ce7a300605d8d2098597fc451ed1a97bb1f6411bb550a7"
++checksum = "2127768764f1556535c01b5326ef94bd60ff08dcfbdc544d53e69ed155610f5d"
  dependencies = [
   "proc-macro2",
   "quote",
@@@ -1325,9 -1326,9 +1336,9 @@@ dependencies = 
  
  [[package]]
  name = "hermit-abi"
--version = "0.1.12"
++version = "0.1.13"
  source = "registry+https://github.com/rust-lang/crates.io-index"
--checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
++checksum = "91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71"
  dependencies = [
   "libc",
  ]
@@@ -2119,9 -2109,9 +2131,9 @@@ checksum = "05da548ad6865900e60eaba7f58
  
  [[package]]
  name = "ppv-lite86"
--version = "0.2.6"
++version = "0.2.7"
  source = "registry+https://github.com/rust-lang/crates.io-index"
--checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
++checksum = "d1e4df3c96bec4c7ce0e32fe5960c98ffc869443ec9592a0411ca1ee96e5e2f0"
  
  [[package]]
  name = "pq-sys"
@@@ -2146,9 -2136,9 +2158,9 @@@ checksum = "8e946095f9d3ed29ec38de908c2
  
  [[package]]
  name = "proc-macro2"
- version = "1.0.12"
 -version = "1.0.10"
++version = "1.0.13"
  source = "registry+https://github.com/rust-lang/crates.io-index"
- checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319"
 -checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
++checksum = "53f5ffe53a6b28e37c9c1ce74893477864d64f74778a93a4beb43c8fa167f639"
  dependencies = [
   "unicode-xid",
  ]
@@@ -2781,9 -2771,9 +2793,9 @@@ dependencies = 
  
  [[package]]
  name = "syn"
- version = "1.0.21"
 -version = "1.0.18"
++version = "1.0.22"
  source = "registry+https://github.com/rust-lang/crates.io-index"
- checksum = "4696caa4048ac7ce2bcd2e484b3cef88c1004e41b8e945a277e2c25dc0b72060"
 -checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213"
++checksum = "1425de3c33b0941002740a420b1a906a350b88d08b82b2c8a01035a3f9447bac"
  dependencies = [
   "proc-macro2",
   "quote",
@@@ -2836,18 -2826,18 +2848,18 @@@ dependencies = 
  
  [[package]]
  name = "thiserror"
- version = "1.0.17"
 -version = "1.0.16"
++version = "1.0.18"
  source = "registry+https://github.com/rust-lang/crates.io-index"
- checksum = "467e5ff447618a916519a4e0d62772ab14f434897f3d63f05d8700ef1e9b22c1"
 -checksum = "d12a1dae4add0f0d568eebc7bf142f145ba1aa2544cafb195c76f0f409091b60"
++checksum = "5976891d6950b4f68477850b5b9e5aa64d955961466f9e174363f573e54e8ca7"
  dependencies = [
   "thiserror-impl",
  ]
  
  [[package]]
  name = "thiserror-impl"
- version = "1.0.17"
 -version = "1.0.16"
++version = "1.0.18"
  source = "registry+https://github.com/rust-lang/crates.io-index"
- checksum = "e63c1091225b9834089b429bc4a2e01223470e3183e891582909e9d1c4cb55d9"
 -checksum = "3f34e0c1caaa462fd840ec6b768946ea1e7842620d94fe29d5b847138f521269"
++checksum = "ab81dbd1cd69cd2ce22ecfbdd3bdb73334ba25350649408cc6c085f46d89573d"
  dependencies = [
   "proc-macro2",
   "quote",
index cf680b66992879af2f8ed1b8f28fafa884523018,2c11c1914a22a690160b9ce30f3fb6013765f52c..a28f98e88a4d5644a9f49b0ed0baf99ba41f605d
@@@ -8,10 -11,11 +11,11 @@@ typed-builder = { git = "https://git.as
  diesel = { version = "1.4.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] }
  diesel_migrations = "1.4.0"
  dotenv = "0.15.0"
- activitystreams = "0.6.1"
+ activitystreams = "0.6.2"
+ activitystreams-new = { version = "0.1.0", git = "https://git.asonix.dog/asonix/activitystreams-sketch" }
 -bcrypt = "0.6.2"
 +bcrypt = "0.8.0"
  chrono = { version = "0.4.7", features = ["serde"] }
 -failure = "0.1.5"
 +failure = "0.1.8"
  serde_json = { version = "1.0.48", features = ["preserve_order"]}
  serde = { version = "1.0.105", features = ["derive"] }
  actix = "0.9.0"
index f469b4622b5ed2aa0bc6a81c8e24fd91555a3ee2,40f87ac9c8cce512b1a2aa39de4b8a0366c4fbdc..369cba5c3d399d8483e3033a8ad492a39c7976d4
@@@ -1,4 -1,41 +1,42 @@@
- use super::*;
+ use crate::{
+   api::{APIError, Oper, Perform},
+   apub::{ApubLikeableType, ApubObjectType},
+   db::{
+     comment::*,
+     comment_view::*,
+     community_view::*,
+     moderator::*,
+     post::*,
+     site_view::*,
+     user::*,
+     user_mention::*,
+     user_view::*,
+     Crud,
+     Likeable,
+     ListingType,
+     Saveable,
+     SortType,
+   },
 -  extract_usernames,
+   naive_now,
+   remove_slurs,
++  scrape_text_for_mentions,
+   send_email,
+   settings::Settings,
+   websocket::{
+     server::{JoinCommunityRoom, SendComment},
+     UserOperation,
+     WebsocketInfo,
+   },
++  MentionData,
+ };
+ use diesel::{
+   r2d2::{ConnectionManager, Pool},
+   PgConnection,
+ };
+ use failure::Error;
+ use log::error;
+ use serde::{Deserialize, Serialize};
+ use std::str::FromStr;
  
  #[derive(Serialize, Deserialize)]
  pub struct CreateComment {
Simple merge
index f746fc0ff224ec5f0c733fc11f1743ab4cd8211c,97f9c27246e9026788dce69458d99825223b1247..90e9f07b6cc3bd1a053eaa91c158a9713a50173d
@@@ -1,4 -1,36 +1,42 @@@
- use super::*;
+ use crate::{
+   apub::{
+     activities::{populate_object_props, send_activity},
+     create_apub_response,
+     create_apub_tombstone_response,
+     create_tombstone,
++    fetch_webfinger_url,
+     fetcher::get_or_fetch_and_upsert_remote_user,
+     ActorType,
+     ApubLikeableType,
+     ApubObjectType,
+     FromApub,
+     ToApub,
+   },
+   convert_datetime,
+   db::{
+     activity::insert_activity,
+     comment::{Comment, CommentForm},
+     community::Community,
+     post::Post,
+     user::User_,
+     Crud,
+   },
+   routes::DbPoolParam,
++  scrape_text_for_mentions,
++  MentionData,
+ };
+ use activitystreams::{
+   activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
+   context,
++  link::Mention,
+   object::{kind::NoteType, properties::ObjectProperties, Note, Tombstone},
+ };
+ use actix_web::{body::Body, web::Path, HttpResponse, Result};
+ use diesel::PgConnection;
+ use failure::Error;
++use itertools::Itertools;
++use log::debug;
+ use serde::Deserialize;
  
  #[derive(Deserialize)]
  pub struct CommentQuery {
Simple merge
index 9d4a601066d1d1f46ed0b817d70bf404f4d2f25b,fdd781094bfb381d91e2ee69e0f70722298a5bf4..3b0872061dface89b96f348a1afb54d8c08eea5c
@@@ -9,70 -9,30 +9,34 @@@ pub mod private_message
  pub mod shared_inbox;
  pub mod user;
  pub mod user_inbox;
- use crate::api::community::CommunityResponse;
- use crate::db::activity::insert_activity;
- use crate::websocket::server::SendCommunityRoomMessage;
- use activitystreams::object::kind::{NoteType, PageType};
+ use crate::{
+   apub::extensions::{
+     group_extensions::GroupExtension,
+     page_extension::PageExtension,
+     signatures::{PublicKey, PublicKeyExtension},
+   },
+   convert_datetime,
+   db::user::User_,
++  routes::webfinger::WebFingerResponse,
++  MentionData,
+   Settings,
+ };
  use activitystreams::{
-   activity::{Accept, Create, Delete, Dislike, Follow, Like, Remove, Undo, Update},
-   actor::{kind::GroupType, properties::ApActorProperties, Group, Person},
-   collection::UnorderedCollection,
-   context,
-   endpoint::EndpointProperties,
-   ext::{Ext, Extensible},
-   link::Mention,
-   object::{properties::ObjectProperties, Note, Page, Tombstone},
-   public, BaseBox,
+   activity::Follow,
+   actor::{properties::ApActorProperties, Group, Person},
+   ext::Ext,
+   object::{Page, Tombstone},
  };
- use actix_web::body::Body;
- use actix_web::web::Path;
- use actix_web::{web, HttpRequest, HttpResponse, Result};
- use diesel::result::Error::NotFound;
+ use actix_web::{body::Body, HttpResponse, Result};
+ use chrono::NaiveDateTime;
  use diesel::PgConnection;
  use failure::Error;
- use failure::_core::fmt::Debug;
 +use isahc::prelude::*;
- use itertools::Itertools;
 +use log::debug;
- use serde::{Deserialize, Serialize};
- use std::time::Duration;
+ use serde::Serialize;
  use url::Url;
  
- use crate::api::comment::{send_local_notifs, CommentResponse};
- use crate::api::post::PostResponse;
- use crate::api::site::SearchResponse;
- use crate::api::user::PrivateMessageResponse;
- use crate::db::comment::{Comment, CommentForm, CommentLike, CommentLikeForm};
- use crate::db::comment_view::CommentView;
- use crate::db::community::{
-   Community, CommunityFollower, CommunityFollowerForm, CommunityForm, CommunityModerator,
-   CommunityModeratorForm,
- };
- use crate::db::community_view::{CommunityFollowerView, CommunityModeratorView, CommunityView};
- use crate::db::post::{Post, PostForm, PostLike, PostLikeForm};
- use crate::db::post_view::PostView;
- use crate::db::private_message::{PrivateMessage, PrivateMessageForm};
- use crate::db::private_message_view::PrivateMessageView;
- use crate::db::user::{UserForm, User_};
- use crate::db::user_view::UserView;
- use crate::db::{Crud, Followable, Joinable, Likeable, SearchType};
- use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
- use crate::routes::webfinger::WebFingerResponse;
- use crate::routes::{ChatServerParam, DbPoolParam};
- use crate::websocket::{
-   server::{SendComment, SendPost, SendUserRoomMessage},
-   UserOperation,
- };
- use crate::{convert_datetime, naive_now, scrape_text_for_mentions, MentionData, Settings};
- use crate::apub::extensions::group_extensions::GroupExtension;
- use crate::apub::extensions::page_extension::PageExtension;
- use activities::{populate_object_props, send_activity};
- use chrono::NaiveDateTime;
- use extensions::signatures::verify;
- use extensions::signatures::{sign, PublicKey, PublicKeyExtension};
- use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user};
  type GroupExt = Ext<Ext<Ext<Group, GroupExtension>, ApActorProperties>, PublicKeyExtension>;
  type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
  type PageExt = Ext<Page, PageExtension>;
Simple merge
index b65f3a8a305d3f567d1ca2e397371d555dcc4c43,51b7826df3b9c37f8a59bfdcb611608fa15a375b..91e92f2d54ab6994e48820c3a45058bc37e38788
@@@ -1,4 -1,40 +1,45 @@@
- use super::*;
+ use crate::{
 -  api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
++  api::{
++    comment::{send_local_notifs, CommentResponse},
++    community::CommunityResponse,
++    post::PostResponse,
++  },
+   apub::{
+     extensions::signatures::verify,
+     fetcher::get_or_fetch_and_upsert_remote_user,
+     FromApub,
+     GroupExt,
+     PageExt,
+   },
+   db::{
+     activity::insert_activity,
+     comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+     comment_view::CommentView,
+     community::{Community, CommunityForm},
+     community_view::CommunityView,
+     post::{Post, PostForm, PostLike, PostLikeForm},
+     post_view::PostView,
+     Crud,
+     Likeable,
+   },
+   naive_now,
+   routes::{ChatServerParam, DbPoolParam},
++  scrape_text_for_mentions,
+   websocket::{
+     server::{SendComment, SendCommunityRoomMessage, SendPost},
+     UserOperation,
+   },
+ };
+ use activitystreams::{
+   activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
+   object::Note,
+   BaseBox,
+ };
+ use actix_web::{web, HttpRequest, HttpResponse, Result};
+ use diesel::PgConnection;
+ use failure::{Error, _core::fmt::Debug};
+ use log::debug;
+ use serde::{Deserialize, Serialize};
  
  #[serde(untagged)]
  #[derive(Serialize, Deserialize, Debug)]
index fad19c4c5bbc073569c581518edc98037c66c30f,e7d92318188f4d3c13426d0ac54c68f4d65e3b04..885c9779b0475ad38475f4bcf20751bb4df45d1e
@@@ -1,5 -1,10 +1,9 @@@
- use super::*;
- use crate::schema::{community, community_follower, community_moderator, community_user_ban};
+ use crate::{
+   db::{Bannable, Crud, Followable, Joinable},
+   schema::{community, community_follower, community_moderator, community_user_ban},
 -  settings::Settings,
+ };
+ use diesel::{dsl::*, result::Error, *};
+ use serde::{Deserialize, Serialize};
  
  #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
  #[table_name = "community"]
index b68e2af581fbaf7650bc635f6c4c686a1a477eaf,4630012bf92b73eff0e4bcfa19d52835368ce63c..055cc5f7ab083183c3df58738b176c81e78a03d4
@@@ -40,11 -40,16 +40,17 @@@ use crate::settings::Settings
  use actix_web::dev::ConnectionInfo;
  use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, Utc};
  use isahc::prelude::*;
- use lettre::smtp::authentication::{Credentials, Mechanism};
- use lettre::smtp::extension::ClientId;
- use lettre::smtp::ConnectionReuseParameters;
- use lettre::{ClientSecurity, SmtpClient, Transport};
 +use itertools::Itertools;
+ use lettre::{
+   smtp::{
+     authentication::{Credentials, Mechanism},
+     extension::ClientId,
+     ConnectionReuseParameters,
+   },
+   ClientSecurity,
+   SmtpClient,
+   Transport,
+ };
  use lettre_email::Email;
  use log::error;
  use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
@@@ -236,48 -254,9 +241,52 @@@ pub fn get_ip(conn_info: &ConnectionInf
      .to_string()
  }
  
 +// TODO nothing is done with community / group webfingers yet, so just ignore those for now
 +#[derive(Clone, PartialEq, Eq, Hash)]
 +pub struct MentionData {
 +  pub name: String,
 +  pub domain: String,
 +}
 +
 +impl MentionData {
 +  pub fn is_local(&self) -> bool {
 +    Settings::get().hostname.eq(&self.domain)
 +  }
 +  pub fn full_name(&self) -> String {
 +    format!("@{}@{}", &self.name, &self.domain)
 +  }
 +}
 +
 +pub fn scrape_text_for_mentions(text: &str) -> Vec<MentionData> {
 +  let mut out: Vec<MentionData> = Vec::new();
 +  for caps in WEBFINGER_USER_REGEX.captures_iter(text) {
 +    out.push(MentionData {
 +      name: caps["name"].to_string(),
 +      domain: caps["domain"].to_string(),
 +    });
 +  }
 +  out.into_iter().unique().collect()
 +}
 +
  #[cfg(test)]
  mod tests {
 -  use crate::{extract_usernames, is_email_regex, remove_slurs, slur_check, slurs_vec_to_str};
 +  use crate::{
-     is_email_regex, remove_slurs, scrape_text_for_mentions, slur_check, slurs_vec_to_str,
++    is_email_regex,
++    remove_slurs,
++    scrape_text_for_mentions,
++    slur_check,
++    slurs_vec_to_str,
 +  };
 +
 +  #[test]
 +  fn test_mentions_regex() {
 +    let text = "Just read a great blog post by [@tedu@honk.teduangst.com](/u/test). And another by !test_community@fish.teduangst.com . Another [@lemmy@lemmy_alpha:8540](/u/fish)";
 +    let mentions = scrape_text_for_mentions(text);
 +
 +    assert_eq!(mentions[0].name, "tedu".to_string());
 +    assert_eq!(mentions[0].domain, "honk.teduangst.com".to_string());
 +    assert_eq!(mentions[1].domain, "lemmy_alpha:8540".to_string());
 +  }
  
    #[test]
    fn test_email() {
Simple merge
index 439064ad732e69f8a194e70d2706b3e4c633bb7d,e6ce84110a403cb526cda05149f89946a827cf78..9fa01a1475e63a6f3d3bc05ae881fbddf451432e
@@@ -1,4 -1,8 +1,11 @@@
- use super::*;
 -use crate::{db::community::Community, routes::DbPoolParam, Settings};
++use crate::{
++  db::{community::Community, user::User_},
++  routes::DbPoolParam,
++  Settings,
++};
+ use actix_web::{error::ErrorBadRequest, web::Query, *};
+ use regex::Regex;
 -use serde::Deserialize;
 -use serde_json::json;
++use serde::{Deserialize, Serialize};
  
  #[derive(Deserialize)]
  pub struct Params {
index 8b94965a48f5bf5376561b5999dc5c3d0a05426f,06d9b66d2c45f9f4bbb1cc0e4e833a20efb2d455..e6de7b77bf2b11d5a07ac10205ab36ddb60953fe
@@@ -1,5 -1,12 +1,12 @@@
- use super::*;
- use crate::websocket::server::*;
+ use crate::{
+   get_ip,
+   websocket::server::{ChatServer, *},
+ };
+ use actix::prelude::*;
+ use actix_web::*;
+ use actix_web_actors::ws;
 -use log::{error, info};
++use log::{debug, error, info};
+ use std::time::{Duration, Instant};
  
  /// How often heartbeat pings are sent
  const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);