Follow activitystreams API change
This commit is contained in:
		
							parent
							
								
									28ec7c665f
								
							
						
					
					
						commit
						50a91ed678
					
				| @ -14,11 +14,11 @@ use crate::{ | |||||||
| use activitystreams::{ | use activitystreams::{ | ||||||
|     activity::{Create, Delete}, |     activity::{Create, Delete}, | ||||||
|     base::{AnyBase, Base}, |     base::{AnyBase, Base}, | ||||||
|     link, |     iri, link, | ||||||
|     object::{Note, ObjectExt}, |     object::{Note, ObjectExt}, | ||||||
|     prelude::*, |     prelude::*, | ||||||
|     primitives::OneOrMany, |     primitives::OneOrMany, | ||||||
|     public, uri as as_uri, |     public, | ||||||
| }; | }; | ||||||
| use chrono::{self, NaiveDateTime}; | use chrono::{self, NaiveDateTime}; | ||||||
| use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; | use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; | ||||||
| @ -152,8 +152,8 @@ impl Comment { | |||||||
|         let note = self.to_activity(&*conn)?; |         let note = self.to_activity(&*conn)?; | ||||||
|         let base = Base::retract(note)?.into_generic()?; |         let base = Base::retract(note)?.into_generic()?; | ||||||
|         let any_base = AnyBase::from_base(base); |         let any_base = AnyBase::from_base(base); | ||||||
|         let act = Create::new::<url::Url, OneOrMany<AnyBase>>( |         let act = Create::new::<_, OneOrMany<AnyBase>>( | ||||||
|             as_uri!(author.ap_url), |             iri!(author.ap_url), | ||||||
|             OneOrMany::from_one(any_base), |             OneOrMany::from_one(any_base), | ||||||
|         ); |         ); | ||||||
|         // let mut act = Create::default();
 |         // let mut act = Create::default();
 | ||||||
| @ -195,7 +195,7 @@ impl Comment { | |||||||
|         let base = Base::retract(comment)?.into_generic()?; |         let base = Base::retract(comment)?.into_generic()?; | ||||||
|         let any_base = AnyBase::from_base(base); |         let any_base = AnyBase::from_base(base); | ||||||
|         let act = Delete::new( |         let act = Delete::new( | ||||||
|             as_uri!(User::get(conn, self.author_id)?.ap_url), // FIXME
 |             iri!(User::get(conn, self.author_id)?.ap_url), // FIXME
 | ||||||
|             OneOrMany::from_one(any_base), |             OneOrMany::from_one(any_base), | ||||||
|         ); |         ); | ||||||
|         // let mut act = Delete::default();
 |         // let mut act = Delete::default();
 | ||||||
| @ -278,10 +278,7 @@ impl FromId<DbConn> for Comment { | |||||||
|                                 .to_string() |                                 .to_string() | ||||||
|                         }) |                         }) | ||||||
|                         .unwrap_or_default(), |                         .unwrap_or_default(), | ||||||
|                     ap_url: note |                     ap_url: note.id().map(|url| url.to_string()), | ||||||
|                         .id(&Instance::get_local()?.public_domain) |  | ||||||
|                         .expect("authorized domain") |  | ||||||
|                         .map(|url| url.to_string()), |  | ||||||
|                     in_response_to_id: previous_comment.iter().map(|c| c.id).next(), |                     in_response_to_id: previous_comment.iter().map(|c| c.id).next(), | ||||||
|                     post_id: previous_comment.map(|c| c.post_id).or_else(|_| { |                     post_id: previous_comment.map(|c| c.post_id).or_else(|_| { | ||||||
|                         Ok(Post::find_by_ap_url(conn, previous_url)?.id) as Result<i32> |                         Ok(Post::find_by_ap_url(conn, previous_url)?.id) as Result<i32> | ||||||
|  | |||||||
| @ -5,8 +5,8 @@ use crate::{ | |||||||
| use activitystreams::{ | use activitystreams::{ | ||||||
|     activity::{Accept, ActivityExt, ActorAndObjectRefExt, AsActivity, Follow as FollowAct, Undo}, |     activity::{Accept, ActivityExt, ActorAndObjectRefExt, AsActivity, Follow as FollowAct, Undo}, | ||||||
|     base::AnyBase, |     base::AnyBase, | ||||||
|  |     iri, | ||||||
|     primitives::OneOrMany, |     primitives::OneOrMany, | ||||||
|     uri as as_uri, |  | ||||||
| }; | }; | ||||||
| use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; | use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; | ||||||
| use plume_common::activity_pub::{ | use plume_common::activity_pub::{ | ||||||
| @ -60,8 +60,8 @@ impl Follow { | |||||||
|         let target = User::get(conn, self.following_id)?; |         let target = User::get(conn, self.following_id)?; | ||||||
| 
 | 
 | ||||||
|         let act = FollowAct::new( |         let act = FollowAct::new( | ||||||
|             as_uri!(user.ap_url),   // FIXME: Use to_activity()
 |             iri!(user.ap_url),   // FIXME: Use to_activity()
 | ||||||
|             as_uri!(target.ap_url), // FIXME: Use to_activity()
 |             iri!(target.ap_url), // FIXME: Use to_activity()
 | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         // let mut act = FollowAct::default();
 |         // let mut act = FollowAct::default();
 | ||||||
| @ -130,8 +130,8 @@ impl Follow { | |||||||
|         follow: FollowAct, |         follow: FollowAct, | ||||||
|     ) -> Result<Accept> { |     ) -> Result<Accept> { | ||||||
|         let accept = Accept::new( |         let accept = Accept::new( | ||||||
|             as_uri!(target.into_id()), // FIXME: Use to_activity()
 |             iri!(target.into_id()), // FIXME: Use to_activity()
 | ||||||
|             as_uri!(from.into_id()),   // FIXME: Use to_activity()
 |             iri!(from.into_id()),   // FIXME: Use to_activity()
 | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         // let mut accept = Accept::default();
 |         // let mut accept = Accept::default();
 | ||||||
| @ -157,12 +157,8 @@ impl Follow { | |||||||
| 
 | 
 | ||||||
|     pub fn build_undo(&self, conn: &Connection) -> Result<Undo> { |     pub fn build_undo(&self, conn: &Connection) -> Result<Undo> { | ||||||
|         let follow = self.to_activity(conn)?; |         let follow = self.to_activity(conn)?; | ||||||
|         let undo = Undo::new::<url::Url, OneOrMany<AnyBase>>( |         let undo = Undo::new::<_, OneOrMany<AnyBase>>( | ||||||
|             *follow |             *follow.actor().as_single_id().expect("exists and only"), | ||||||
|                 .actor() |  | ||||||
|                 .expect("authorized domain") |  | ||||||
|                 .as_single_id() |  | ||||||
|                 .expect("exists and only"), |  | ||||||
|             *follow.result().expect("exists"), |             *follow.result().expect("exists"), | ||||||
|         ); |         ); | ||||||
|         // let mut undo = Undo::default();
 |         // let mut undo = Undo::default();
 | ||||||
| @ -187,7 +183,7 @@ impl AsObject<User, FollowAct, &DbConn> for User { | |||||||
|     fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Follow> { |     fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Follow> { | ||||||
|         // Mastodon (at least) requires the full Follow object when accepting it,
 |         // Mastodon (at least) requires the full Follow object when accepting it,
 | ||||||
|         // so we rebuilt it here
 |         // so we rebuilt it here
 | ||||||
|         let follow = FollowAct::new(as_uri!(actor.ap_url), as_uri!(id)); |         let follow = FollowAct::new(iri!(actor.ap_url), iri!(id)); | ||||||
|         // let mut follow = FollowAct::default();
 |         // let mut follow = FollowAct::default();
 | ||||||
|         // follow.object_props.set_id_string(id.to_string())?;
 |         // follow.object_props.set_id_string(id.to_string())?;
 | ||||||
|         // follow
 |         // follow
 | ||||||
| @ -210,7 +206,6 @@ impl FromId<DbConn> for Follow { | |||||||
|             conn, |             conn, | ||||||
|             &follow |             &follow | ||||||
|                 .actor() |                 .actor() | ||||||
|                 .expect("authorized domain") |  | ||||||
|                 .as_single_id() |                 .as_single_id() | ||||||
|                 .expect("exists and only") |                 .expect("exists and only") | ||||||
|                 .as_str(), |                 .as_str(), | ||||||
|  | |||||||
| @ -5,8 +5,8 @@ use crate::{ | |||||||
| use activitystreams::{ | use activitystreams::{ | ||||||
|     activity::{self, ActivityExt, ActorAndObjectRefExt}, |     activity::{self, ActivityExt, ActorAndObjectRefExt}, | ||||||
|     base::AnyBase, |     base::AnyBase, | ||||||
|  |     iri, | ||||||
|     primitives::OneOrMany, |     primitives::OneOrMany, | ||||||
|     uri as as_uri, |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use chrono::NaiveDateTime; | use chrono::NaiveDateTime; | ||||||
| @ -41,8 +41,8 @@ impl Like { | |||||||
| 
 | 
 | ||||||
|     pub fn to_activity(&self, conn: &Connection) -> Result<activity::Like> { |     pub fn to_activity(&self, conn: &Connection) -> Result<activity::Like> { | ||||||
|         let act = activity::Like::new( |         let act = activity::Like::new( | ||||||
|             as_uri!(User::get(conn, self.user_id)?.ap_url), // FIXME: use to_activity()
 |             iri!(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()
 |             iri!(Post::get(conn, self.post_id)?.ap_url), // FIXME: use to_activity()
 | ||||||
|         ); |         ); | ||||||
|         // let mut act = activity::Like::default();
 |         // let mut act = activity::Like::default();
 | ||||||
|         // act.like_props
 |         // act.like_props
 | ||||||
| @ -78,12 +78,8 @@ impl Like { | |||||||
| 
 | 
 | ||||||
|     pub fn build_undo(&self, conn: &Connection) -> Result<activity::Undo> { |     pub fn build_undo(&self, conn: &Connection) -> Result<activity::Undo> { | ||||||
|         let like = self.to_activity(conn)?; |         let like = self.to_activity(conn)?; | ||||||
|         let act = activity::Undo::new::<url::Url, OneOrMany<AnyBase>>( |         let act = activity::Undo::new::<_, OneOrMany<AnyBase>>( | ||||||
|             *like |             *like.actor().as_single_id().expect("exists and only"), | ||||||
|                 .actor() |  | ||||||
|                 .expect("authorized domain") |  | ||||||
|                 .as_single_id() |  | ||||||
|                 .expect("exists and only"), |  | ||||||
|             *like.result().expect("exists"), |             *like.result().expect("exists"), | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
| @ -145,11 +141,7 @@ impl FromId<DbConn> for Like { | |||||||
|                 .id, |                 .id, | ||||||
|                 user_id: User::from_id( |                 user_id: User::from_id( | ||||||
|                     conn, |                     conn, | ||||||
|                     &act.actor() |                     &act.actor().as_single_id().expect("exists").as_str(), | ||||||
|                         .expect("authorized domain") |  | ||||||
|                         .as_single_id() |  | ||||||
|                         .expect("exists") |  | ||||||
|                         .as_str(), |  | ||||||
|                     None, |                     None, | ||||||
|                     CONFIG.proxy(), |                     CONFIG.proxy(), | ||||||
|                 ) |                 ) | ||||||
|  | |||||||
| @ -5,8 +5,8 @@ use crate::{ | |||||||
| use activitystreams::{ | use activitystreams::{ | ||||||
|     activity::{ActivityExt, ActorAndObjectRefExt, Announce, Undo}, |     activity::{ActivityExt, ActorAndObjectRefExt, Announce, Undo}, | ||||||
|     base::AnyBase, |     base::AnyBase, | ||||||
|  |     iri, | ||||||
|     primitives::OneOrMany, |     primitives::OneOrMany, | ||||||
|     uri as as_uri, |  | ||||||
| }; | }; | ||||||
| use chrono::NaiveDateTime; | use chrono::NaiveDateTime; | ||||||
| use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; | use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; | ||||||
| @ -66,8 +66,8 @@ impl Reshare { | |||||||
| 
 | 
 | ||||||
|     pub fn to_activity(&self, conn: &Connection) -> Result<Announce> { |     pub fn to_activity(&self, conn: &Connection) -> Result<Announce> { | ||||||
|         let act = Announce::new( |         let act = Announce::new( | ||||||
|             as_uri!(User::get(conn, self.user_id)?.ap_url), // FIXME: Use to_activity()
 |             iri!(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()
 |             iri!(Post::get(conn, self.post_id)?.ap_url), // FIXME: Use to_activity()
 | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         // let mut act = Announce::default();
 |         // let mut act = Announce::default();
 | ||||||
| @ -103,12 +103,8 @@ impl Reshare { | |||||||
| 
 | 
 | ||||||
|     pub fn build_undo(&self, conn: &Connection) -> Result<Undo> { |     pub fn build_undo(&self, conn: &Connection) -> Result<Undo> { | ||||||
|         let announce = self.to_activity(conn)?; |         let announce = self.to_activity(conn)?; | ||||||
|         let act = Undo::new::<url::Url, OneOrMany<AnyBase>>( |         let act = Undo::new::<_, OneOrMany<AnyBase>>( | ||||||
|             *announce |             *announce.actor().as_single_id().expect("exists and only"), | ||||||
|                 .actor() |  | ||||||
|                 .expect("authorized domain") |  | ||||||
|                 .as_single_id() |  | ||||||
|                 .expect("exists and only"), |  | ||||||
|             *announce.result().expect("exists"), |             *announce.result().expect("exists"), | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
| @ -173,11 +169,7 @@ impl FromId<DbConn> for Reshare { | |||||||
|                 .id, |                 .id, | ||||||
|                 user_id: User::from_id( |                 user_id: User::from_id( | ||||||
|                     conn, |                     conn, | ||||||
|                     &act.actor() |                     &act.actor().as_single_id().expect("exists").as_str(), | ||||||
|                         .expect("authorized domain") |  | ||||||
|                         .as_single_id() |  | ||||||
|                         .expect("exists") |  | ||||||
|                         .as_str(), |  | ||||||
|                     None, |                     None, | ||||||
|                     CONFIG.proxy(), |                     CONFIG.proxy(), | ||||||
|                 ) |                 ) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user