"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"
[[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",
[[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",
]
[[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"
[[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",
]
[[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",
[[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",
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"
- 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 {
- 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 {
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>;
- 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)]
- 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"]
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};
.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() {
- 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 {
- 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);