Create DbActor type and use it to represent actor_profile.actor_json column value
This commit is contained in:
parent
4f9a99e6f2
commit
462da87e9b
22 changed files with 125 additions and 79 deletions
|
@ -175,7 +175,7 @@ pub async fn create_remote_profile(
|
||||||
extra_fields,
|
extra_fields,
|
||||||
aliases,
|
aliases,
|
||||||
emojis,
|
emojis,
|
||||||
actor_json: Some(actor),
|
actor_json: Some(actor.into_db_actor()),
|
||||||
};
|
};
|
||||||
clean_profile_create_data(&mut profile_data)?;
|
clean_profile_create_data(&mut profile_data)?;
|
||||||
let profile = create_profile(db_client, profile_data).await?;
|
let profile = create_profile(db_client, profile_data).await?;
|
||||||
|
@ -233,7 +233,7 @@ pub async fn update_remote_profile(
|
||||||
extra_fields,
|
extra_fields,
|
||||||
aliases,
|
aliases,
|
||||||
emojis,
|
emojis,
|
||||||
actor_json: Some(actor),
|
actor_json: Some(actor.into_db_actor()),
|
||||||
};
|
};
|
||||||
clean_profile_update_data(&mut profile_data)?;
|
clean_profile_update_data(&mut profile_data)?;
|
||||||
let profile = update_profile(db_client, &profile.id, profile_data).await?;
|
let profile = update_profile(db_client, &profile.id, profile_data).await?;
|
||||||
|
|
|
@ -36,6 +36,8 @@ use crate::errors::ValidationError;
|
||||||
use crate::media::get_file_url;
|
use crate::media::get_file_url;
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
profiles::types::{
|
profiles::types::{
|
||||||
|
DbActor,
|
||||||
|
DbActorPublicKey,
|
||||||
ExtraField,
|
ExtraField,
|
||||||
IdentityProof,
|
IdentityProof,
|
||||||
PaymentOption,
|
PaymentOption,
|
||||||
|
@ -52,7 +54,7 @@ use super::attachments::{
|
||||||
parse_payment_option,
|
parse_payment_option,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[cfg_attr(test, derive(Default))]
|
#[cfg_attr(test, derive(Default))]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct PublicKey {
|
pub struct PublicKey {
|
||||||
|
@ -61,7 +63,7 @@ pub struct PublicKey {
|
||||||
pub public_key_pem: String,
|
pub public_key_pem: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ActorImage {
|
pub struct ActorImage {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -70,7 +72,7 @@ pub struct ActorImage {
|
||||||
pub media_type: Option<String>,
|
pub media_type: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ActorAttachment {
|
pub struct ActorAttachment {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -130,8 +132,7 @@ fn deserialize_attachments<'de, D>(
|
||||||
Ok(attachments)
|
Ok(attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone and Debug traits are required by FromSql
|
#[derive(Deserialize, Serialize)]
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
#[cfg_attr(test, derive(Default))]
|
#[cfg_attr(test, derive(Default))]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Actor {
|
pub struct Actor {
|
||||||
|
@ -210,6 +211,23 @@ impl Actor {
|
||||||
Ok(actor_address)
|
Ok(actor_address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_db_actor(self) -> DbActor {
|
||||||
|
DbActor {
|
||||||
|
object_type: self.object_type,
|
||||||
|
id: self.id,
|
||||||
|
inbox: self.inbox,
|
||||||
|
outbox: self.outbox,
|
||||||
|
followers: self.followers,
|
||||||
|
subscribers: self.subscribers,
|
||||||
|
url: self.url,
|
||||||
|
public_key: DbActorPublicKey {
|
||||||
|
id: self.public_key.id,
|
||||||
|
owner: self.public_key.owner,
|
||||||
|
public_key_pem: self.public_key.public_key_pem,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_attachments(&self) -> (
|
pub fn parse_attachments(&self) -> (
|
||||||
Vec<IdentityProof>,
|
Vec<IdentityProof>,
|
||||||
Vec<PaymentOption>,
|
Vec<PaymentOption>,
|
||||||
|
|
|
@ -4,14 +4,13 @@ use mitra_config::Instance;
|
||||||
use mitra_utils::id::generate_ulid;
|
use mitra_utils::id::generate_ulid;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{local_actor_id, local_object_id},
|
identifiers::{local_actor_id, local_object_id},
|
||||||
types::{build_default_context, Context},
|
types::{build_default_context, Context},
|
||||||
vocabulary::ACCEPT,
|
vocabulary::ACCEPT,
|
||||||
};
|
};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
profiles::types::DbActorProfile,
|
profiles::types::{DbActor, DbActorProfile},
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ fn build_accept_follow(
|
||||||
pub fn prepare_accept_follow(
|
pub fn prepare_accept_follow(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
source_actor: &Actor,
|
source_actor: &DbActor,
|
||||||
follow_activity_id: &str,
|
follow_activity_id: &str,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
let activity = build_accept_follow(
|
let activity = build_accept_follow(
|
||||||
|
|
|
@ -4,13 +4,15 @@ use mitra_config::Instance;
|
||||||
use mitra_utils::id::generate_ulid;
|
use mitra_utils::id::generate_ulid;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{local_actor_id, local_object_id, LocalActorCollection},
|
identifiers::{local_actor_id, local_object_id, LocalActorCollection},
|
||||||
types::{build_default_context, Context},
|
types::{build_default_context, Context},
|
||||||
vocabulary::{ADD, REMOVE},
|
vocabulary::{ADD, REMOVE},
|
||||||
};
|
};
|
||||||
use crate::models::users::types::User;
|
use crate::models::{
|
||||||
|
profiles::types::DbActor,
|
||||||
|
users::types::User,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct AddOrRemovePerson {
|
struct AddOrRemovePerson {
|
||||||
|
@ -53,7 +55,7 @@ fn build_update_collection(
|
||||||
pub fn prepare_update_collection(
|
pub fn prepare_update_collection(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
person: &Actor,
|
person: &DbActor,
|
||||||
collection: LocalActorCollection,
|
collection: LocalActorCollection,
|
||||||
remove: bool,
|
remove: bool,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
|
@ -76,7 +78,7 @@ pub fn prepare_update_collection(
|
||||||
pub fn prepare_add_person(
|
pub fn prepare_add_person(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
person: &Actor,
|
person: &DbActor,
|
||||||
collection: LocalActorCollection,
|
collection: LocalActorCollection,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
prepare_update_collection(instance, sender, person, collection, false)
|
prepare_update_collection(instance, sender, person, collection, false)
|
||||||
|
|
|
@ -4,7 +4,6 @@ use serde::Serialize;
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
constants::AP_PUBLIC,
|
constants::AP_PUBLIC,
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{
|
identifiers::{
|
||||||
|
@ -20,6 +19,7 @@ use crate::activitypub::{
|
||||||
use crate::database::{DatabaseClient, DatabaseError};
|
use crate::database::{DatabaseClient, DatabaseError};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
posts::types::Post,
|
posts::types::Post,
|
||||||
|
profiles::types::DbActor,
|
||||||
relationships::queries::get_followers,
|
relationships::queries::get_followers,
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
@ -70,9 +70,9 @@ pub async fn get_announce_recipients(
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
current_user: &User,
|
current_user: &User,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Result<(Vec<Actor>, String), DatabaseError> {
|
) -> Result<(Vec<DbActor>, String), DatabaseError> {
|
||||||
let followers = get_followers(db_client, ¤t_user.id).await?;
|
let followers = get_followers(db_client, ¤t_user.id).await?;
|
||||||
let mut recipients: Vec<Actor> = Vec::new();
|
let mut recipients = vec![];
|
||||||
for profile in followers {
|
for profile in followers {
|
||||||
if let Some(remote_actor) = profile.actor_json {
|
if let Some(remote_actor) = profile.actor_json {
|
||||||
recipients.push(remote_actor);
|
recipients.push(remote_actor);
|
||||||
|
@ -113,7 +113,6 @@ pub async fn prepare_announce(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -123,7 +122,7 @@ mod tests {
|
||||||
fn test_build_announce() {
|
fn test_build_announce() {
|
||||||
let post_author_id = "https://test.net/user/test";
|
let post_author_id = "https://test.net/user/test";
|
||||||
let post_author = DbActorProfile {
|
let post_author = DbActorProfile {
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: post_author_id.to_string(),
|
id: post_author_id.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -4,7 +4,6 @@ use serde::Serialize;
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
constants::{AP_MEDIA_TYPE, AP_PUBLIC},
|
constants::{AP_MEDIA_TYPE, AP_PUBLIC},
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{
|
identifiers::{
|
||||||
|
@ -34,6 +33,7 @@ use crate::models::{
|
||||||
emojis::types::DbEmoji,
|
emojis::types::DbEmoji,
|
||||||
posts::queries::get_post_author,
|
posts::queries::get_post_author,
|
||||||
posts::types::{Post, Visibility},
|
posts::types::{Post, Visibility},
|
||||||
|
profiles::types::DbActor,
|
||||||
relationships::queries::{get_followers, get_subscribers},
|
relationships::queries::{get_followers, get_subscribers},
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
@ -256,7 +256,7 @@ pub async fn get_note_recipients(
|
||||||
db_client: &impl DatabaseClient,
|
db_client: &impl DatabaseClient,
|
||||||
current_user: &User,
|
current_user: &User,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Result<Vec<Actor>, DatabaseError> {
|
) -> Result<Vec<DbActor>, DatabaseError> {
|
||||||
let mut audience = vec![];
|
let mut audience = vec![];
|
||||||
match post.visibility {
|
match post.visibility {
|
||||||
Visibility::Public | Visibility::Followers => {
|
Visibility::Public | Visibility::Followers => {
|
||||||
|
@ -276,7 +276,7 @@ pub async fn get_note_recipients(
|
||||||
};
|
};
|
||||||
audience.extend(post.mentions.clone());
|
audience.extend(post.mentions.clone());
|
||||||
|
|
||||||
let mut recipients: Vec<Actor> = Vec::new();
|
let mut recipients = vec![];
|
||||||
for profile in audience {
|
for profile in audience {
|
||||||
if let Some(remote_actor) = profile.actor_json {
|
if let Some(remote_actor) = profile.actor_json {
|
||||||
recipients.push(remote_actor);
|
recipients.push(remote_actor);
|
||||||
|
@ -399,7 +399,7 @@ mod tests {
|
||||||
let subscriber = DbActorProfile {
|
let subscriber = DbActorProfile {
|
||||||
username: "subscriber".to_string(),
|
username: "subscriber".to_string(),
|
||||||
hostname: Some("test.com".to_string()),
|
hostname: Some("test.com".to_string()),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: subscriber_id.to_string(),
|
id: subscriber_id.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -426,7 +426,7 @@ mod tests {
|
||||||
let mentioned = DbActorProfile {
|
let mentioned = DbActorProfile {
|
||||||
username: "mention".to_string(),
|
username: "mention".to_string(),
|
||||||
hostname: Some("test.com".to_string()),
|
hostname: Some("test.com".to_string()),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: mentioned_id.to_string(),
|
id: mentioned_id.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -473,7 +473,7 @@ mod tests {
|
||||||
username: "test".to_string(),
|
username: "test".to_string(),
|
||||||
hostname: Some("test.net".to_string()),
|
hostname: Some("test.net".to_string()),
|
||||||
acct: parent_author_acct.to_string(),
|
acct: parent_author_acct.to_string(),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: parent_author_actor_id.to_string(),
|
id: parent_author_actor_id.to_string(),
|
||||||
url: Some(parent_author_actor_url.to_string()),
|
url: Some(parent_author_actor_url.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -4,7 +4,6 @@ use uuid::Uuid;
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
constants::AP_PUBLIC,
|
constants::AP_PUBLIC,
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::local_actor_id,
|
identifiers::local_actor_id,
|
||||||
|
@ -13,6 +12,7 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::database::{DatabaseClient, DatabaseError};
|
use crate::database::{DatabaseClient, DatabaseError};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
|
profiles::types::DbActor,
|
||||||
relationships::queries::{get_followers, get_following},
|
relationships::queries::{get_followers, get_following},
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
@ -51,7 +51,7 @@ fn build_delete_person(
|
||||||
async fn get_delete_person_recipients(
|
async fn get_delete_person_recipients(
|
||||||
db_client: &impl DatabaseClient,
|
db_client: &impl DatabaseClient,
|
||||||
user_id: &Uuid,
|
user_id: &Uuid,
|
||||||
) -> Result<Vec<Actor>, DatabaseError> {
|
) -> Result<Vec<DbActor>, DatabaseError> {
|
||||||
let followers = get_followers(db_client, user_id).await?;
|
let followers = get_followers(db_client, user_id).await?;
|
||||||
let following = get_following(db_client, user_id).await?;
|
let following = get_following(db_client, user_id).await?;
|
||||||
let mut recipients = vec![];
|
let mut recipients = vec![];
|
||||||
|
|
|
@ -4,14 +4,13 @@ use uuid::Uuid;
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{local_actor_id, local_object_id},
|
identifiers::{local_actor_id, local_object_id},
|
||||||
types::{build_default_context, Context},
|
types::{build_default_context, Context},
|
||||||
vocabulary::FOLLOW,
|
vocabulary::FOLLOW,
|
||||||
};
|
};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
profiles::types::DbActorProfile,
|
profiles::types::{DbActor, DbActorProfile},
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ fn build_follow(
|
||||||
pub fn prepare_follow(
|
pub fn prepare_follow(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
target_actor: &Actor,
|
target_actor: &DbActor,
|
||||||
follow_request_id: &Uuid,
|
follow_request_id: &Uuid,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
let activity = build_follow(
|
let activity = build_follow(
|
||||||
|
|
|
@ -4,7 +4,6 @@ use uuid::Uuid;
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
constants::AP_PUBLIC,
|
constants::AP_PUBLIC,
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{
|
identifiers::{
|
||||||
|
@ -19,7 +18,7 @@ use crate::activitypub::{
|
||||||
use crate::database::{DatabaseClient, DatabaseError};
|
use crate::database::{DatabaseClient, DatabaseError};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
posts::types::{Post, Visibility},
|
posts::types::{Post, Visibility},
|
||||||
profiles::types::DbActorProfile,
|
profiles::types::{DbActor, DbActorProfile},
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,8 +77,8 @@ pub async fn get_like_recipients(
|
||||||
_db_client: &impl DatabaseClient,
|
_db_client: &impl DatabaseClient,
|
||||||
_instance_url: &str,
|
_instance_url: &str,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Result<Vec<Actor>, DatabaseError> {
|
) -> Result<Vec<DbActor>, DatabaseError> {
|
||||||
let mut recipients: Vec<Actor> = Vec::new();
|
let mut recipients = vec![];
|
||||||
if let Some(remote_actor) = post.author.actor_json.as_ref() {
|
if let Some(remote_actor) = post.author.actor_json.as_ref() {
|
||||||
recipients.push(remote_actor.clone());
|
recipients.push(remote_actor.clone());
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,13 +5,15 @@ use mitra_config::Instance;
|
||||||
use mitra_utils::id::generate_ulid;
|
use mitra_utils::id::generate_ulid;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{local_actor_id, local_object_id},
|
identifiers::{local_actor_id, local_object_id},
|
||||||
types::{build_default_context, Context},
|
types::{build_default_context, Context},
|
||||||
vocabulary::MOVE,
|
vocabulary::MOVE,
|
||||||
};
|
};
|
||||||
use crate::models::users::types::User;
|
use crate::models::{
|
||||||
|
profiles::types::DbActor,
|
||||||
|
users::types::User,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct MovePerson {
|
pub struct MovePerson {
|
||||||
|
@ -55,7 +57,7 @@ pub fn prepare_move_person(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
from_actor_id: &str,
|
from_actor_id: &str,
|
||||||
followers: Vec<Actor>,
|
followers: Vec<DbActor>,
|
||||||
maybe_internal_activity_id: Option<&Uuid>,
|
maybe_internal_activity_id: Option<&Uuid>,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
let followers_ids: Vec<String> = followers.iter()
|
let followers_ids: Vec<String> = followers.iter()
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::LocalActorCollection,
|
identifiers::LocalActorCollection,
|
||||||
};
|
};
|
||||||
use crate::models::users::types::User;
|
use crate::models::{
|
||||||
|
profiles::types::DbActor,
|
||||||
|
users::types::User,
|
||||||
|
};
|
||||||
use super::add_person::prepare_update_collection;
|
use super::add_person::prepare_update_collection;
|
||||||
|
|
||||||
pub fn prepare_remove_person(
|
pub fn prepare_remove_person(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
person: &Actor,
|
person: &DbActor,
|
||||||
collection: LocalActorCollection,
|
collection: LocalActorCollection,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
prepare_update_collection(instance, sender, person, collection, true)
|
prepare_update_collection(instance, sender, person, collection, true)
|
||||||
|
|
|
@ -4,14 +4,13 @@ use uuid::Uuid;
|
||||||
use mitra_config::Instance;
|
use mitra_config::Instance;
|
||||||
|
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
deliverer::OutgoingActivity,
|
deliverer::OutgoingActivity,
|
||||||
identifiers::{local_actor_id, local_object_id},
|
identifiers::{local_actor_id, local_object_id},
|
||||||
types::{build_default_context, Context},
|
types::{build_default_context, Context},
|
||||||
vocabulary::{FOLLOW, UNDO},
|
vocabulary::{FOLLOW, UNDO},
|
||||||
};
|
};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
profiles::types::DbActorProfile,
|
profiles::types::{DbActor, DbActorProfile},
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
use super::follow::Follow;
|
use super::follow::Follow;
|
||||||
|
@ -68,7 +67,7 @@ fn build_undo_follow(
|
||||||
pub fn prepare_undo_follow(
|
pub fn prepare_undo_follow(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
target_actor: &Actor,
|
target_actor: &DbActor,
|
||||||
follow_request_id: &Uuid,
|
follow_request_id: &Uuid,
|
||||||
) -> OutgoingActivity {
|
) -> OutgoingActivity {
|
||||||
let activity = build_undo_follow(
|
let activity = build_undo_follow(
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError};
|
use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
|
profiles::types::DbActor,
|
||||||
relationships::queries::get_followers,
|
relationships::queries::get_followers,
|
||||||
users::types::User,
|
users::types::User,
|
||||||
};
|
};
|
||||||
|
@ -60,9 +61,9 @@ pub fn build_update_person(
|
||||||
async fn get_update_person_recipients(
|
async fn get_update_person_recipients(
|
||||||
db_client: &impl DatabaseClient,
|
db_client: &impl DatabaseClient,
|
||||||
user_id: &Uuid,
|
user_id: &Uuid,
|
||||||
) -> Result<Vec<Actor>, DatabaseError> {
|
) -> Result<Vec<DbActor>, DatabaseError> {
|
||||||
let followers = get_followers(db_client, user_id).await?;
|
let followers = get_followers(db_client, user_id).await?;
|
||||||
let mut recipients: Vec<Actor> = Vec::new();
|
let mut recipients = vec![];
|
||||||
for profile in followers {
|
for profile in followers {
|
||||||
if let Some(remote_actor) = profile.actor_json {
|
if let Some(remote_actor) = profile.actor_json {
|
||||||
recipients.push(remote_actor);
|
recipients.push(remote_actor);
|
||||||
|
|
|
@ -25,9 +25,11 @@ use crate::json_signatures::create::{
|
||||||
sign_object,
|
sign_object,
|
||||||
JsonSignatureError,
|
JsonSignatureError,
|
||||||
};
|
};
|
||||||
use crate::models::users::types::User;
|
use crate::models::{
|
||||||
|
profiles::types::DbActor,
|
||||||
|
users::types::User,
|
||||||
|
};
|
||||||
use super::{
|
use super::{
|
||||||
actors::types::Actor,
|
|
||||||
constants::AP_MEDIA_TYPE,
|
constants::AP_MEDIA_TYPE,
|
||||||
http_client::build_federation_client,
|
http_client::build_federation_client,
|
||||||
identifiers::{local_actor_id, local_actor_key_id},
|
identifiers::{local_actor_id, local_actor_key_id},
|
||||||
|
@ -186,7 +188,7 @@ impl OutgoingActivity {
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
sender: &User,
|
sender: &User,
|
||||||
activity: impl Serialize,
|
activity: impl Serialize,
|
||||||
recipients: Vec<Actor>,
|
recipients: Vec<DbActor>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Sort and de-duplicate recipients
|
// Sort and de-duplicate recipients
|
||||||
let mut recipient_map = BTreeMap::new();
|
let mut recipient_map = BTreeMap::new();
|
||||||
|
|
|
@ -667,10 +667,10 @@ pub async fn handle_create(
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use crate::activitypub::{
|
use crate::activitypub::{
|
||||||
actors::types::Actor,
|
|
||||||
types::Object,
|
types::Object,
|
||||||
vocabulary::NOTE,
|
vocabulary::NOTE,
|
||||||
};
|
};
|
||||||
|
use crate::models::profiles::types::DbActor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -742,7 +742,7 @@ mod tests {
|
||||||
fn test_get_object_visibility_followers() {
|
fn test_get_object_visibility_followers() {
|
||||||
let author_followers = "https://example.com/users/author/followers";
|
let author_followers = "https://example.com/users/author/followers";
|
||||||
let author = DbActorProfile {
|
let author = DbActorProfile {
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
followers: Some(author_followers.to_string()),
|
followers: Some(author_followers.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -763,7 +763,7 @@ mod tests {
|
||||||
let author_followers = "https://example.com/users/author/followers";
|
let author_followers = "https://example.com/users/author/followers";
|
||||||
let author_subscribers = "https://example.com/users/author/subscribers";
|
let author_subscribers = "https://example.com/users/author/subscribers";
|
||||||
let author = DbActorProfile {
|
let author = DbActorProfile {
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
followers: Some(author_followers.to_string()),
|
followers: Some(author_followers.to_string()),
|
||||||
subscribers: Some(author_subscribers.to_string()),
|
subscribers: Some(author_subscribers.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -783,7 +783,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_object_visibility_direct() {
|
fn test_get_object_visibility_direct() {
|
||||||
let author = DbActorProfile {
|
let author = DbActorProfile {
|
||||||
actor_json: Some(Actor::default()),
|
actor_json: Some(DbActor::default()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let primary_audience = vec!["https://example.com/users/1".to_string()];
|
let primary_audience = vec!["https://example.com/users/1".to_string()];
|
||||||
|
|
|
@ -199,7 +199,7 @@ pub async fn move_followers_task(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::models::profiles::types::DbActor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -211,7 +211,7 @@ mod tests {
|
||||||
let profile_2 = DbActorProfile {
|
let profile_2 = DbActorProfile {
|
||||||
username: "user2".to_string(),
|
username: "user2".to_string(),
|
||||||
hostname: Some("test.net".to_string()),
|
hostname: Some("test.net".to_string()),
|
||||||
actor_json: Some(Actor::default()),
|
actor_json: Some(DbActor::default()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let csv = export_profiles_to_csv(
|
let csv = export_profiles_to_csv(
|
||||||
|
|
|
@ -105,7 +105,7 @@ pub fn replace_mentions(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::models::profiles::types::DbActor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const INSTANCE_HOSTNAME: &str = "server1.com";
|
const INSTANCE_HOSTNAME: &str = "server1.com";
|
||||||
|
@ -147,7 +147,7 @@ mod tests {
|
||||||
// Remote actors
|
// Remote actors
|
||||||
let profile_3 = DbActorProfile {
|
let profile_3 = DbActorProfile {
|
||||||
username: "user2".to_string(),
|
username: "user2".to_string(),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: "https://server2.com/actors/user2".to_string(),
|
id: "https://server2.com/actors/user2".to_string(),
|
||||||
url: Some("https://server2.com/@user2".to_string()),
|
url: Some("https://server2.com/@user2".to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -156,7 +156,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
let profile_4 = DbActorProfile {
|
let profile_4 = DbActorProfile {
|
||||||
username: "user3".to_string(),
|
username: "user3".to_string(),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: "https://server2.com/actors/user3".to_string(),
|
id: "https://server2.com/actors/user3".to_string(),
|
||||||
url: Some("https://server2.com/@user3".to_string()),
|
url: Some("https://server2.com/@user3".to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -828,13 +828,13 @@ pub async fn find_empty_profiles(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use crate::activitypub::actors::types::Actor;
|
|
||||||
use crate::database::test_utils::create_test_database;
|
use crate::database::test_utils::create_test_database;
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
emojis::queries::create_emoji,
|
emojis::queries::create_emoji,
|
||||||
emojis::types::EmojiImage,
|
emojis::types::EmojiImage,
|
||||||
profiles::queries::create_profile,
|
profiles::queries::create_profile,
|
||||||
profiles::types::{
|
profiles::types::{
|
||||||
|
DbActor,
|
||||||
ExtraField,
|
ExtraField,
|
||||||
IdentityProof,
|
IdentityProof,
|
||||||
IdentityProofType,
|
IdentityProofType,
|
||||||
|
@ -845,8 +845,8 @@ mod tests {
|
||||||
};
|
};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn create_test_actor(actor_id: &str) -> Actor {
|
fn create_test_actor(actor_id: &str) -> DbActor {
|
||||||
Actor { id: actor_id.to_string(), ..Default::default() }
|
DbActor { id: actor_id.to_string(), ..Default::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -13,9 +13,6 @@ use mitra_utils::{
|
||||||
did::Did,
|
did::Did,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::activitypub::{
|
|
||||||
actors::types::Actor,
|
|
||||||
};
|
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
json_macro::{json_from_sql, json_to_sql},
|
json_macro::{json_from_sql, json_to_sql},
|
||||||
DatabaseTypeError,
|
DatabaseTypeError,
|
||||||
|
@ -336,8 +333,34 @@ impl ProfileEmojis {
|
||||||
|
|
||||||
json_from_sql!(ProfileEmojis);
|
json_from_sql!(ProfileEmojis);
|
||||||
|
|
||||||
json_from_sql!(Actor);
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
json_to_sql!(Actor);
|
#[cfg_attr(test, derive(Default))]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct DbActorPublicKey {
|
||||||
|
pub id: String,
|
||||||
|
pub owner: String,
|
||||||
|
pub public_key_pem: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(test, derive(Default))]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct DbActor {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub object_type: String,
|
||||||
|
|
||||||
|
pub id: String,
|
||||||
|
pub inbox: String,
|
||||||
|
pub outbox: String,
|
||||||
|
pub followers: Option<String>,
|
||||||
|
pub subscribers: Option<String>,
|
||||||
|
pub url: Option<String>,
|
||||||
|
|
||||||
|
pub public_key: DbActorPublicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
json_from_sql!(DbActor);
|
||||||
|
json_to_sql!(DbActor);
|
||||||
|
|
||||||
#[derive(Clone, FromSql)]
|
#[derive(Clone, FromSql)]
|
||||||
#[postgres(name = "actor_profile")]
|
#[postgres(name = "actor_profile")]
|
||||||
|
@ -360,7 +383,7 @@ pub struct DbActorProfile {
|
||||||
pub subscriber_count: i32,
|
pub subscriber_count: i32,
|
||||||
pub post_count: i32,
|
pub post_count: i32,
|
||||||
pub emojis: ProfileEmojis,
|
pub emojis: ProfileEmojis,
|
||||||
pub actor_json: Option<Actor>,
|
pub actor_json: Option<DbActor>,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
pub unreachable_since: Option<DateTime<Utc>>,
|
pub unreachable_since: Option<DateTime<Utc>>,
|
||||||
|
@ -446,7 +469,7 @@ pub struct ProfileCreateData {
|
||||||
pub extra_fields: Vec<ExtraField>,
|
pub extra_fields: Vec<ExtraField>,
|
||||||
pub aliases: Vec<String>,
|
pub aliases: Vec<String>,
|
||||||
pub emojis: Vec<Uuid>,
|
pub emojis: Vec<Uuid>,
|
||||||
pub actor_json: Option<Actor>,
|
pub actor_json: Option<DbActor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProfileUpdateData {
|
pub struct ProfileUpdateData {
|
||||||
|
@ -461,7 +484,7 @@ pub struct ProfileUpdateData {
|
||||||
pub extra_fields: Vec<ExtraField>,
|
pub extra_fields: Vec<ExtraField>,
|
||||||
pub aliases: Vec<String>,
|
pub aliases: Vec<String>,
|
||||||
pub emojis: Vec<Uuid>,
|
pub emojis: Vec<Uuid>,
|
||||||
pub actor_json: Option<Actor>,
|
pub actor_json: Option<DbActor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProfileUpdateData {
|
impl ProfileUpdateData {
|
||||||
|
|
|
@ -557,15 +557,16 @@ pub async fn show_replies(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use crate::activitypub::actors::types::Actor;
|
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
test_utils::create_test_database,
|
test_utils::create_test_database,
|
||||||
DatabaseError,
|
DatabaseError,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::queries::create_profile;
|
use crate::models::{
|
||||||
use crate::models::profiles::types::ProfileCreateData;
|
profiles::queries::create_profile,
|
||||||
use crate::models::users::queries::create_user;
|
profiles::types::{DbActor, ProfileCreateData},
|
||||||
use crate::models::users::types::UserCreateData;
|
users::queries::create_user,
|
||||||
|
users::types::UserCreateData,
|
||||||
|
};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -580,7 +581,7 @@ mod tests {
|
||||||
let target_data = ProfileCreateData {
|
let target_data = ProfileCreateData {
|
||||||
username: "followed".to_string(),
|
username: "followed".to_string(),
|
||||||
hostname: Some("example.org".to_string()),
|
hostname: Some("example.org".to_string()),
|
||||||
actor_json: Some(Actor::default()),
|
actor_json: Some(DbActor::default()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let target = create_profile(db_client, target_data).await.unwrap();
|
let target = create_profile(db_client, target_data).await.unwrap();
|
||||||
|
@ -621,7 +622,7 @@ mod tests {
|
||||||
let source_data = ProfileCreateData {
|
let source_data = ProfileCreateData {
|
||||||
username: "follower".to_string(),
|
username: "follower".to_string(),
|
||||||
hostname: Some("example.org".to_string()),
|
hostname: Some("example.org".to_string()),
|
||||||
actor_json: Some(Actor::default()),
|
actor_json: Some(DbActor::default()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let source = create_profile(db_client, source_data).await.unwrap();
|
let source = create_profile(db_client, source_data).await.unwrap();
|
||||||
|
|
|
@ -129,7 +129,7 @@ pub fn clean_profile_update_data(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::models::profiles::types::DbActor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -185,7 +185,7 @@ mod tests {
|
||||||
username: "test".to_string(),
|
username: "test".to_string(),
|
||||||
hostname: Some("example.org".to_string()),
|
hostname: Some("example.org".to_string()),
|
||||||
display_name: Some("Test Test".to_string()),
|
display_name: Some("Test Test".to_string()),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: "https://example.org/test".to_string(),
|
id: "https://example.org/test".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -104,7 +104,7 @@ pub struct JsonResourceDescriptor {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::activitypub::actors::types::Actor;
|
use crate::models::profiles::types::DbActor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -138,7 +138,7 @@ mod tests {
|
||||||
username: "test".to_string(),
|
username: "test".to_string(),
|
||||||
hostname: Some("remote.com".to_string()),
|
hostname: Some("remote.com".to_string()),
|
||||||
acct: "test@remote.com".to_string(),
|
acct: "test@remote.com".to_string(),
|
||||||
actor_json: Some(Actor {
|
actor_json: Some(DbActor {
|
||||||
id: "https://test".to_string(),
|
id: "https://test".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue