Make Reshare follow activitystreams 0.7
This commit is contained in:
parent
ff26149b7c
commit
fad7c7279b
@ -2,13 +2,17 @@ use crate::{
|
|||||||
db_conn::DbConn, instance::Instance, notifications::*, posts::Post, schema::reshares,
|
db_conn::DbConn, instance::Instance, notifications::*, posts::Post, schema::reshares,
|
||||||
timeline::*, users::User, Connection, Error, Result, CONFIG,
|
timeline::*, users::User, Connection, Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::activity::{Announce, Undo};
|
use activitystreams::{
|
||||||
|
activity::{ActivityExt, ActorAndObjectRefExt, Announce, Undo},
|
||||||
|
base::AnyBase,
|
||||||
|
primitives::OneOrMany,
|
||||||
|
uri as as_uri,
|
||||||
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
sign::Signer,
|
sign::Signer,
|
||||||
Id, IntoId, PUBLIC_VISIBILITY,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable)]
|
#[derive(Clone, Queryable, Identifiable)]
|
||||||
@ -61,16 +65,21 @@ impl Reshare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_activity(&self, conn: &Connection) -> Result<Announce> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<Announce> {
|
||||||
let mut act = Announce::default();
|
let act = Announce::new(
|
||||||
act.announce_props
|
as_uri!(User::get(conn, self.user_id)?.ap_url), // FIXME: Use to_activity()
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
as_uri!(Post::get(conn, self.post_id)?.ap_url), // FIXME: Use to_activity()
|
||||||
act.announce_props
|
);
|
||||||
.set_object_link(Post::get(conn, self.post_id)?.into_id())?;
|
|
||||||
act.object_props.set_id_string(self.ap_url.clone())?;
|
// let mut act = Announce::default();
|
||||||
act.object_props
|
// act.announce_props
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
// .set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
||||||
act.object_props
|
// act.announce_props
|
||||||
.set_cc_link_vec(vec![Id::new(self.get_user(conn)?.followers_endpoint)])?;
|
// .set_object_link(Post::get(conn, self.post_id)?.into_id())?;
|
||||||
|
// act.object_props.set_id_string(self.ap_url.clone())?;
|
||||||
|
// act.object_props
|
||||||
|
// .set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||||
|
// act.object_props
|
||||||
|
// .set_cc_link_vec(vec![Id::new(self.get_user(conn)?.followers_endpoint)])?;
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
@ -93,16 +102,26 @@ impl Reshare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
||||||
let mut act = Undo::default();
|
let announce = self.to_activity(conn)?;
|
||||||
act.undo_props
|
let act = Undo::new::<url::Url, OneOrMany<AnyBase>>(
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
*announce
|
||||||
act.undo_props.set_object_object(self.to_activity(conn)?)?;
|
.actor()
|
||||||
act.object_props
|
.expect("authorized domain")
|
||||||
.set_id_string(format!("{}#delete", self.ap_url))?;
|
.as_single_id()
|
||||||
act.object_props
|
.expect("exists and only"),
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
*announce.result().expect("exists"),
|
||||||
act.object_props
|
);
|
||||||
.set_cc_link_vec(vec![Id::new(self.get_user(conn)?.followers_endpoint)])?;
|
|
||||||
|
// let mut act = Undo::default();
|
||||||
|
// act.undo_props
|
||||||
|
// .set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
||||||
|
// act.undo_props.set_object_object(self.to_activity(conn)?)?;
|
||||||
|
// act.object_props
|
||||||
|
// .set_id_string(format!("{}#delete", self.ap_url))?;
|
||||||
|
// act.object_props
|
||||||
|
// .set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||||
|
// act.object_props
|
||||||
|
// .set_cc_link_vec(vec![Id::new(self.get_user(conn)?.followers_endpoint)])?;
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
@ -143,7 +162,10 @@ impl FromId<DbConn> for Reshare {
|
|||||||
NewReshare {
|
NewReshare {
|
||||||
post_id: Post::from_id(
|
post_id: Post::from_id(
|
||||||
conn,
|
conn,
|
||||||
&act.announce_props.object_link::<Id>()?,
|
&act.object()
|
||||||
|
.as_single_id()
|
||||||
|
.expect("exists and only")
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
@ -151,13 +173,21 @@ impl FromId<DbConn> for Reshare {
|
|||||||
.id,
|
.id,
|
||||||
user_id: User::from_id(
|
user_id: User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&act.announce_props.actor_link::<Id>()?,
|
&act.actor()
|
||||||
|
.expect("authorized domain")
|
||||||
|
.as_single_id()
|
||||||
|
.expect("exists")
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
.map_err(|(_, e)| e)?
|
.map_err(|(_, e)| e)?
|
||||||
.id,
|
.id,
|
||||||
ap_url: act.object_props.id_string()?,
|
ap_url: act
|
||||||
|
.object()
|
||||||
|
.as_single_id()
|
||||||
|
.expect("exists and only")
|
||||||
|
.to_string(),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
res.notify(conn)?;
|
res.notify(conn)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user