108 lines
3.4 KiB
Rust
108 lines
3.4 KiB
Rust
use super::{AcceptFollow, Follow as FollowRequested, RejectFollow, UndoAcceptFollow, UndoFollow};
|
|
use crate::{Completed, Context, Error, Required};
|
|
use activitystreams::{
|
|
activity::{Accept, Follow, Reject, Undo},
|
|
base::AnyBase,
|
|
context,
|
|
prelude::*,
|
|
security,
|
|
};
|
|
|
|
impl Completed for FollowRequested {
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let follow = ctx
|
|
.store
|
|
.view
|
|
.follow_requests
|
|
.by_id(self.follow_request_id)?
|
|
.req()?;
|
|
let actor_id = ctx.apub.apub_for_profile(follow.right)?.req()?;
|
|
let object_id = ctx.apub.apub_for_profile(follow.left)?.req()?;
|
|
let published = follow.published;
|
|
|
|
let follow_id = ctx.apub.info.gen_id();
|
|
ctx.apub
|
|
.follow_request(&follow_id, self.follow_request_id)?;
|
|
|
|
let mut follow = Follow::new(actor_id, object_id);
|
|
follow
|
|
.set_id(follow_id)
|
|
.set_published(published.into())
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let follow = follow.into_any_base()?;
|
|
ctx.apub.store_object(&follow)?;
|
|
|
|
Ok(follow)
|
|
}
|
|
}
|
|
|
|
impl Completed for RejectFollow {
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let person_id = ctx.apub.apub_for_profile(self.profile_id)?.req()?;
|
|
let follow_request = ctx.apub.object(&self.follow_apub_id)?.req()?;
|
|
|
|
let mut reject = Reject::new(person_id, follow_request);
|
|
reject
|
|
.set_id(ctx.apub.info.gen_id())
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let reject = reject.into_any_base()?;
|
|
ctx.apub.store_object(&reject)?;
|
|
|
|
Ok(reject)
|
|
}
|
|
}
|
|
|
|
impl Completed for AcceptFollow {
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let person_id = ctx.apub.apub_for_profile(self.profile_id)?.req()?;
|
|
let follow_request = ctx.apub.object(&self.follow_apub_id)?.req()?;
|
|
|
|
let accept_id = ctx.apub.info.gen_id();
|
|
ctx.apub.follow(&accept_id, self.follow_id)?;
|
|
|
|
let mut accept = Accept::new(person_id, follow_request);
|
|
accept
|
|
.set_id(accept_id)
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let accept = accept.into_any_base()?;
|
|
ctx.apub.store_object(&accept)?;
|
|
|
|
Ok(accept)
|
|
}
|
|
}
|
|
|
|
impl Completed for UndoAcceptFollow {
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let person_id = ctx.apub.apub_for_profile(self.profile_id)?.req()?;
|
|
let accept = ctx.apub.object(&self.accept_apub_id)?.req()?;
|
|
|
|
let mut undo = Undo::new(person_id, accept);
|
|
undo.set_id(ctx.apub.info.gen_id())
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let undo = undo.into_any_base()?;
|
|
ctx.apub.store_object(&undo)?;
|
|
|
|
Ok(undo)
|
|
}
|
|
}
|
|
|
|
impl Completed for UndoFollow {
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let person_id = ctx.apub.apub_for_profile(self.profile_id)?.req()?;
|
|
let follow = ctx.apub.object(&self.follow_apub_id)?.req()?;
|
|
|
|
let mut undo = Undo::new(person_id, follow);
|
|
undo.set_id(ctx.apub.info.gen_id())
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let undo = undo.into_any_base()?;
|
|
ctx.apub.store_object(&undo)?;
|
|
|
|
Ok(undo)
|
|
}
|
|
}
|