mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
Add to
field for follow, undo follow
This commit is contained in:
parent
0dda2577e1
commit
2ad60379e4
2 changed files with 29 additions and 19 deletions
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
activities::send::generate_activity_id,
|
activities::send::generate_activity_id,
|
||||||
activity_queue::{send_activity_single_dest, send_to_community_followers},
|
activity_queue::{send_activity_single_dest, send_to_community_followers},
|
||||||
check_is_apub_id_valid,
|
check_is_apub_id_valid,
|
||||||
fetcher::get_or_fetch_and_upsert_actor,
|
fetcher::get_or_fetch_and_upsert_user,
|
||||||
ActorType,
|
ActorType,
|
||||||
ToApub,
|
ToApub,
|
||||||
};
|
};
|
||||||
|
@ -72,16 +72,15 @@ impl ActorType for Community {
|
||||||
.actor()?
|
.actor()?
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let actor = get_or_fetch_and_upsert_actor(actor_uri, context).await?;
|
let user = get_or_fetch_and_upsert_user(actor_uri, context).await?;
|
||||||
|
|
||||||
let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?);
|
let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?);
|
||||||
let to = actor.get_inbox_url()?;
|
|
||||||
accept
|
accept
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(AcceptType::Accept)?)
|
.set_id(generate_activity_id(AcceptType::Accept)?)
|
||||||
.set_to(to.clone());
|
.set_to(user.actor_id()?);
|
||||||
|
|
||||||
send_activity_single_dest(accept, self, to, context).await?;
|
send_activity_single_dest(accept, self, user.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::send::generate_activity_id,
|
activities::send::generate_activity_id,
|
||||||
activity_queue::send_activity_single_dest,
|
activity_queue::send_activity_single_dest,
|
||||||
fetcher::get_or_fetch_and_upsert_actor,
|
|
||||||
ActorType,
|
ActorType,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -11,8 +10,10 @@ use activitystreams::{
|
||||||
Undo,
|
Undo,
|
||||||
},
|
},
|
||||||
base::{AnyBase, BaseExt, ExtendsExt},
|
base::{AnyBase, BaseExt, ExtendsExt},
|
||||||
|
object::ObjectExt,
|
||||||
};
|
};
|
||||||
use lemmy_db::{user::User_, DbPool};
|
use lemmy_db::{community::Community, user::User_, DbPool};
|
||||||
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -41,14 +42,19 @@ impl ActorType for User_ {
|
||||||
follow_actor_id: &Url,
|
follow_actor_id: &Url,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id.as_str());
|
let follow_actor_id = follow_actor_id.to_string();
|
||||||
|
let community = blocking(context.pool(), move |conn| {
|
||||||
|
Community::read_from_actor_id(conn, &follow_actor_id)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
|
let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
|
||||||
follow
|
follow
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(FollowType::Follow)?);
|
.set_id(generate_activity_id(FollowType::Follow)?)
|
||||||
let follow_actor = get_or_fetch_and_upsert_actor(follow_actor_id, context).await?;
|
.set_to(community.actor_id()?);
|
||||||
let to = follow_actor.get_inbox_url()?;
|
|
||||||
|
|
||||||
send_activity_single_dest(follow, self, to, context).await?;
|
send_activity_single_dest(follow, self, community.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,21 +63,26 @@ impl ActorType for User_ {
|
||||||
follow_actor_id: &Url,
|
follow_actor_id: &Url,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id.as_str());
|
let follow_actor_id = follow_actor_id.to_string();
|
||||||
|
let community = blocking(context.pool(), move |conn| {
|
||||||
|
Community::read_from_actor_id(conn, &follow_actor_id)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
|
let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
|
||||||
follow
|
follow
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(FollowType::Follow)?);
|
.set_id(generate_activity_id(FollowType::Follow)?)
|
||||||
let follow_actor = get_or_fetch_and_upsert_actor(follow_actor_id, context).await?;
|
.set_to(community.actor_id()?);
|
||||||
|
|
||||||
let to = follow_actor.get_inbox_url()?;
|
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?);
|
let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?);
|
||||||
undo
|
undo
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?);
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
|
.set_to(community.actor_id()?);
|
||||||
|
|
||||||
send_activity_single_dest(undo, self, to, context).await?;
|
send_activity_single_dest(undo, self, community.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue