Process outbound in new thread
This commit is contained in:
parent
d53dfe9fda
commit
5c280ef6f6
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Action for CreateBlock {
|
impl Action for CreateBlock {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let block = context.store.view.blocks.new(
|
let block = context.store.view.blocks.new(
|
||||||
self.blocked_profile,
|
self.blocked_profile,
|
||||||
self.blocked_by_profile,
|
self.blocked_by_profile,
|
||||||
|
@ -88,7 +88,7 @@ impl Action for CreateBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for DeleteBlock {
|
impl Action for DeleteBlock {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context.store.view.blocks.remove(self.block_id)?;
|
let opt = context.store.view.blocks.remove(self.block_id)?;
|
||||||
let block_apub_id = context.apub.apub_for_block(self.block_id)?.req()?;
|
let block_apub_id = context.apub.apub_for_block(self.block_id)?.req()?;
|
||||||
context.apub.delete_object(&block_apub_id)?;
|
context.apub.delete_object(&block_apub_id)?;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::actions::{AnnounceComment, CreateComment, DeleteComment, DeleteReact, UpdateComment},
|
apub::actions::{AnnounceComment, CreateComment, DeleteComment, DeleteReact, UpdateComment},
|
||||||
Action, Outbound, Context, Error, Required,
|
Action, Context, Error, Outbound, Required,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Action for CreateComment {
|
impl Action for CreateComment {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let submissioner_id = context
|
let submissioner_id = context
|
||||||
.store
|
.store
|
||||||
.submissions
|
.submissions
|
||||||
|
@ -79,13 +79,13 @@ impl Action for CreateComment {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for AnnounceComment {
|
impl Action for AnnounceComment {
|
||||||
fn perform(&self, _: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, _: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for UpdateComment {
|
impl Action for UpdateComment {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let comment = context.store.comments.by_id(self.comment_id)?.req()?;
|
let comment = context.store.comments.by_id(self.comment_id)?.req()?;
|
||||||
|
|
||||||
let mut changes = comment.update();
|
let mut changes = comment.update();
|
||||||
|
@ -126,7 +126,7 @@ fn delete_react(react_id: uuid::Uuid, context: &Context) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for DeleteComment {
|
impl Action for DeleteComment {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context.store.comments.delete(self.comment_id)?;
|
let opt = context.store.comments.delete(self.comment_id)?;
|
||||||
context.store.view.comments.remove(self.comment_id);
|
context.store.view.comments.remove(self.comment_id);
|
||||||
context.apub.delete_object(&self.note_apub_id)?;
|
context.apub.delete_object(&self.note_apub_id)?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Action for UndoFollow {
|
impl Action for UndoFollow {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context.store.view.follows.remove(self.follow_id)?;
|
let opt = context.store.view.follows.remove(self.follow_id)?;
|
||||||
let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?;
|
let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?;
|
||||||
context.apub.delete_object(&accept_apub_id)?;
|
context.apub.delete_object(&accept_apub_id)?;
|
||||||
|
@ -25,7 +25,7 @@ impl Action for UndoFollow {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for UndoAcceptFollow {
|
impl Action for UndoAcceptFollow {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context.store.view.follows.remove(self.follow_id)?;
|
let opt = context.store.view.follows.remove(self.follow_id)?;
|
||||||
let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?;
|
let accept_apub_id = context.apub.apub_for_follow(self.follow_id)?.req()?;
|
||||||
context.apub.delete_object(&accept_apub_id)?;
|
context.apub.delete_object(&accept_apub_id)?;
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Action for CreateFollowRequest {
|
impl Action for CreateFollowRequest {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
context.check_block(self.followed_by_profile, self.followed_profile)?;
|
context.check_block(self.followed_by_profile, self.followed_profile)?;
|
||||||
|
|
||||||
let follow_request = context.store.view.follow_requests.new(
|
let follow_request = context.store.view.follow_requests.new(
|
||||||
|
@ -40,7 +40,7 @@ impl Action for CreateFollowRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for AcceptFollowRequest {
|
impl Action for AcceptFollowRequest {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context
|
let opt = context
|
||||||
.store
|
.store
|
||||||
.view
|
.view
|
||||||
|
@ -82,7 +82,7 @@ impl Action for AcceptFollowRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for RejectFollowRequest {
|
impl Action for RejectFollowRequest {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context
|
let opt = context
|
||||||
.store
|
.store
|
||||||
.view
|
.view
|
||||||
|
@ -118,7 +118,7 @@ impl Action for RejectFollowRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for UndoFollowRequest {
|
impl Action for UndoFollowRequest {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let opt = context
|
let opt = context
|
||||||
.store
|
.store
|
||||||
.view
|
.view
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Action for CreateProfile {
|
impl Action for CreateProfile {
|
||||||
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let profile = ctx.store.profiles.create(
|
let profile = ctx.store.profiles.create(
|
||||||
self.owner_source.clone(),
|
self.owner_source.clone(),
|
||||||
&self.handle,
|
&self.handle,
|
||||||
|
@ -53,7 +53,7 @@ impl Action for CreateProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for UpdateProfile {
|
impl Action for UpdateProfile {
|
||||||
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let profile = ctx.store.profiles.by_id(self.profile_id)?.req()?;
|
let profile = ctx.store.profiles.by_id(self.profile_id)?.req()?;
|
||||||
|
|
||||||
let mut changes = profile.update();
|
let mut changes = profile.update();
|
||||||
|
@ -115,7 +115,7 @@ fn delete_submission(submission_id: uuid::Uuid, ctx: &Context) -> Result<(), Err
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for DeleteProfile {
|
impl Action for DeleteProfile {
|
||||||
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, ctx: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let profile_id = self.profile_id;
|
let profile_id = self.profile_id;
|
||||||
let opt = ctx.store.profiles.delete(profile_id)?;
|
let opt = ctx.store.profiles.delete(profile_id)?;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Action for CreateReact {
|
impl Action for CreateReact {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let submissioner_id = context
|
let submissioner_id = context
|
||||||
.store
|
.store
|
||||||
.submissions
|
.submissions
|
||||||
|
@ -62,7 +62,7 @@ impl Action for CreateReact {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for DeleteReact {
|
impl Action for DeleteReact {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let react_id = self.react_id;
|
let react_id = self.react_id;
|
||||||
let opt = context.store.reacts.delete(react_id)?;
|
let opt = context.store.reacts.delete(react_id)?;
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ use crate::{
|
||||||
apub::actions::{
|
apub::actions::{
|
||||||
AnnounceSubmission, CreateSubmission, DeleteComment, DeleteSubmission, UpdateSubmission,
|
AnnounceSubmission, CreateSubmission, DeleteComment, DeleteSubmission, UpdateSubmission,
|
||||||
},
|
},
|
||||||
Action, Outbound, Context, Error, Required,
|
Action, Context, Error, Outbound, Required,
|
||||||
};
|
};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
impl Action for CreateSubmission {
|
impl Action for CreateSubmission {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let submission =
|
let submission =
|
||||||
context
|
context
|
||||||
.store
|
.store
|
||||||
|
@ -60,13 +60,13 @@ impl Action for CreateSubmission {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for AnnounceSubmission {
|
impl Action for AnnounceSubmission {
|
||||||
fn perform(&self, _: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, _: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for UpdateSubmission {
|
impl Action for UpdateSubmission {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let submission_id = self.submission_id;
|
let submission_id = self.submission_id;
|
||||||
let submission = context.store.submissions.by_id(submission_id)?.req()?;
|
let submission = context.store.submissions.by_id(submission_id)?.req()?;
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ fn delete_comment(comment_id: uuid::Uuid, context: &Context) -> Result<(), Error
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for DeleteSubmission {
|
impl Action for DeleteSubmission {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error> {
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error> {
|
||||||
let submission_id = self.submission_id;
|
let submission_id = self.submission_id;
|
||||||
let opt = context.store.submissions.delete(submission_id)?;
|
let opt = context.store.submissions.delete(submission_id)?;
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ enum RecoverableError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Action {
|
pub trait Action {
|
||||||
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound>>, Error>;
|
fn perform(&self, context: &Context) -> Result<Option<Box<dyn Outbound + Send>>, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Outbound {
|
pub trait Outbound {
|
||||||
|
@ -171,8 +171,10 @@ impl State {
|
||||||
|
|
||||||
match action.perform(&ctx)? {
|
match action.perform(&ctx)? {
|
||||||
Some(outbound) => {
|
Some(outbound) => {
|
||||||
ctx.deliver(&*outbound);
|
let id = outbound.id();
|
||||||
Ok(outbound.id())
|
let context_clone = ctx.clone();
|
||||||
|
ctx.spawn_blocking(move || context_clone.deliver(&*outbound));
|
||||||
|
Ok(id)
|
||||||
}
|
}
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue