Refactor activity_pub::activity::Activity
I only had to wrap it in Arc… -_-
This commit is contained in:
@@ -6,7 +6,7 @@ use std::str::FromStr;
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::object::Object;
|
||||
|
||||
pub trait Activity: ActivityClone {
|
||||
pub trait Activity {
|
||||
fn get_id(&self) -> String;
|
||||
|
||||
fn serialize(&self) -> serde_json::Value;
|
||||
@@ -14,26 +14,6 @@ pub trait Activity: ActivityClone {
|
||||
// fn deserialize(serde_json::Value) -> Self;
|
||||
}
|
||||
|
||||
trait ActivityClone {
|
||||
fn clone_box(&self) -> Box<Activity>;
|
||||
}
|
||||
|
||||
impl<T> ActivityClone for T
|
||||
where
|
||||
T: 'static + Activity + Clone,
|
||||
{
|
||||
fn clone_box(&self) -> Box<Activity> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
// We can now implement Clone manually by forwarding to clone_box.
|
||||
impl Clone for Box<Activity> {
|
||||
fn clone(&self) -> Box<Activity> {
|
||||
self.clone_box()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Accept {
|
||||
id: String,
|
||||
|
||||
@@ -3,19 +3,20 @@ use rocket::http::Status;
|
||||
use rocket::response::{Response, Responder};
|
||||
use rocket::request::Request;
|
||||
use serde_json;
|
||||
use std::sync::Arc;
|
||||
|
||||
use activity_pub::{activity_pub, ActivityPub, context};
|
||||
use activity_pub::activity::Activity;
|
||||
use activity_pub::actor::Actor;
|
||||
use models::users::User;
|
||||
|
||||
pub struct Outbox<A> where A: Activity + Clone {
|
||||
pub struct Outbox {
|
||||
id: String,
|
||||
items: Vec<Box<A>>
|
||||
items: Vec<Arc<Activity>>
|
||||
}
|
||||
|
||||
impl<A: Activity + Clone + 'static> Outbox<A> {
|
||||
pub fn new(id: String, items: Vec<Box<A>>) -> Outbox<A> {
|
||||
impl Outbox {
|
||||
pub fn new(id: String, items: Vec<Arc<Activity>>) -> Outbox {
|
||||
Outbox {
|
||||
id: id,
|
||||
items: items
|
||||
@@ -34,7 +35,7 @@ impl<A: Activity + Clone + 'static> Outbox<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, A: Activity + Clone + 'static> Responder<'r> for Outbox<A> {
|
||||
impl<'r> Responder<'r> for Outbox {
|
||||
fn respond_to(self, request: &Request) -> Result<Response<'r>, Status> {
|
||||
self.serialize().respond_to(request)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user