mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-16 00:21:04 +00:00
WIP: inboxes
This commit is contained in:
parent
14534d1ff3
commit
03df88e186
5 changed files with 48 additions and 0 deletions
29
src/activity_pub/inbox.rs
Normal file
29
src/activity_pub/inbox.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use diesel::PgConnection;
|
||||
use serde_json;
|
||||
|
||||
use models::posts::{Post, NewPost};
|
||||
|
||||
pub trait Inbox {
|
||||
fn received(&self, conn: &PgConnection, act: serde_json::Value);
|
||||
|
||||
fn save(&self, conn: &PgConnection, act: serde_json::Value) {
|
||||
match act["type"].as_str().unwrap() {
|
||||
"Create" => {
|
||||
match act["object"]["type"].as_str().unwrap() {
|
||||
"Article" => {
|
||||
Post::insert(conn, NewPost {
|
||||
blog_id: 0,
|
||||
slug: String::from(""),
|
||||
title: String::from(""),
|
||||
content: act["object"]["content"].as_str().unwrap().to_string(),
|
||||
published: true,
|
||||
license: String::from("CC-0")
|
||||
});
|
||||
},
|
||||
x => println!("Received a new {}, but didn't saved it", x)
|
||||
}
|
||||
},
|
||||
x => println!("Received unknow activity type: {}", x)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ use serde_json;
|
|||
|
||||
pub mod activity;
|
||||
pub mod actor;
|
||||
pub mod inbox;
|
||||
pub mod object;
|
||||
pub mod outbox;
|
||||
pub mod sign;
|
||||
|
|
|
@ -57,6 +57,7 @@ fn main() {
|
|||
routes::user::details,
|
||||
routes::user::activity_details,
|
||||
routes::user::outbox,
|
||||
routes::user::inbox,
|
||||
routes::user::new,
|
||||
routes::user::create,
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use serde_json;
|
|||
|
||||
use activity_pub::activity::Activity;
|
||||
use activity_pub::actor::{ActorType, Actor};
|
||||
use activity_pub::inbox::Inbox;
|
||||
use activity_pub::outbox::Outbox;
|
||||
use activity_pub::webfinger::{Webfinger, resolve};
|
||||
use db_conn::DbConn;
|
||||
|
@ -226,6 +227,13 @@ impl Actor for User {
|
|||
}
|
||||
}
|
||||
|
||||
impl Inbox for User {
|
||||
fn received(&self, conn: &PgConnection, act: serde_json::Value) {
|
||||
self.save(conn, act);
|
||||
// TODO: add to stream or create notification, or whatever needs to be done
|
||||
}
|
||||
}
|
||||
|
||||
impl Webfinger for User {
|
||||
fn webfinger_subject(&self, conn: &PgConnection) -> String {
|
||||
format!("acct:{}@{}", self.username, self.get_instance(conn).public_domain)
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::collections::HashMap;
|
|||
|
||||
use activity_pub::ActivityPub;
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::inbox::Inbox;
|
||||
use activity_pub::outbox::Outbox;
|
||||
use db_conn::DbConn;
|
||||
use models::instance::Instance;
|
||||
|
@ -68,3 +69,11 @@ fn outbox(name: String, conn: DbConn) -> Outbox {
|
|||
let user = User::find_local(&*conn, name).unwrap();
|
||||
user.outbox(&*conn)
|
||||
}
|
||||
|
||||
#[post("/@/<name>/inbox", data = "<data>")]
|
||||
fn inbox(name: String, conn: DbConn, data: String) -> String {
|
||||
let user = User::find_local(&*conn, name).unwrap();
|
||||
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
|
||||
user.received(&*conn, act);
|
||||
String::from("")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue