Make Like follow activitystreams 0.7
This commit is contained in:
parent
7a404c68df
commit
ff26149b7c
@ -2,13 +2,18 @@ use crate::{
|
||||
db_conn::DbConn, instance::Instance, notifications::*, posts::Post, schema::likes, timeline::*,
|
||||
users::User, Connection, Error, Result, CONFIG,
|
||||
};
|
||||
use activitypub::activity;
|
||||
use activitystreams::{
|
||||
activity::{self, ActivityExt, ActorAndObjectRefExt},
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
uri as as_uri,
|
||||
};
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use plume_common::activity_pub::{
|
||||
inbox::{AsActor, AsObject, FromId},
|
||||
sign::Signer,
|
||||
Id, IntoId, PUBLIC_VISIBILITY,
|
||||
};
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable)]
|
||||
@ -35,17 +40,21 @@ impl Like {
|
||||
find_by!(likes, find_by_user_on_post, user_id as i32, post_id as i32);
|
||||
|
||||
pub fn to_activity(&self, conn: &Connection) -> Result<activity::Like> {
|
||||
let mut act = activity::Like::default();
|
||||
act.like_props
|
||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
||||
act.like_props
|
||||
.set_object_link(Post::get(conn, self.post_id)?.into_id())?;
|
||||
act.object_props
|
||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||
act.object_props.set_cc_link_vec(vec![Id::new(
|
||||
User::get(conn, self.user_id)?.followers_endpoint,
|
||||
)])?;
|
||||
act.object_props.set_id_string(self.ap_url.clone())?;
|
||||
let act = activity::Like::new(
|
||||
as_uri!(User::get(conn, self.user_id)?.ap_url), // FIXME: use to_activity()
|
||||
as_uri!(Post::get(conn, self.post_id)?.ap_url), // FIXME: use to_activity()
|
||||
);
|
||||
// let mut act = activity::Like::default();
|
||||
// act.like_props
|
||||
// .set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
||||
// act.like_props
|
||||
// .set_object_link(Post::get(conn, self.post_id)?.into_id())?;
|
||||
// act.object_props
|
||||
// .set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
||||
// act.object_props.set_cc_link_vec(vec![Id::new(
|
||||
// User::get(conn, self.user_id)?.followers_endpoint,
|
||||
// )])?;
|
||||
// act.object_props.set_id_string(self.ap_url.clone())?;
|
||||
|
||||
Ok(act)
|
||||
}
|
||||
@ -68,17 +77,27 @@ impl Like {
|
||||
}
|
||||
|
||||
pub fn build_undo(&self, conn: &Connection) -> Result<activity::Undo> {
|
||||
let mut act = activity::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(
|
||||
User::get(conn, self.user_id)?.followers_endpoint,
|
||||
)])?;
|
||||
let like = self.to_activity(conn)?;
|
||||
let act = activity::Undo::new::<url::Url, OneOrMany<AnyBase>>(
|
||||
*like
|
||||
.actor()
|
||||
.expect("authorized domain")
|
||||
.as_single_id()
|
||||
.expect("exists and only"),
|
||||
*like.result().expect("exists"),
|
||||
);
|
||||
|
||||
// let mut act = activity::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(
|
||||
// User::get(conn, self.user_id)?.followers_endpoint,
|
||||
// )])?;
|
||||
|
||||
Ok(act)
|
||||
}
|
||||
@ -118,7 +137,7 @@ impl FromId<DbConn> for Like {
|
||||
NewLike {
|
||||
post_id: Post::from_id(
|
||||
conn,
|
||||
&act.like_props.object_link::<Id>()?,
|
||||
&act.object().as_single_id().expect("exists").as_str(),
|
||||
None,
|
||||
CONFIG.proxy(),
|
||||
)
|
||||
@ -126,13 +145,17 @@ impl FromId<DbConn> for Like {
|
||||
.id,
|
||||
user_id: User::from_id(
|
||||
conn,
|
||||
&act.like_props.actor_link::<Id>()?,
|
||||
&act.actor()
|
||||
.expect("authorized domain")
|
||||
.as_single_id()
|
||||
.expect("exists")
|
||||
.as_str(),
|
||||
None,
|
||||
CONFIG.proxy(),
|
||||
)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
ap_url: act.object_props.id_string()?,
|
||||
ap_url: act.object().as_single_id().expect("exists").to_string(),
|
||||
},
|
||||
)?;
|
||||
res.notify(conn)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user