mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 15:31:08 +00:00
Better activity id generation
This commit is contained in:
parent
e56e8adbdf
commit
09b68d0411
7 changed files with 12 additions and 17 deletions
|
@ -32,7 +32,7 @@ impl Accept {
|
|||
object: Follow,
|
||||
data: &Data<IbisData>,
|
||||
) -> MyResult<()> {
|
||||
let id = generate_activity_id(&local_instance.ap_id)?;
|
||||
let id = generate_activity_id(data)?;
|
||||
let follower = object.actor.dereference(data).await?;
|
||||
let accept = Accept {
|
||||
actor: local_instance.ap_id.clone(),
|
||||
|
|
|
@ -33,7 +33,7 @@ impl CreateArticle {
|
|||
pub async fn send_to_followers(article: DbArticle, data: &Data<IbisData>) -> MyResult<()> {
|
||||
let local_instance = DbInstance::read_local_instance(data)?;
|
||||
let object = article.clone().into_json(data).await?;
|
||||
let id = generate_activity_id(&local_instance.ap_id)?;
|
||||
let id = generate_activity_id(data)?;
|
||||
let to = local_instance.follower_ids(data)?;
|
||||
let create = CreateArticle {
|
||||
actor: local_instance.ap_id.clone(),
|
||||
|
|
|
@ -29,7 +29,7 @@ pub struct Follow {
|
|||
|
||||
impl Follow {
|
||||
pub async fn send(actor: DbPerson, to: &DbInstance, data: &Data<IbisData>) -> MyResult<()> {
|
||||
let id = generate_activity_id(&actor.ap_id)?;
|
||||
let id = generate_activity_id(data)?;
|
||||
let follow = Follow {
|
||||
actor: actor.ap_id.clone(),
|
||||
object: to.ap_id.clone(),
|
||||
|
|
|
@ -39,7 +39,7 @@ impl RejectEdit {
|
|||
data: &Data<IbisData>,
|
||||
) -> MyResult<()> {
|
||||
let local_instance = DbInstance::read_local_instance(data)?;
|
||||
let id = generate_activity_id(&local_instance.ap_id)?;
|
||||
let id = generate_activity_id(data)?;
|
||||
let reject = RejectEdit {
|
||||
actor: local_instance.ap_id.clone(),
|
||||
to: vec![user_instance.ap_id.into_inner()],
|
||||
|
|
|
@ -38,7 +38,7 @@ impl UpdateLocalArticle {
|
|||
) -> MyResult<()> {
|
||||
debug_assert!(article.local);
|
||||
let local_instance = DbInstance::read_local_instance(data)?;
|
||||
let id = generate_activity_id(&local_instance.ap_id)?;
|
||||
let id = generate_activity_id(data)?;
|
||||
let mut to = local_instance.follower_ids(data)?;
|
||||
to.extend(extra_recipients.iter().map(|i| i.ap_id.inner().clone()));
|
||||
let update = UpdateLocalArticle {
|
||||
|
|
|
@ -42,7 +42,7 @@ impl UpdateRemoteArticle {
|
|||
data: &Data<IbisData>,
|
||||
) -> MyResult<()> {
|
||||
let local_instance = DbInstance::read_local_instance(data)?;
|
||||
let id = generate_activity_id(&local_instance.ap_id)?;
|
||||
let id = generate_activity_id(data)?;
|
||||
let update = UpdateRemoteArticle {
|
||||
actor: local_instance.ap_id.clone(),
|
||||
to: vec![article_instance.ap_id.into_inner()],
|
||||
|
|
|
@ -1,27 +1,22 @@
|
|||
use crate::{
|
||||
backend::error::MyResult,
|
||||
common::{utils, utils::extract_domain, EditVersion, EditView},
|
||||
backend::{database::IbisData, error::MyResult},
|
||||
common::{utils, EditVersion, EditView},
|
||||
};
|
||||
use activitypub_federation::{fetch::object_id::ObjectId, traits::Object};
|
||||
use activitypub_federation::config::Data;
|
||||
use anyhow::anyhow;
|
||||
use diffy::{apply, Patch};
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use serde::Deserialize;
|
||||
use url::{ParseError, Url};
|
||||
|
||||
pub fn generate_activity_id<T>(for_url: &ObjectId<T>) -> Result<Url, ParseError>
|
||||
where
|
||||
T: Object + Send + 'static,
|
||||
for<'de2> <T as Object>::Kind: Deserialize<'de2>,
|
||||
{
|
||||
let domain = extract_domain(for_url);
|
||||
pub fn generate_activity_id(data: &Data<IbisData>) -> Result<Url, ParseError> {
|
||||
let domain = &data.config.federation.domain;
|
||||
let id: String = thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(7)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
Url::parse(&format!(
|
||||
"{}://{}/objects/{}",
|
||||
"{}://{}/activity/{}",
|
||||
utils::http_protocol_str(),
|
||||
domain,
|
||||
id
|
||||
|
|
Loading…
Reference in a new issue