Use re-exported tokio_postgres::GenericClient trait
This commit is contained in:
parent
0e68ea263c
commit
01f56d9ef7
57 changed files with 311 additions and 320 deletions
|
@ -1,7 +1,6 @@
|
|||
use std::path::Path;
|
||||
|
||||
use serde_json::{Value as JsonValue};
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
actors::types::Actor,
|
||||
|
@ -9,6 +8,7 @@ use crate::activitypub::{
|
|||
receiver::{parse_property_value, HandlerError},
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseClient;
|
||||
use crate::models::profiles::{
|
||||
queries::{create_profile, update_profile},
|
||||
types::{
|
||||
|
@ -90,7 +90,7 @@ fn parse_tags(actor: &Actor) -> () {
|
|||
}
|
||||
|
||||
pub async fn create_remote_profile(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
media_dir: &Path,
|
||||
actor: Actor,
|
||||
|
@ -128,7 +128,7 @@ pub async fn create_remote_profile(
|
|||
|
||||
/// Updates remote actor's profile
|
||||
pub async fn update_remote_profile(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
media_dir: &Path,
|
||||
profile: DbActorProfile,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use actix_web::HttpRequest;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::http_signatures::verify::{
|
||||
parse_http_signature,
|
||||
verify_http_signature,
|
||||
|
@ -71,7 +70,7 @@ fn key_id_to_actor_id(key_id: &str) -> Result<String, AuthenticationError> {
|
|||
|
||||
async fn get_signer(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
signer_id: &str,
|
||||
no_fetch: bool,
|
||||
) -> Result<DbActorProfile, AuthenticationError> {
|
||||
|
@ -98,7 +97,7 @@ async fn get_signer(
|
|||
/// Verifies HTTP signature and returns signer
|
||||
pub async fn verify_signed_request(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
request: &HttpRequest,
|
||||
no_fetch: bool,
|
||||
) -> Result<DbActorProfile, AuthenticationError> {
|
||||
|
@ -129,7 +128,7 @@ pub async fn verify_signed_request(
|
|||
/// Verifies JSON signature and returns signer
|
||||
pub async fn verify_signed_activity(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
activity: &Value,
|
||||
no_fetch: bool,
|
||||
) -> Result<DbActorProfile, AuthenticationError> {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
actors::types::Actor,
|
||||
|
@ -10,7 +9,7 @@ use crate::activitypub::{
|
|||
vocabulary::ANNOUNCE,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::types::Post;
|
||||
use crate::models::relationships::queries::get_followers;
|
||||
use crate::models::users::types::User;
|
||||
|
@ -56,7 +55,7 @@ fn build_announce(
|
|||
}
|
||||
|
||||
pub async fn get_announce_recipients(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance_url: &str,
|
||||
current_user: &User,
|
||||
post: &Post,
|
||||
|
@ -76,7 +75,7 @@ pub async fn get_announce_recipients(
|
|||
}
|
||||
|
||||
pub async fn prepare_announce(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
repost: &Post,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
actors::types::Actor,
|
||||
|
@ -16,7 +15,7 @@ use crate::activitypub::{
|
|||
vocabulary::{CREATE, DOCUMENT, HASHTAG, LINK, MENTION, NOTE},
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::queries::get_post_author;
|
||||
use crate::models::posts::types::{Post, Visibility};
|
||||
use crate::models::relationships::queries::{get_followers, get_subscribers};
|
||||
|
@ -206,7 +205,7 @@ pub fn build_create_note(
|
|||
}
|
||||
|
||||
pub async fn get_note_recipients(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
current_user: &User,
|
||||
post: &Post,
|
||||
) -> Result<Vec<Actor>, DatabaseError> {
|
||||
|
@ -239,7 +238,7 @@ pub async fn get_note_recipients(
|
|||
}
|
||||
|
||||
pub async fn prepare_create_note(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
author: &User,
|
||||
post: &Post,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
constants::AP_CONTEXT,
|
||||
|
@ -8,7 +7,7 @@ use crate::activitypub::{
|
|||
vocabulary::{DELETE, NOTE, TOMBSTONE},
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::helpers::add_related_posts;
|
||||
use crate::models::posts::types::Post;
|
||||
use crate::models::users::types::User;
|
||||
|
@ -74,7 +73,7 @@ fn build_delete_note(
|
|||
}
|
||||
|
||||
pub async fn prepare_delete_note(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
author: &User,
|
||||
post: &Post,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -9,7 +8,7 @@ use crate::activitypub::{
|
|||
vocabulary::DELETE,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::relationships::queries::{get_followers, get_following};
|
||||
use crate::models::users::types::User;
|
||||
|
||||
|
@ -45,7 +44,7 @@ fn build_delete_person(
|
|||
}
|
||||
|
||||
async fn get_delete_person_recipients(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
) -> Result<Vec<Actor>, DatabaseError> {
|
||||
let followers = get_followers(db_client, user_id).await?;
|
||||
|
@ -60,7 +59,7 @@ async fn get_delete_person_recipients(
|
|||
}
|
||||
|
||||
pub async fn prepare_delete_person(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
user: &User,
|
||||
) -> Result<OutgoingActivity, DatabaseError> {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -10,7 +9,7 @@ use crate::activitypub::{
|
|||
vocabulary::LIKE,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::types::{Post, Visibility};
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::User;
|
||||
|
@ -67,7 +66,7 @@ fn build_like(
|
|||
}
|
||||
|
||||
pub async fn get_like_recipients(
|
||||
_db_client: &impl GenericClient,
|
||||
_db_client: &impl DatabaseClient,
|
||||
_instance_url: &str,
|
||||
post: &Post,
|
||||
) -> Result<Vec<Actor>, DatabaseError> {
|
||||
|
@ -79,7 +78,7 @@ pub async fn get_like_recipients(
|
|||
}
|
||||
|
||||
pub async fn prepare_like(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
post: &Post,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -9,7 +8,7 @@ use crate::activitypub::{
|
|||
vocabulary::UNDO,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::types::Post;
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::User;
|
||||
|
@ -59,7 +58,7 @@ fn build_undo_announce(
|
|||
}
|
||||
|
||||
pub async fn prepare_undo_announce(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
post: &Post,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -9,7 +8,7 @@ use crate::activitypub::{
|
|||
vocabulary::UNDO,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::types::{Post, Visibility};
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::User;
|
||||
|
@ -58,7 +57,7 @@ fn build_undo_like(
|
|||
}
|
||||
|
||||
pub async fn prepare_undo_like(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
post: &Post,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -10,7 +9,7 @@ use crate::activitypub::{
|
|||
vocabulary::UPDATE,
|
||||
};
|
||||
use crate::config::Instance;
|
||||
use crate::database::{DatabaseError, DatabaseTypeError};
|
||||
use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError};
|
||||
use crate::models::relationships::queries::get_followers;
|
||||
use crate::models::users::types::User;
|
||||
use crate::utils::id::new_uuid;
|
||||
|
@ -55,7 +54,7 @@ pub fn build_update_person(
|
|||
}
|
||||
|
||||
async fn get_update_person_recipients(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
) -> Result<Vec<Actor>, DatabaseError> {
|
||||
let followers = get_followers(db_client, user_id).await?;
|
||||
|
@ -69,7 +68,7 @@ async fn get_update_person_recipients(
|
|||
}
|
||||
|
||||
pub async fn prepare_update_person(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
user: &User,
|
||||
maybe_internal_activity_id: Option<Uuid>,
|
||||
|
|
|
@ -7,10 +7,14 @@ use rsa::RsaPrivateKey;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use tokio::time::sleep;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::config::Instance;
|
||||
use crate::database::{get_database_client, DatabaseError, DbPool};
|
||||
use crate::database::{
|
||||
get_database_client,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
DbPool,
|
||||
};
|
||||
use crate::http_signatures::create::{
|
||||
create_http_signature,
|
||||
HttpSignatureError,
|
||||
|
@ -265,7 +269,7 @@ impl OutgoingActivity {
|
|||
|
||||
pub async fn enqueue(
|
||||
self,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let job_data = OutgoingActivityJobData {
|
||||
activity: self.activity,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
actors::helpers::{create_remote_profile, update_remote_profile},
|
||||
handlers::create::handle_note,
|
||||
|
@ -11,7 +9,7 @@ use crate::activitypub::{
|
|||
types::Object,
|
||||
};
|
||||
use crate::config::{Config, Instance};
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::posts::helpers::get_local_post_by_id;
|
||||
use crate::models::posts::queries::get_post_by_remote_object_id;
|
||||
|
@ -29,7 +27,7 @@ use super::fetchers::{
|
|||
};
|
||||
|
||||
pub async fn get_or_import_profile_by_actor_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
media_dir: &Path,
|
||||
actor_id: &str,
|
||||
|
@ -105,7 +103,7 @@ pub async fn get_or_import_profile_by_actor_id(
|
|||
|
||||
/// Fetches actor profile and saves it into database
|
||||
pub async fn import_profile_by_actor_address(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
media_dir: &Path,
|
||||
actor_address: &ActorAddress,
|
||||
|
@ -135,7 +133,7 @@ pub async fn import_profile_by_actor_address(
|
|||
}
|
||||
|
||||
pub async fn get_or_import_profile_by_actor_address(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
media_dir: &Path,
|
||||
actor_address: &ActorAddress,
|
||||
|
@ -164,7 +162,7 @@ pub async fn get_or_import_profile_by_actor_address(
|
|||
|
||||
pub async fn import_post(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
object_id: String,
|
||||
object_received: Option<Object>,
|
||||
) -> Result<Post, HandlerError> {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
identifiers::parse_local_object_id,
|
||||
|
@ -8,6 +7,7 @@ use crate::activitypub::{
|
|||
vocabulary::FOLLOW,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseClient;
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||
use crate::models::relationships::queries::{
|
||||
|
@ -26,7 +26,7 @@ struct Accept {
|
|||
|
||||
pub async fn handle_accept(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
// Accept(Follow)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
identifiers::parse_local_actor_id,
|
||||
vocabulary::PERSON,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseClient;
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||
use crate::models::relationships::queries::subscribe_opt;
|
||||
|
@ -22,7 +22,7 @@ struct Add {
|
|||
|
||||
pub async fn handle_add(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let activity: Add = serde_json::from_value(activity)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
fetcher::helpers::{get_or_import_profile_by_actor_id, import_post},
|
||||
|
@ -9,7 +8,7 @@ use crate::activitypub::{
|
|||
vocabulary::{CREATE, DISLIKE, LIKE, NOTE, UNDO, UPDATE},
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::posts::queries::{
|
||||
create_post,
|
||||
|
@ -28,7 +27,7 @@ struct Announce {
|
|||
|
||||
pub async fn handle_announce(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
if let Some(CREATE | DISLIKE | LIKE | UNDO | UPDATE) =
|
||||
|
|
|
@ -3,7 +3,6 @@ use std::path::Path;
|
|||
|
||||
use chrono::Utc;
|
||||
use serde_json::{Value as JsonValue};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -20,7 +19,7 @@ use crate::activitypub::{
|
|||
vocabulary::*,
|
||||
};
|
||||
use crate::config::{Config, Instance};
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::{ConversionError, ValidationError};
|
||||
use crate::models::attachments::queries::create_attachment;
|
||||
use crate::models::emojis::queries::{
|
||||
|
@ -158,7 +157,7 @@ fn is_gnu_social_link(author_id: &str, attachment: &Attachment) -> bool {
|
|||
}
|
||||
|
||||
pub async fn handle_note(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
media_dir: &Path,
|
||||
object: Object,
|
||||
|
@ -524,7 +523,7 @@ pub async fn handle_note(
|
|||
|
||||
pub async fn handle_create(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: JsonValue,
|
||||
is_authenticated: bool,
|
||||
) -> HandlerResult {
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
receiver::deserialize_into_object_id,
|
||||
vocabulary::{NOTE, PERSON},
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::posts::queries::{
|
||||
delete_post,
|
||||
|
@ -28,7 +27,7 @@ struct Delete {
|
|||
|
||||
pub async fn handle_delete(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let activity: Delete = serde_json::from_value(activity)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
builders::accept_follow::prepare_accept_follow,
|
||||
|
@ -10,7 +9,7 @@ use crate::activitypub::{
|
|||
vocabulary::PERSON,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::{
|
||||
relationships::queries::{
|
||||
|
@ -31,7 +30,7 @@ struct Follow {
|
|||
|
||||
pub async fn handle_follow(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
// Follow(Person)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
fetcher::helpers::get_or_import_profile_by_actor_id,
|
||||
|
@ -9,7 +8,7 @@ use crate::activitypub::{
|
|||
vocabulary::NOTE,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::reactions::queries::create_reaction;
|
||||
use crate::models::posts::queries::get_post_by_remote_object_id;
|
||||
|
@ -25,7 +24,7 @@ struct Like {
|
|||
|
||||
pub async fn handle_like(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let activity: Like = serde_json::from_value(activity)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
builders::{
|
||||
|
@ -13,7 +12,7 @@ use crate::activitypub::{
|
|||
vocabulary::PERSON,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::{
|
||||
notifications::queries::create_move_notification,
|
||||
|
@ -36,7 +35,7 @@ struct Move {
|
|||
|
||||
pub async fn handle_move(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
// Move(Person)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
identifiers::parse_local_object_id,
|
||||
|
@ -8,6 +7,7 @@ use crate::activitypub::{
|
|||
vocabulary::FOLLOW,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseClient;
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||
use crate::models::relationships::queries::{
|
||||
|
@ -26,7 +26,7 @@ struct Reject {
|
|||
|
||||
pub async fn handle_reject(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
// Reject(Follow)
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
identifiers::parse_local_actor_id,
|
||||
vocabulary::PERSON,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::notifications::queries::{
|
||||
create_subscription_expiration_notification,
|
||||
|
@ -26,7 +25,7 @@ struct Remove {
|
|||
|
||||
pub async fn handle_remove(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let activity: Remove = serde_json::from_value(activity)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
identifiers::parse_local_actor_id,
|
||||
|
@ -8,7 +7,7 @@ use crate::activitypub::{
|
|||
vocabulary::{ANNOUNCE, FOLLOW, LIKE},
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::{
|
||||
posts::queries::{
|
||||
|
@ -38,7 +37,7 @@ struct UndoFollow {
|
|||
|
||||
async fn handle_undo_follow(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let activity: UndoFollow = serde_json::from_value(activity)
|
||||
|
@ -72,7 +71,7 @@ struct Undo {
|
|||
|
||||
pub async fn handle_undo(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
if let Some(FOLLOW) = activity["object"]["type"].as_str() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use chrono::Utc;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::{
|
||||
actors::{
|
||||
|
@ -13,7 +12,7 @@ use crate::activitypub::{
|
|||
vocabulary::{NOTE, PERSON},
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::{
|
||||
posts::queries::{
|
||||
|
@ -26,7 +25,7 @@ use crate::models::{
|
|||
use super::HandlerResult;
|
||||
|
||||
async fn handle_update_note(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let object: Object = serde_json::from_value(activity["object"].to_owned())
|
||||
|
@ -55,7 +54,7 @@ struct UpdatePerson {
|
|||
|
||||
async fn handle_update_person(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let activity: UpdatePerson = serde_json::from_value(activity)
|
||||
|
@ -79,7 +78,7 @@ async fn handle_update_person(
|
|||
|
||||
pub async fn handle_update(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: Value,
|
||||
) -> HandlerResult {
|
||||
let object_type = activity["object"]["type"].as_str()
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use chrono::{Duration, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::database::{
|
||||
get_database_client,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
DatabaseTypeError,
|
||||
DbPool,
|
||||
|
@ -41,7 +41,7 @@ impl IncomingActivityJobData {
|
|||
|
||||
pub async fn into_job(
|
||||
self,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
delay: i64,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let job_data = serde_json::to_value(self)
|
||||
|
@ -58,7 +58,7 @@ impl IncomingActivityJobData {
|
|||
|
||||
pub async fn process_queued_incoming_activities(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let batch_size = 10;
|
||||
let max_retries = 2;
|
||||
|
@ -111,7 +111,7 @@ pub struct OutgoingActivityJobData {
|
|||
impl OutgoingActivityJobData {
|
||||
pub async fn into_job(
|
||||
self,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let job_data = serde_json::to_value(self)
|
||||
.expect("activity should be serializable");
|
||||
|
|
|
@ -6,10 +6,9 @@ use serde::{
|
|||
de::Error as DeserializerError,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::{
|
||||
ConversionError,
|
||||
HttpError,
|
||||
|
@ -145,7 +144,7 @@ pub fn deserialize_into_object_id<'de, D>(
|
|||
|
||||
pub async fn handle_activity(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
activity: &Value,
|
||||
is_authenticated: bool,
|
||||
) -> Result<(), HandlerError> {
|
||||
|
@ -211,7 +210,7 @@ pub async fn handle_activity(
|
|||
|
||||
pub async fn receive_activity(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
request: &HttpRequest,
|
||||
activity: &Value,
|
||||
) -> Result<(), HandlerError> {
|
||||
|
|
30
src/cli.rs
30
src/cli.rs
|
@ -1,7 +1,6 @@
|
|||
use anyhow::{anyhow, Error};
|
||||
use chrono::{Duration, Utc};
|
||||
use clap::Parser;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -11,6 +10,7 @@ use crate::activitypub::{
|
|||
fetcher::fetchers::fetch_actor,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseClient;
|
||||
use crate::ethereum::signatures::generate_ecdsa_key;
|
||||
use crate::ethereum::sync::save_current_block_number;
|
||||
use crate::ethereum::utils::key_to_ethereum_address;
|
||||
|
@ -108,7 +108,7 @@ pub struct GenerateInviteCode;
|
|||
impl GenerateInviteCode {
|
||||
pub async fn execute(
|
||||
&self,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let invite_code = create_invite_code(db_client).await?;
|
||||
println!("generated invite code: {}", invite_code);
|
||||
|
@ -123,7 +123,7 @@ pub struct ListInviteCodes;
|
|||
impl ListInviteCodes {
|
||||
pub async fn execute(
|
||||
&self,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let invite_codes = get_invite_codes(db_client).await?;
|
||||
if invite_codes.is_empty() {
|
||||
|
@ -147,7 +147,7 @@ pub struct SetPassword {
|
|||
impl SetPassword {
|
||||
pub async fn execute(
|
||||
&self,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let password_hash = hash_password(&self.password)?;
|
||||
set_user_password(db_client, &self.id, password_hash).await?;
|
||||
|
@ -168,7 +168,7 @@ impl RefetchActor {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let profile = get_profile_by_remote_actor_id(
|
||||
db_client,
|
||||
|
@ -197,7 +197,7 @@ impl DeleteProfile {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let profile = get_profile_by_id(db_client, &self.id).await?;
|
||||
let mut maybe_delete_person = None;
|
||||
|
@ -228,7 +228,7 @@ impl DeletePost {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let post = get_post_by_id(db_client, &self.id).await?;
|
||||
let mut maybe_delete_note = None;
|
||||
|
@ -263,7 +263,7 @@ impl DeleteEmoji {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let deletion_queue = delete_emoji(db_client, &self.id).await?;
|
||||
deletion_queue.process(config).await;
|
||||
|
@ -282,7 +282,7 @@ impl DeleteExtraneousPosts {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let updated_before = Utc::now() - Duration::days(self.days);
|
||||
let posts = find_extraneous_posts(db_client, &updated_before).await?;
|
||||
|
@ -305,7 +305,7 @@ impl DeleteUnusedAttachments {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let created_before = Utc::now() - Duration::days(self.days);
|
||||
let deletion_queue = delete_unused_attachments(
|
||||
|
@ -326,7 +326,7 @@ impl DeleteOrphanedFiles {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let media_dir = config.media_dir();
|
||||
let mut files = vec![];
|
||||
|
@ -355,7 +355,7 @@ impl DeleteEmptyProfiles {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let updated_before = Utc::now() - Duration::days(self.days);
|
||||
let profiles = find_empty_profiles(db_client, &updated_before).await?;
|
||||
|
@ -379,7 +379,7 @@ impl UpdateCurrentBlock {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
_db_client: &impl GenericClient,
|
||||
_db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
save_current_block_number(&config.storage_dir, self.number)?;
|
||||
println!("current block updated");
|
||||
|
@ -399,7 +399,7 @@ impl ResetSubscriptions {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
_config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
reset_subscriptions(db_client, self.ethereum_contract_replaced).await?;
|
||||
println!("subscriptions deleted");
|
||||
|
@ -443,7 +443,7 @@ impl CheckExpiredInvoice {
|
|||
pub async fn execute(
|
||||
&self,
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<(), Error> {
|
||||
let monero_config = config.blockchain()
|
||||
.and_then(|conf| conf.monero_config())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use tokio_postgres::config::{Config as DbConfig};
|
||||
use tokio_postgres::config::{Config as DatabaseConfig};
|
||||
use tokio_postgres::error::{Error as PgError, SqlState};
|
||||
|
||||
pub mod int_enum;
|
||||
|
@ -10,6 +10,7 @@ pub mod query_macro;
|
|||
pub mod test_utils;
|
||||
|
||||
pub type DbPool = deadpool_postgres::Pool;
|
||||
pub use tokio_postgres::{GenericClient as DatabaseClient};
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
#[error("database type error")]
|
||||
|
@ -36,7 +37,9 @@ pub enum DatabaseError {
|
|||
AlreadyExists(&'static str), // object type
|
||||
}
|
||||
|
||||
pub async fn create_database_client(db_config: &DbConfig) -> tokio_postgres::Client {
|
||||
pub async fn create_database_client(db_config: &DatabaseConfig)
|
||||
-> tokio_postgres::Client
|
||||
{
|
||||
let (client, connection) = db_config.connect(tokio_postgres::NoTls)
|
||||
.await.unwrap();
|
||||
tokio::spawn(async move {
|
||||
|
@ -73,8 +76,8 @@ pub fn catch_unique_violation(
|
|||
if let Some(code) = err.code() {
|
||||
if code == &SqlState::UNIQUE_VIOLATION {
|
||||
return DatabaseError::AlreadyExists(object_type);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
err.into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::convert::TryInto;
|
||||
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use web3::{
|
||||
api::Web3,
|
||||
|
@ -17,7 +16,12 @@ use crate::activitypub::builders::{
|
|||
};
|
||||
use crate::activitypub::identifiers::LocalActorCollection;
|
||||
use crate::config::{EthereumConfig, Instance};
|
||||
use crate::database::{get_database_client, DatabaseError, DbPool};
|
||||
use crate::database::{
|
||||
get_database_client,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
DbPool,
|
||||
};
|
||||
use crate::errors::ConversionError;
|
||||
use crate::models::notifications::queries::{
|
||||
create_subscription_notification,
|
||||
|
@ -64,7 +68,7 @@ fn u256_to_date(value: U256) -> Result<DateTime<Utc>, ConversionError> {
|
|||
}
|
||||
|
||||
pub async fn send_subscription_notifications(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
sender: &DbActorProfile,
|
||||
recipient: &User,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::builders::follow::prepare_follow;
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::{
|
||||
profiles::types::DbActorProfile,
|
||||
relationships::queries::{
|
||||
|
@ -17,7 +16,7 @@ use crate::models::{
|
|||
use super::types::RelationshipMap;
|
||||
|
||||
pub async fn follow_or_create_request(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
current_user: &User,
|
||||
target_profile: &DbActorProfile,
|
||||
|
@ -51,7 +50,7 @@ pub async fn follow_or_create_request(
|
|||
}
|
||||
|
||||
pub async fn get_relationship(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<RelationshipMap, DatabaseError> {
|
||||
|
@ -112,7 +111,7 @@ mod tests {
|
|||
use crate::models::users::types::{User, UserCreateData};
|
||||
use super::*;
|
||||
|
||||
async fn create_users(db_client: &mut impl GenericClient)
|
||||
async fn create_users(db_client: &mut impl DatabaseClient)
|
||||
-> Result<(User, User), DatabaseError>
|
||||
{
|
||||
let user_data_1 = UserCreateData {
|
||||
|
|
|
@ -5,15 +5,14 @@ use actix_web::{
|
|||
middleware::{ErrorHandlerResponse, ErrorHandlers},
|
||||
};
|
||||
use serde_json::json;
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::HttpError;
|
||||
use crate::models::oauth::queries::get_user_by_oauth_token;
|
||||
use crate::models::users::types::User;
|
||||
|
||||
pub async fn get_current_user(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
token: &str,
|
||||
) -> Result<User, HttpError> {
|
||||
let user = get_user_by_oauth_token(db_client, token).await.map_err(|err| {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use regex::Regex;
|
||||
use tokio_postgres::GenericClient;
|
||||
use url::Url;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -14,7 +13,7 @@ use crate::activitypub::{
|
|||
HandlerError,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::{HttpError, ValidationError};
|
||||
use crate::identity::did::Did;
|
||||
use crate::mastodon_api::accounts::types::Account;
|
||||
|
@ -101,7 +100,7 @@ fn parse_search_query(search_query: &str) -> SearchQuery {
|
|||
|
||||
async fn search_profiles_or_import(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
username: String,
|
||||
mut maybe_hostname: Option<String>,
|
||||
limit: u16,
|
||||
|
@ -150,7 +149,7 @@ async fn search_profiles_or_import(
|
|||
/// Finds post by its object ID
|
||||
async fn find_post_by_url(
|
||||
config: &Config,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
url: &str,
|
||||
) -> Result<Option<Post>, DatabaseError> {
|
||||
let maybe_post = match parse_local_object_id(
|
||||
|
@ -185,7 +184,7 @@ async fn find_post_by_url(
|
|||
|
||||
async fn find_profile_by_url(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
url: &str,
|
||||
) -> Result<Option<DbActorProfile>, DatabaseError> {
|
||||
let profile = match parse_local_actor_id(
|
||||
|
@ -217,7 +216,7 @@ async fn find_profile_by_url(
|
|||
pub async fn search(
|
||||
config: &Config,
|
||||
current_user: &User,
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
search_query: &str,
|
||||
limit: u16,
|
||||
) -> Result<SearchResults, HttpError> {
|
||||
|
@ -293,7 +292,7 @@ pub async fn search(
|
|||
|
||||
pub async fn search_profiles_only(
|
||||
config: &Config,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
search_query: &str,
|
||||
limit: u16,
|
||||
) -> Result<Vec<Account>, HttpError> {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::{
|
||||
|
@ -6,7 +5,12 @@ use crate::activitypub::{
|
|||
HandlerError,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::database::{get_database_client, DatabaseError, DbPool};
|
||||
use crate::database::{
|
||||
get_database_client,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
DbPool,
|
||||
};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::mastodon_api::accounts::helpers::follow_or_create_request;
|
||||
use crate::models::{
|
||||
|
@ -30,7 +34,7 @@ fn export_profiles_to_csv(
|
|||
}
|
||||
|
||||
pub async fn export_followers(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
local_hostname: &str,
|
||||
user_id: &Uuid,
|
||||
) -> Result<String, DatabaseError> {
|
||||
|
@ -40,7 +44,7 @@ pub async fn export_followers(
|
|||
}
|
||||
|
||||
pub async fn export_follows(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
local_hostname: &str,
|
||||
user_id: &Uuid,
|
||||
) -> Result<String, DatabaseError> {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config::Instance;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::{
|
||||
posts::{
|
||||
hashtags::{find_hashtags, replace_hashtags},
|
||||
|
@ -24,7 +23,7 @@ pub struct PostContent {
|
|||
}
|
||||
|
||||
pub async fn parse_microsyntaxes(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: &Instance,
|
||||
mut content: String,
|
||||
) -> Result<PostContent, DatabaseError> {
|
||||
|
@ -65,7 +64,7 @@ pub async fn parse_microsyntaxes(
|
|||
|
||||
/// Load related objects and build status for API response
|
||||
pub async fn build_status(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance_url: &str,
|
||||
user: Option<&User>,
|
||||
mut post: Post,
|
||||
|
@ -79,7 +78,7 @@ pub async fn build_status(
|
|||
}
|
||||
|
||||
pub async fn build_status_list(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance_url: &str,
|
||||
user: Option<&User>,
|
||||
mut posts: Vec<Post>,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::cleanup::{
|
||||
find_orphaned_files,
|
||||
find_orphaned_ipfs_objects,
|
||||
|
@ -12,7 +11,7 @@ use crate::utils::id::new_uuid;
|
|||
use super::types::DbMediaAttachment;
|
||||
|
||||
pub async fn create_attachment(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
owner_id: &Uuid,
|
||||
file_name: String,
|
||||
media_type: Option<String>,
|
||||
|
@ -31,7 +30,7 @@ pub async fn create_attachment(
|
|||
}
|
||||
|
||||
pub async fn set_attachment_ipfs_cid(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
attachment_id: &Uuid,
|
||||
ipfs_cid: &str,
|
||||
) -> Result<DbMediaAttachment, DatabaseError> {
|
||||
|
@ -50,7 +49,7 @@ pub async fn set_attachment_ipfs_cid(
|
|||
}
|
||||
|
||||
pub async fn delete_unused_attachments(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
created_before: &DateTime<Utc>,
|
||||
) -> Result<DeletionQueue, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde_json::Value;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use super::types::{DbBackgroundJob, JobStatus, JobType};
|
||||
|
||||
pub async fn enqueue_job(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
job_type: &JobType,
|
||||
job_data: &Value,
|
||||
scheduled_for: &DateTime<Utc>,
|
||||
|
@ -29,7 +28,7 @@ pub async fn enqueue_job(
|
|||
}
|
||||
|
||||
pub async fn get_job_batch(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
job_type: &JobType,
|
||||
batch_size: i64,
|
||||
) -> Result<Vec<DbBackgroundJob>, DatabaseError> {
|
||||
|
@ -65,7 +64,7 @@ pub async fn get_job_batch(
|
|||
}
|
||||
|
||||
pub async fn delete_job_from_queue(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
job_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let deleted_count = db_client.execute(
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::ipfs::store as ipfs_store;
|
||||
use crate::utils::files::remove_files;
|
||||
|
||||
|
@ -31,7 +29,7 @@ impl DeletionQueue {
|
|||
}
|
||||
|
||||
pub async fn find_orphaned_files(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
files: Vec<String>,
|
||||
) -> Result<Vec<String>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -61,7 +59,7 @@ pub async fn find_orphaned_files(
|
|||
}
|
||||
|
||||
pub async fn find_orphaned_ipfs_objects(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
ipfs_objects: Vec<String>,
|
||||
) -> Result<Vec<String>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{catch_unique_violation, DatabaseError};
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::models::{
|
||||
cleanup::{find_orphaned_files, DeletionQueue},
|
||||
instances::queries::create_instance,
|
||||
|
@ -12,7 +15,7 @@ use crate::utils::id::new_uuid;
|
|||
use super::types::DbEmoji;
|
||||
|
||||
pub async fn create_emoji(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
emoji_name: &str,
|
||||
hostname: Option<&str>,
|
||||
file_name: &str,
|
||||
|
@ -55,7 +58,7 @@ pub async fn create_emoji(
|
|||
}
|
||||
|
||||
pub async fn update_emoji(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
emoji_id: &Uuid,
|
||||
file_name: &str,
|
||||
media_type: &str,
|
||||
|
@ -85,7 +88,7 @@ pub async fn update_emoji(
|
|||
}
|
||||
|
||||
pub async fn get_emoji_by_remote_object_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
object_id: &str,
|
||||
) -> Result<DbEmoji, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -101,7 +104,7 @@ pub async fn get_emoji_by_remote_object_id(
|
|||
}
|
||||
|
||||
pub async fn delete_emoji(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
emoji_id: &Uuid,
|
||||
) -> Result<DeletionQueue, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
|
||||
pub async fn create_instance(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
hostname: &str,
|
||||
) -> Result<(), DatabaseError> {
|
||||
db_client.execute(
|
||||
|
@ -17,7 +15,7 @@ pub async fn create_instance(
|
|||
}
|
||||
|
||||
pub async fn get_peer_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<i64, DatabaseError> {
|
||||
let row = db_client.query_one(
|
||||
"SELECT count(instance) FROM instance",
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{catch_unique_violation, DatabaseError};
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::utils::caip2::ChainId;
|
||||
use crate::utils::id::new_uuid;
|
||||
use super::types::{DbInvoice, InvoiceStatus};
|
||||
|
||||
pub async fn create_invoice(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
chain_id: &ChainId,
|
||||
|
@ -42,7 +45,7 @@ pub async fn create_invoice(
|
|||
}
|
||||
|
||||
pub async fn get_invoice_by_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
invoice_id: &Uuid,
|
||||
) -> Result<DbInvoice, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -58,7 +61,7 @@ pub async fn get_invoice_by_id(
|
|||
}
|
||||
|
||||
pub async fn get_invoice_by_address(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
chain_id: &ChainId,
|
||||
payment_address: &str,
|
||||
) -> Result<DbInvoice, DatabaseError> {
|
||||
|
@ -75,7 +78,7 @@ pub async fn get_invoice_by_address(
|
|||
}
|
||||
|
||||
pub async fn get_invoices_by_status(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
chain_id: &ChainId,
|
||||
status: InvoiceStatus,
|
||||
) -> Result<Vec<DbInvoice>, DatabaseError> {
|
||||
|
@ -93,7 +96,7 @@ pub async fn get_invoices_by_status(
|
|||
}
|
||||
|
||||
pub async fn set_invoice_status(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
invoice_id: &Uuid,
|
||||
status: InvoiceStatus,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use super::types::{DbTimelineMarker, Timeline};
|
||||
|
||||
pub async fn create_or_update_marker(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
timeline: Timeline,
|
||||
last_read_id: String,
|
||||
|
@ -25,7 +24,7 @@ pub async fn create_or_update_marker(
|
|||
}
|
||||
|
||||
pub async fn get_marker_opt(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
timeline: Timeline,
|
||||
) -> Result<Option<DbTimelineMarker>, DatabaseError> {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::helpers::{add_related_posts, add_user_actions};
|
||||
use crate::models::posts::queries::{
|
||||
RELATED_ATTACHMENTS,
|
||||
|
@ -13,7 +12,7 @@ use crate::models::posts::queries::{
|
|||
use super::types::{EventType, Notification};
|
||||
|
||||
async fn create_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
post_id: Option<&Uuid>,
|
||||
|
@ -35,7 +34,7 @@ async fn create_notification(
|
|||
}
|
||||
|
||||
pub async fn create_follow_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -46,7 +45,7 @@ pub async fn create_follow_notification(
|
|||
}
|
||||
|
||||
pub async fn create_reply_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
|
@ -58,7 +57,7 @@ pub async fn create_reply_notification(
|
|||
}
|
||||
|
||||
pub async fn create_reaction_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
|
@ -70,7 +69,7 @@ pub async fn create_reaction_notification(
|
|||
}
|
||||
|
||||
pub async fn create_mention_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
|
@ -82,7 +81,7 @@ pub async fn create_mention_notification(
|
|||
}
|
||||
|
||||
pub async fn create_repost_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
|
@ -94,7 +93,7 @@ pub async fn create_repost_notification(
|
|||
}
|
||||
|
||||
pub async fn create_subscription_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -105,7 +104,7 @@ pub async fn create_subscription_notification(
|
|||
}
|
||||
|
||||
pub async fn create_subscription_expiration_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -116,7 +115,7 @@ pub async fn create_subscription_expiration_notification(
|
|||
}
|
||||
|
||||
pub async fn create_move_notification(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -127,7 +126,7 @@ pub async fn create_move_notification(
|
|||
}
|
||||
|
||||
pub async fn get_notifications(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
recipient_id: &Uuid,
|
||||
max_id: Option<i32>,
|
||||
limit: u16,
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::{DbUser, User};
|
||||
|
||||
pub async fn save_oauth_token(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
owner_id: &Uuid,
|
||||
token: &str,
|
||||
created_at: &DateTime<Utc>,
|
||||
|
@ -24,7 +23,7 @@ pub async fn save_oauth_token(
|
|||
}
|
||||
|
||||
pub async fn delete_oauth_token(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
current_user_id: &Uuid,
|
||||
token: &str,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -54,7 +53,7 @@ pub async fn delete_oauth_token(
|
|||
}
|
||||
|
||||
pub async fn delete_oauth_tokens(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
owner_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
db_client.execute(
|
||||
|
@ -65,7 +64,7 @@ pub async fn delete_oauth_tokens(
|
|||
}
|
||||
|
||||
pub async fn get_user_by_oauth_token(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
access_token: &str,
|
||||
) -> Result<User, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::activitypub::identifiers::parse_local_object_id;
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::reactions::queries::find_favourited_by_user;
|
||||
use crate::models::relationships::queries::has_relationship;
|
||||
use crate::models::relationships::types::RelationshipType;
|
||||
|
@ -16,7 +15,7 @@ use super::queries::{
|
|||
use super::types::{Post, PostActions, Visibility};
|
||||
|
||||
pub async fn add_related_posts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
posts: Vec<&mut Post>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let posts_ids = posts.iter().map(|post| post.id).collect();
|
||||
|
@ -50,7 +49,7 @@ pub async fn add_related_posts(
|
|||
}
|
||||
|
||||
pub async fn add_user_actions(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
posts: Vec<&mut Post>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -82,7 +81,7 @@ pub async fn add_user_actions(
|
|||
}
|
||||
|
||||
pub async fn can_view_post(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user: Option<&User>,
|
||||
post: &Post,
|
||||
) -> Result<bool, DatabaseError> {
|
||||
|
@ -125,7 +124,7 @@ pub async fn can_view_post(
|
|||
}
|
||||
|
||||
pub async fn get_local_post_by_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
) -> Result<Post, DatabaseError> {
|
||||
let post = get_post_by_id(db_client, post_id).await?;
|
||||
|
@ -136,7 +135,7 @@ pub async fn get_local_post_by_id(
|
|||
}
|
||||
|
||||
pub async fn get_post_by_object_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance_url: &str,
|
||||
object_id: &str,
|
||||
) -> Result<Post, DatabaseError> {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use regex::{Captures, Match, Regex};
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use super::helpers::get_post_by_object_id;
|
||||
use super::types::{Post, Visibility};
|
||||
|
||||
|
@ -38,7 +37,7 @@ fn find_object_links(text: &str) -> Vec<String> {
|
|||
}
|
||||
|
||||
pub async fn find_linked_posts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance_url: &str,
|
||||
text: &str,
|
||||
) -> Result<HashMap<String, Post>, DatabaseError> {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use regex::{Captures, Regex};
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::profiles::queries::get_profiles_by_accts;
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
|
@ -45,7 +44,7 @@ fn find_mentions(
|
|||
}
|
||||
|
||||
pub async fn find_mentioned_profiles(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance_hostname: &str,
|
||||
text: &str,
|
||||
) -> Result<HashMap<String, DbActorProfile>, DatabaseError> {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
query_macro::query,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::models::attachments::queries::set_attachment_ipfs_cid;
|
||||
|
@ -33,7 +33,7 @@ use super::types::{
|
|||
};
|
||||
|
||||
pub async fn create_post(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
author_id: &Uuid,
|
||||
data: PostCreateData,
|
||||
) -> Result<Post, DatabaseError> {
|
||||
|
@ -300,7 +300,7 @@ fn build_visibility_filter() -> String {
|
|||
}
|
||||
|
||||
pub async fn get_home_timeline(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
current_user_id: &Uuid,
|
||||
max_post_id: Option<Uuid>,
|
||||
limit: u16,
|
||||
|
@ -404,7 +404,7 @@ pub async fn get_home_timeline(
|
|||
}
|
||||
|
||||
pub async fn get_local_timeline(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
current_user_id: &Uuid,
|
||||
max_post_id: Option<Uuid>,
|
||||
limit: u16,
|
||||
|
@ -449,7 +449,7 @@ pub async fn get_local_timeline(
|
|||
}
|
||||
|
||||
pub async fn get_related_posts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
posts_ids: Vec<Uuid>,
|
||||
) -> Result<Vec<Post>, DatabaseError> {
|
||||
let statement = format!(
|
||||
|
@ -495,7 +495,7 @@ pub async fn get_related_posts(
|
|||
}
|
||||
|
||||
pub async fn get_posts_by_author(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
current_user_id: Option<&Uuid>,
|
||||
include_replies: bool,
|
||||
|
@ -553,7 +553,7 @@ pub async fn get_posts_by_author(
|
|||
}
|
||||
|
||||
pub async fn get_posts_by_tag(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
tag_name: &str,
|
||||
current_user_id: Option<&Uuid>,
|
||||
max_post_id: Option<Uuid>,
|
||||
|
@ -604,7 +604,7 @@ pub async fn get_posts_by_tag(
|
|||
}
|
||||
|
||||
pub async fn get_post_by_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
) -> Result<Post, DatabaseError> {
|
||||
let statement = format!(
|
||||
|
@ -640,7 +640,7 @@ pub async fn get_post_by_id(
|
|||
/// Given a post ID, finds all items in thread.
|
||||
/// Results are sorted by tree path.
|
||||
pub async fn get_thread(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
current_user_id: Option<&Uuid>,
|
||||
) -> Result<Vec<Post>, DatabaseError> {
|
||||
|
@ -700,7 +700,7 @@ pub async fn get_thread(
|
|||
}
|
||||
|
||||
pub async fn get_post_by_remote_object_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
object_id: &str,
|
||||
) -> Result<Post, DatabaseError> {
|
||||
let statement = format!(
|
||||
|
@ -732,7 +732,7 @@ pub async fn get_post_by_remote_object_id(
|
|||
}
|
||||
|
||||
pub async fn get_post_by_ipfs_cid(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
ipfs_cid: &str,
|
||||
) -> Result<Post, DatabaseError> {
|
||||
let statement = format!(
|
||||
|
@ -766,7 +766,7 @@ pub async fn get_post_by_ipfs_cid(
|
|||
}
|
||||
|
||||
pub async fn update_post(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
post_data: PostUpdateData,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -794,7 +794,7 @@ pub async fn update_post(
|
|||
}
|
||||
|
||||
pub async fn update_reply_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -813,7 +813,7 @@ pub async fn update_reply_count(
|
|||
}
|
||||
|
||||
pub async fn update_reaction_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -832,7 +832,7 @@ pub async fn update_reaction_count(
|
|||
}
|
||||
|
||||
pub async fn update_repost_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -851,7 +851,7 @@ pub async fn update_repost_count(
|
|||
}
|
||||
|
||||
pub async fn set_post_ipfs_cid(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
ipfs_cid: &str,
|
||||
attachments: Vec<(Uuid, String)>,
|
||||
|
@ -878,7 +878,7 @@ pub async fn set_post_ipfs_cid(
|
|||
}
|
||||
|
||||
pub async fn set_post_token_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
token_id: i32,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -899,7 +899,7 @@ pub async fn set_post_token_id(
|
|||
}
|
||||
|
||||
pub async fn set_post_token_tx_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
token_tx_id: &str,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -919,7 +919,7 @@ pub async fn set_post_token_tx_id(
|
|||
}
|
||||
|
||||
pub async fn get_post_author(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -938,7 +938,7 @@ pub async fn get_post_author(
|
|||
|
||||
/// Finds reposts of given posts and returns their IDs
|
||||
pub async fn find_reposts_by_user(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
posts_ids: &[Uuid],
|
||||
) -> Result<Vec<Uuid>, DatabaseError> {
|
||||
|
@ -958,7 +958,7 @@ pub async fn find_reposts_by_user(
|
|||
|
||||
/// Finds items reposted by user among given posts
|
||||
pub async fn find_reposted_by_user(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
posts_ids: &[Uuid],
|
||||
) -> Result<Vec<Uuid>, DatabaseError> {
|
||||
|
@ -980,7 +980,7 @@ pub async fn find_reposted_by_user(
|
|||
}
|
||||
|
||||
pub async fn get_token_waitlist(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<Vec<Uuid>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
"
|
||||
|
@ -1000,7 +1000,7 @@ pub async fn get_token_waitlist(
|
|||
/// updated before the specified date
|
||||
/// that do not contain local posts, reposts, mentions, links or reactions.
|
||||
pub async fn find_extraneous_posts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
updated_before: &DateTime<Utc>,
|
||||
) -> Result<Vec<Uuid>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -1075,7 +1075,7 @@ pub async fn find_extraneous_posts(
|
|||
|
||||
/// Deletes post from database and returns collection of orphaned objects.
|
||||
pub async fn delete_post(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
post_id: &Uuid,
|
||||
) -> Result<DeletionQueue, DatabaseError> {
|
||||
let transaction = db_client.transaction().await?;
|
||||
|
@ -1168,7 +1168,7 @@ pub async fn delete_post(
|
|||
}
|
||||
|
||||
pub async fn get_local_post_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<i64, DatabaseError> {
|
||||
let row = db_client.query_one(
|
||||
"
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use super::queries::search_profiles_by_did_only;
|
||||
use super::types::DbActorProfile;
|
||||
|
||||
pub async fn find_aliases(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile: &DbActorProfile,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let mut results = vec![];
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
query_macro::query,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::identity::{did::Did, did_pkh::DidPkh};
|
||||
|
@ -28,7 +28,7 @@ use super::types::{
|
|||
|
||||
/// Create new profile using given Client or Transaction.
|
||||
pub async fn create_profile(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_data: ProfileCreateData,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
let profile_id = new_uuid();
|
||||
|
@ -66,7 +66,7 @@ pub async fn create_profile(
|
|||
}
|
||||
|
||||
pub async fn update_profile(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
data: ProfileUpdateData,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
|
@ -108,7 +108,7 @@ pub async fn update_profile(
|
|||
}
|
||||
|
||||
pub async fn get_profile_by_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
let result = db_client.query_opt(
|
||||
|
@ -127,7 +127,7 @@ pub async fn get_profile_by_id(
|
|||
}
|
||||
|
||||
pub async fn get_profile_by_remote_actor_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
actor_id: &str,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -145,7 +145,7 @@ pub async fn get_profile_by_remote_actor_id(
|
|||
}
|
||||
|
||||
pub async fn get_profile_by_acct(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
acct: &str,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
let result = db_client.query_opt(
|
||||
|
@ -164,7 +164,7 @@ pub async fn get_profile_by_acct(
|
|||
}
|
||||
|
||||
pub async fn get_profiles(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
only_local: bool,
|
||||
offset: u16,
|
||||
limit: u16,
|
||||
|
@ -191,7 +191,7 @@ pub async fn get_profiles(
|
|||
}
|
||||
|
||||
pub async fn get_profiles_by_accts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
accts: Vec<String>,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -210,7 +210,7 @@ pub async fn get_profiles_by_accts(
|
|||
|
||||
/// Deletes profile from database and returns collection of orphaned objects.
|
||||
pub async fn delete_profile(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
) -> Result<DeletionQueue, DatabaseError> {
|
||||
let transaction = db_client.transaction().await?;
|
||||
|
@ -378,7 +378,7 @@ pub async fn delete_profile(
|
|||
}
|
||||
|
||||
pub async fn search_profiles(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
username: &str,
|
||||
maybe_hostname: Option<&String>,
|
||||
limit: u16,
|
||||
|
@ -409,7 +409,7 @@ pub async fn search_profiles(
|
|||
}
|
||||
|
||||
pub async fn search_profiles_by_did_only(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
did: &Did,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -432,7 +432,7 @@ pub async fn search_profiles_by_did_only(
|
|||
}
|
||||
|
||||
pub async fn search_profiles_by_did(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
did: &Did,
|
||||
prefer_verified: bool,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
|
@ -495,7 +495,7 @@ pub async fn search_profiles_by_did(
|
|||
}
|
||||
|
||||
pub async fn search_profiles_by_wallet_address(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
currency: &Currency,
|
||||
wallet_address: &str,
|
||||
prefer_verified: bool,
|
||||
|
@ -506,7 +506,7 @@ pub async fn search_profiles_by_wallet_address(
|
|||
}
|
||||
|
||||
pub async fn update_follower_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
|
@ -525,7 +525,7 @@ pub async fn update_follower_count(
|
|||
}
|
||||
|
||||
pub async fn update_following_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
|
@ -544,7 +544,7 @@ pub async fn update_following_count(
|
|||
}
|
||||
|
||||
pub async fn update_subscriber_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
|
@ -563,7 +563,7 @@ pub async fn update_subscriber_count(
|
|||
}
|
||||
|
||||
pub async fn update_post_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
change: i32,
|
||||
) -> Result<DbActorProfile, DatabaseError> {
|
||||
|
@ -583,7 +583,7 @@ pub async fn update_post_count(
|
|||
|
||||
// Doesn't return error if profile doesn't exist
|
||||
pub async fn set_reachability_status(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
actor_id: &str,
|
||||
is_reachable: bool,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -615,7 +615,7 @@ pub async fn set_reachability_status(
|
|||
/// (without any posts, reactions, relationships)
|
||||
/// updated before the specified date
|
||||
pub async fn find_empty_profiles(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
updated_before: &DateTime<Utc>,
|
||||
) -> Result<Vec<Uuid>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{catch_unique_violation, DatabaseError};
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::models::notifications::queries::create_reaction_notification;
|
||||
use crate::models::posts::queries::{
|
||||
update_reaction_count,
|
||||
|
@ -11,7 +14,7 @@ use crate::utils::id::new_uuid;
|
|||
use super::types::DbReaction;
|
||||
|
||||
pub async fn create_reaction(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
author_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
activity_id: Option<&String>,
|
||||
|
@ -48,7 +51,7 @@ pub async fn create_reaction(
|
|||
}
|
||||
|
||||
pub async fn get_reaction_by_remote_activity_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
activity_id: &str,
|
||||
) -> Result<DbReaction, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -65,7 +68,7 @@ pub async fn get_reaction_by_remote_activity_id(
|
|||
}
|
||||
|
||||
pub async fn delete_reaction(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
author_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
) -> Result<Uuid, DatabaseError> {
|
||||
|
@ -87,7 +90,7 @@ pub async fn delete_reaction(
|
|||
|
||||
/// Finds favourites among given posts and returns their IDs
|
||||
pub async fn find_favourited_by_user(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
posts_ids: &[Uuid],
|
||||
) -> Result<Vec<Uuid>, DatabaseError> {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{catch_unique_violation, DatabaseError};
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::models::notifications::queries::create_follow_notification;
|
||||
use crate::models::profiles::queries::{
|
||||
update_follower_count,
|
||||
|
@ -19,7 +22,7 @@ use super::types::{
|
|||
};
|
||||
|
||||
pub async fn get_relationships(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<Vec<DbRelationship>, DatabaseError> {
|
||||
|
@ -52,7 +55,7 @@ pub async fn get_relationships(
|
|||
}
|
||||
|
||||
pub async fn has_relationship(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
relationship_type: RelationshipType,
|
||||
|
@ -75,7 +78,7 @@ pub async fn has_relationship(
|
|||
}
|
||||
|
||||
pub async fn follow(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -97,7 +100,7 @@ pub async fn follow(
|
|||
}
|
||||
|
||||
pub async fn unfollow(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<Option<Uuid>, DatabaseError> {
|
||||
|
@ -135,7 +138,7 @@ pub async fn unfollow(
|
|||
|
||||
// Follow remote actor
|
||||
pub async fn create_follow_request(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<DbFollowRequest, DatabaseError> {
|
||||
|
@ -161,7 +164,7 @@ pub async fn create_follow_request(
|
|||
|
||||
// Save follow request from remote actor
|
||||
pub async fn create_remote_follow_request_opt(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
activity_id: &str,
|
||||
|
@ -194,7 +197,7 @@ pub async fn create_remote_follow_request_opt(
|
|||
}
|
||||
|
||||
pub async fn follow_request_accepted(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
request_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let mut transaction = db_client.transaction().await?;
|
||||
|
@ -216,7 +219,7 @@ pub async fn follow_request_accepted(
|
|||
}
|
||||
|
||||
pub async fn follow_request_rejected(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
request_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let updated_count = db_client.execute(
|
||||
|
@ -234,7 +237,7 @@ pub async fn follow_request_rejected(
|
|||
}
|
||||
|
||||
async fn delete_follow_request_opt(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<Option<Uuid>, DatabaseError> {
|
||||
|
@ -254,7 +257,7 @@ async fn delete_follow_request_opt(
|
|||
}
|
||||
|
||||
pub async fn get_follow_request_by_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
request_id: &Uuid,
|
||||
) -> Result<DbFollowRequest, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -271,7 +274,7 @@ pub async fn get_follow_request_by_id(
|
|||
}
|
||||
|
||||
pub async fn get_follow_request_by_activity_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
activity_id: &str,
|
||||
) -> Result<DbFollowRequest, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -288,7 +291,7 @@ pub async fn get_follow_request_by_activity_id(
|
|||
}
|
||||
|
||||
pub async fn get_followers(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -310,7 +313,7 @@ pub async fn get_followers(
|
|||
}
|
||||
|
||||
pub async fn get_followers_paginated(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
max_relationship_id: Option<i32>,
|
||||
limit: u16,
|
||||
|
@ -342,7 +345,7 @@ pub async fn get_followers_paginated(
|
|||
}
|
||||
|
||||
pub async fn get_following(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -364,7 +367,7 @@ pub async fn get_following(
|
|||
}
|
||||
|
||||
pub async fn get_following_paginated(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
max_relationship_id: Option<i32>,
|
||||
limit: u16,
|
||||
|
@ -396,7 +399,7 @@ pub async fn get_following_paginated(
|
|||
}
|
||||
|
||||
pub async fn subscribe(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -414,7 +417,7 @@ pub async fn subscribe(
|
|||
}
|
||||
|
||||
pub async fn subscribe_opt(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -435,7 +438,7 @@ pub async fn subscribe_opt(
|
|||
}
|
||||
|
||||
pub async fn unsubscribe(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -458,7 +461,7 @@ pub async fn unsubscribe(
|
|||
}
|
||||
|
||||
pub async fn get_subscribers(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
profile_id: &Uuid,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
|
@ -481,7 +484,7 @@ pub async fn get_subscribers(
|
|||
}
|
||||
|
||||
pub async fn hide_reposts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -497,7 +500,7 @@ pub async fn hide_reposts(
|
|||
}
|
||||
|
||||
pub async fn show_reposts(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -515,7 +518,7 @@ pub async fn show_reposts(
|
|||
}
|
||||
|
||||
pub async fn hide_replies(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -531,7 +534,7 @@ pub async fn hide_replies(
|
|||
}
|
||||
|
||||
pub async fn show_replies(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{catch_unique_violation, DatabaseError};
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::models::profiles::types::PaymentType;
|
||||
use crate::models::relationships::queries::{subscribe, subscribe_opt};
|
||||
use crate::models::relationships::types::RelationshipType;
|
||||
|
@ -10,7 +13,7 @@ use crate::utils::caip2::ChainId;
|
|||
use super::types::{DbSubscription, Subscription};
|
||||
|
||||
pub async fn create_subscription(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
sender_address: Option<&str>,
|
||||
recipient_id: &Uuid,
|
||||
|
@ -47,7 +50,7 @@ pub async fn create_subscription(
|
|||
}
|
||||
|
||||
pub async fn update_subscription(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
subscription_id: i32,
|
||||
chain_id: &ChainId,
|
||||
expires_at: &DateTime<Utc>,
|
||||
|
@ -82,7 +85,7 @@ pub async fn update_subscription(
|
|||
}
|
||||
|
||||
pub async fn get_subscription_by_participants(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
) -> Result<DbSubscription, DatabaseError> {
|
||||
|
@ -100,7 +103,7 @@ pub async fn get_subscription_by_participants(
|
|||
}
|
||||
|
||||
pub async fn get_expired_subscriptions(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<Vec<DbSubscription>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
"
|
||||
|
@ -123,7 +126,7 @@ pub async fn get_expired_subscriptions(
|
|||
}
|
||||
|
||||
pub async fn get_incoming_subscriptions(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
recipient_id: &Uuid,
|
||||
max_subscription_id: Option<i32>,
|
||||
limit: u16,
|
||||
|
@ -149,7 +152,7 @@ pub async fn get_incoming_subscriptions(
|
|||
}
|
||||
|
||||
pub async fn reset_subscriptions(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
ethereum_contract_replaced: bool,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let transaction = db_client.transaction().await?;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
|
||||
pub async fn search_tags(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
search_query: &str,
|
||||
limit: u16,
|
||||
) -> Result<Vec<String>, DatabaseError> {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::database::{catch_unique_violation, DatabaseError};
|
||||
use crate::database::{
|
||||
catch_unique_violation,
|
||||
DatabaseClient,
|
||||
DatabaseError,
|
||||
};
|
||||
use crate::identity::{did::Did, did_pkh::DidPkh};
|
||||
use crate::models::profiles::queries::create_profile;
|
||||
use crate::models::profiles::types::{DbActorProfile, ProfileCreateData};
|
||||
|
@ -10,7 +13,7 @@ use super::types::{DbUser, User, UserCreateData};
|
|||
use super::utils::generate_invite_code;
|
||||
|
||||
pub async fn create_invite_code(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<String, DatabaseError> {
|
||||
let invite_code = generate_invite_code();
|
||||
db_client.execute(
|
||||
|
@ -24,7 +27,7 @@ pub async fn create_invite_code(
|
|||
}
|
||||
|
||||
pub async fn get_invite_codes(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<Vec<String>, DatabaseError> {
|
||||
let rows = db_client.query(
|
||||
"
|
||||
|
@ -41,7 +44,7 @@ pub async fn get_invite_codes(
|
|||
}
|
||||
|
||||
pub async fn is_valid_invite_code(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
invite_code: &str,
|
||||
) -> Result<bool, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -55,7 +58,7 @@ pub async fn is_valid_invite_code(
|
|||
}
|
||||
|
||||
pub async fn create_user(
|
||||
db_client: &mut impl GenericClient,
|
||||
db_client: &mut impl DatabaseClient,
|
||||
user_data: UserCreateData,
|
||||
) -> Result<User, DatabaseError> {
|
||||
let transaction = db_client.transaction().await?;
|
||||
|
@ -128,7 +131,7 @@ pub async fn create_user(
|
|||
}
|
||||
|
||||
pub async fn set_user_password(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
password_hash: String,
|
||||
) -> Result<(), DatabaseError> {
|
||||
|
@ -146,7 +149,7 @@ pub async fn set_user_password(
|
|||
}
|
||||
|
||||
pub async fn get_user_by_id(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
user_id: &Uuid,
|
||||
) -> Result<User, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -165,7 +168,7 @@ pub async fn get_user_by_id(
|
|||
}
|
||||
|
||||
pub async fn get_user_by_name(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
username: &str,
|
||||
) -> Result<User, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -184,7 +187,7 @@ pub async fn get_user_by_name(
|
|||
}
|
||||
|
||||
pub async fn is_registered_user(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
username: &str,
|
||||
) -> Result<bool, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -198,7 +201,7 @@ pub async fn is_registered_user(
|
|||
}
|
||||
|
||||
pub async fn get_user_by_login_address(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
wallet_address: &str,
|
||||
) -> Result<User, DatabaseError> {
|
||||
let maybe_row = db_client.query_opt(
|
||||
|
@ -217,7 +220,7 @@ pub async fn get_user_by_login_address(
|
|||
}
|
||||
|
||||
pub async fn get_user_by_did(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
did: &Did,
|
||||
) -> Result<User, DatabaseError> {
|
||||
// DIDs must be locally unique
|
||||
|
@ -242,7 +245,7 @@ pub async fn get_user_by_did(
|
|||
}
|
||||
|
||||
pub async fn get_user_by_public_wallet_address(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
currency: &Currency,
|
||||
wallet_address: &str,
|
||||
) -> Result<User, DatabaseError> {
|
||||
|
@ -252,7 +255,7 @@ pub async fn get_user_by_public_wallet_address(
|
|||
}
|
||||
|
||||
pub async fn get_user_count(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
) -> Result<i64, DatabaseError> {
|
||||
let row = db_client.query_one(
|
||||
"SELECT count(user_account) FROM user_account",
|
||||
|
|
|
@ -2,10 +2,10 @@ use std::str::FromStr;
|
|||
|
||||
use monero_rpc::TransferType;
|
||||
use monero_rpc::monero::Address;
|
||||
use tokio_postgres::GenericClient;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config::MoneroConfig;
|
||||
use crate::database::DatabaseClient;
|
||||
use crate::errors::ValidationError;
|
||||
use crate::models::{
|
||||
invoices::queries::{
|
||||
|
@ -30,7 +30,7 @@ pub fn validate_monero_address(address: &str)
|
|||
|
||||
pub async fn check_expired_invoice(
|
||||
config: &MoneroConfig,
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
invoice_id: &Uuid,
|
||||
) -> Result<(), MoneroError> {
|
||||
let wallet_client = open_monero_wallet(config).await?;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::database::DatabaseError;
|
||||
use crate::database::{DatabaseClient, DatabaseError};
|
||||
use crate::models::posts::queries::get_local_post_count;
|
||||
use crate::models::users::queries::get_user_count;
|
||||
use super::types::{Usage, Users};
|
||||
|
||||
pub async fn get_usage(db_client: &impl GenericClient) -> Result<Usage, DatabaseError> {
|
||||
pub async fn get_usage(db_client: &impl DatabaseClient)
|
||||
-> Result<Usage, DatabaseError>
|
||||
{
|
||||
let user_count = get_user_count(db_client).await?;
|
||||
let post_count = get_local_post_count(db_client).await?;
|
||||
let usage = Usage {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use actix_web::{get, web, HttpResponse};
|
||||
use tokio_postgres::GenericClient;
|
||||
|
||||
use crate::activitypub::constants::AP_MEDIA_TYPE;
|
||||
use crate::activitypub::identifiers::{
|
||||
|
@ -8,7 +7,7 @@ use crate::activitypub::identifiers::{
|
|||
parse_local_actor_id,
|
||||
};
|
||||
use crate::config::{Config, Instance};
|
||||
use crate::database::{get_database_client, DbPool};
|
||||
use crate::database::{get_database_client, DatabaseClient, DbPool};
|
||||
use crate::errors::{HttpError, ValidationError};
|
||||
use crate::models::users::queries::is_registered_user;
|
||||
use super::types::{
|
||||
|
@ -28,7 +27,7 @@ fn parse_acct_uri(uri: &str) -> Result<ActorAddress, ValidationError> {
|
|||
}
|
||||
|
||||
async fn get_jrd(
|
||||
db_client: &impl GenericClient,
|
||||
db_client: &impl DatabaseClient,
|
||||
instance: Instance,
|
||||
resource: &str,
|
||||
) -> Result<JsonResourceDescriptor, HttpError> {
|
||||
|
|
Loading…
Reference in a new issue