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,
|
object: Follow,
|
||||||
data: &Data<IbisData>,
|
data: &Data<IbisData>,
|
||||||
) -> MyResult<()> {
|
) -> MyResult<()> {
|
||||||
let id = generate_activity_id(&local_instance.ap_id)?;
|
let id = generate_activity_id(data)?;
|
||||||
let follower = object.actor.dereference(data).await?;
|
let follower = object.actor.dereference(data).await?;
|
||||||
let accept = Accept {
|
let accept = Accept {
|
||||||
actor: local_instance.ap_id.clone(),
|
actor: local_instance.ap_id.clone(),
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl CreateArticle {
|
||||||
pub async fn send_to_followers(article: DbArticle, data: &Data<IbisData>) -> MyResult<()> {
|
pub async fn send_to_followers(article: DbArticle, data: &Data<IbisData>) -> MyResult<()> {
|
||||||
let local_instance = DbInstance::read_local_instance(data)?;
|
let local_instance = DbInstance::read_local_instance(data)?;
|
||||||
let object = article.clone().into_json(data).await?;
|
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 to = local_instance.follower_ids(data)?;
|
||||||
let create = CreateArticle {
|
let create = CreateArticle {
|
||||||
actor: local_instance.ap_id.clone(),
|
actor: local_instance.ap_id.clone(),
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub struct Follow {
|
||||||
|
|
||||||
impl Follow {
|
impl Follow {
|
||||||
pub async fn send(actor: DbPerson, to: &DbInstance, data: &Data<IbisData>) -> MyResult<()> {
|
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 {
|
let follow = Follow {
|
||||||
actor: actor.ap_id.clone(),
|
actor: actor.ap_id.clone(),
|
||||||
object: to.ap_id.clone(),
|
object: to.ap_id.clone(),
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl RejectEdit {
|
||||||
data: &Data<IbisData>,
|
data: &Data<IbisData>,
|
||||||
) -> MyResult<()> {
|
) -> MyResult<()> {
|
||||||
let local_instance = DbInstance::read_local_instance(data)?;
|
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 {
|
let reject = RejectEdit {
|
||||||
actor: local_instance.ap_id.clone(),
|
actor: local_instance.ap_id.clone(),
|
||||||
to: vec![user_instance.ap_id.into_inner()],
|
to: vec![user_instance.ap_id.into_inner()],
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl UpdateLocalArticle {
|
||||||
) -> MyResult<()> {
|
) -> MyResult<()> {
|
||||||
debug_assert!(article.local);
|
debug_assert!(article.local);
|
||||||
let local_instance = DbInstance::read_local_instance(data)?;
|
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)?;
|
let mut to = local_instance.follower_ids(data)?;
|
||||||
to.extend(extra_recipients.iter().map(|i| i.ap_id.inner().clone()));
|
to.extend(extra_recipients.iter().map(|i| i.ap_id.inner().clone()));
|
||||||
let update = UpdateLocalArticle {
|
let update = UpdateLocalArticle {
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl UpdateRemoteArticle {
|
||||||
data: &Data<IbisData>,
|
data: &Data<IbisData>,
|
||||||
) -> MyResult<()> {
|
) -> MyResult<()> {
|
||||||
let local_instance = DbInstance::read_local_instance(data)?;
|
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 {
|
let update = UpdateRemoteArticle {
|
||||||
actor: local_instance.ap_id.clone(),
|
actor: local_instance.ap_id.clone(),
|
||||||
to: vec![article_instance.ap_id.into_inner()],
|
to: vec![article_instance.ap_id.into_inner()],
|
||||||
|
|
|
@ -1,27 +1,22 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::error::MyResult,
|
backend::{database::IbisData, error::MyResult},
|
||||||
common::{utils, utils::extract_domain, EditVersion, EditView},
|
common::{utils, EditVersion, EditView},
|
||||||
};
|
};
|
||||||
use activitypub_federation::{fetch::object_id::ObjectId, traits::Object};
|
use activitypub_federation::config::Data;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use diffy::{apply, Patch};
|
use diffy::{apply, Patch};
|
||||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
use serde::Deserialize;
|
|
||||||
use url::{ParseError, Url};
|
use url::{ParseError, Url};
|
||||||
|
|
||||||
pub fn generate_activity_id<T>(for_url: &ObjectId<T>) -> Result<Url, ParseError>
|
pub fn generate_activity_id(data: &Data<IbisData>) -> Result<Url, ParseError> {
|
||||||
where
|
let domain = &data.config.federation.domain;
|
||||||
T: Object + Send + 'static,
|
|
||||||
for<'de2> <T as Object>::Kind: Deserialize<'de2>,
|
|
||||||
{
|
|
||||||
let domain = extract_domain(for_url);
|
|
||||||
let id: String = thread_rng()
|
let id: String = thread_rng()
|
||||||
.sample_iter(&Alphanumeric)
|
.sample_iter(&Alphanumeric)
|
||||||
.take(7)
|
.take(7)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect();
|
.collect();
|
||||||
Url::parse(&format!(
|
Url::parse(&format!(
|
||||||
"{}://{}/objects/{}",
|
"{}://{}/activity/{}",
|
||||||
utils::http_protocol_str(),
|
utils::http_protocol_str(),
|
||||||
domain,
|
domain,
|
||||||
id
|
id
|
||||||
|
|
Loading…
Reference in a new issue