asonix
ab8aa2cbe1
- Add image purge to profile update - Add outbound processing in apub ingest - Add follower + follow request cleanup in profile delete - Add inboxes + id to Outbound trait
109 lines
3.2 KiB
Rust
109 lines
3.2 KiB
Rust
use super::{React, UndoReact};
|
|
use crate::{Context, Error, Outbound, Required};
|
|
use activitystreams::{
|
|
activity::{Create, Delete, Like},
|
|
base::AnyBase,
|
|
context,
|
|
prelude::*,
|
|
public, security,
|
|
};
|
|
use url::Url;
|
|
use uuid::Uuid;
|
|
|
|
impl Outbound for React {
|
|
fn id(&self) -> Option<Uuid> {
|
|
Some(self.react_id)
|
|
}
|
|
|
|
fn inboxes(&self, ctx: &Context) -> Result<Vec<Url>, Error> {
|
|
let react = ctx.store.reacts.by_id(self.react_id)?.req()?;
|
|
|
|
let notifier_id = if let Some(comment_id) = react.comment_id() {
|
|
ctx.store.comments.by_id(comment_id)?.req()?.profile_id()
|
|
} else {
|
|
ctx.store
|
|
.submissions
|
|
.by_id(react.submission_id())?
|
|
.req()?
|
|
.profile_id()
|
|
};
|
|
|
|
let inbox = ctx.apub.endpoints_for_profile(notifier_id)?.req()?.inbox;
|
|
|
|
Ok(vec![inbox])
|
|
}
|
|
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let react = ctx.store.reacts.by_id(self.react_id)?.req()?;
|
|
let person_id = ctx.apub.apub_for_profile(react.profile_id())?.req()?;
|
|
|
|
let note_id = if let Some(comment_id) = react.comment_id() {
|
|
ctx.apub.apub_for_comment(comment_id)?.req()?
|
|
} else {
|
|
ctx.apub.apub_for_submission(react.submission_id())?.req()?
|
|
};
|
|
|
|
let published = react.published();
|
|
let endpoints = ctx.apub.endpoints_for_profile(react.profile_id())?.req()?;
|
|
|
|
let mut like = Like::new(person_id.clone(), note_id);
|
|
like.set_id(ctx.apub.info.gen_id().req()?)
|
|
.set_content(react.react())
|
|
.set_published(published.into())
|
|
.set_attributed_to(person_id.clone())
|
|
.add_to(endpoints.followers)
|
|
.add_cc(public());
|
|
|
|
let like = like.into_any_base()?;
|
|
ctx.apub.store_object(&like)?;
|
|
|
|
let mut create = Create::new(person_id, like);
|
|
create
|
|
.set_id(ctx.apub.info.gen_id().req()?)
|
|
.add_context(context())
|
|
.add_context(security());
|
|
|
|
let create = create.into_any_base()?;
|
|
ctx.apub.store_object(&create)?;
|
|
|
|
Ok(create)
|
|
}
|
|
}
|
|
|
|
impl Outbound for UndoReact {
|
|
fn id(&self) -> Option<Uuid> {
|
|
None
|
|
}
|
|
|
|
fn inboxes(&self, ctx: &Context) -> Result<Vec<Url>, Error> {
|
|
let notifier_id = if let Some(comment_id) = self.comment_id {
|
|
ctx.store.comments.by_id(comment_id)?.req()?.profile_id()
|
|
} else {
|
|
ctx.store
|
|
.submissions
|
|
.by_id(self.submission_id)?
|
|
.req()?
|
|
.profile_id()
|
|
};
|
|
|
|
let inbox = ctx.apub.endpoints_for_profile(notifier_id)?.req()?.inbox;
|
|
|
|
Ok(vec![inbox])
|
|
}
|
|
|
|
fn to_apub(&self, ctx: &Context) -> Result<AnyBase, Error> {
|
|
let person_id = ctx.apub.apub_for_profile(self.profile_id)?.req()?;
|
|
let like = ctx.apub.object(&self.like_apub_id)?.req()?;
|
|
|
|
let mut delete = Delete::new(person_id, like);
|
|
delete
|
|
.set_id(ctx.apub.info.gen_id().req()?)
|
|
.add_context(context())
|
|
.add_context(security());
|
|
let delete = delete.into_any_base()?;
|
|
ctx.apub.store_object(&delete)?;
|
|
|
|
Ok(delete)
|
|
}
|
|
}
|