1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-12-23 23:01:23 +00:00

Add ghost user to be able to fetch articles in case edit author cant be fetched

This commit is contained in:
Felix Ableitner 2024-11-08 15:11:29 +01:00
parent 026c8c81f2
commit 1a0acca3a0
3 changed files with 39 additions and 2 deletions

View file

@ -164,4 +164,31 @@ impl DbPerson {
.select(instance::all_columns)
.get_results(conn.deref_mut())?)
}
/// Ghost user serves as placeholder for deleted accounts
pub fn ghost(data: &Data<IbisData>) -> MyResult<DbPerson> {
let username = "ghost";
let read = DbPerson::read_from_name(username, &None, data);
if read.is_ok() {
read
} else {
let domain = &data.config.federation.domain;
let ap_id = ObjectId::parse(&format!(
"{}://{domain}/user/{username}",
http_protocol_str()
))?;
let inbox_url = format!("{}://{domain}/inbox", http_protocol_str());
let keypair = generate_actor_keypair()?;
let person_form = DbPersonForm {
username: username.to_string(),
ap_id,
inbox_url,
public_key: keypair.public_key,
private_key: Some(keypair.private_key),
last_refreshed_at: Utc::now(),
local: true,
};
DbPerson::create(&person_form, data)
}
}
}

View file

@ -12,6 +12,7 @@ use activitypub_federation::{
traits::Object,
};
use chrono::{DateTime, Utc};
use log::warn;
use serde::{Deserialize, Serialize};
use url::Url;
@ -77,8 +78,14 @@ impl Object for DbEdit {
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
let article = json.object.dereference(data).await?;
let creator = json.attributed_to.dereference(data).await?;
// TODO: if creator fails to fetch, make a dummy user
let creator = match json.attributed_to.dereference(data).await {
Ok(c) => c,
Err(e) => {
// If actor couldnt be fetched, use ghost as placeholder
warn!("Failed to fetch user {}: {e}", json.attributed_to);
DbPerson::ghost(data)?
}
};
let form = DbEditForm {
creator_id: creator.id,
ap_id: json.id,

View file

@ -169,6 +169,9 @@ async fn setup(data: &Data<IbisData>) -> Result<(), Error> {
)
.await?;
// create ghost user
DbPerson::ghost(data)?;
Ok(())
}