mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 13:31:02 +00:00
Receive likes with ActivityPub
This commit is contained in:
parent
7b5f0f1704
commit
ac7b4441e8
2 changed files with 25 additions and 9 deletions
|
@ -6,8 +6,9 @@ use activity_pub::actor::Actor;
|
|||
use activity_pub::sign::*;
|
||||
use models::blogs::Blog;
|
||||
use models::comments::*;
|
||||
use models::follows::{Follow, NewFollow};
|
||||
use models::posts::{Post, NewPost};
|
||||
use models::follows::*;
|
||||
use models::likes::*;
|
||||
use models::posts::*;
|
||||
use models::users::User;
|
||||
|
||||
pub trait Inbox: Actor + Sized {
|
||||
|
@ -58,6 +59,14 @@ pub trait Inbox: Actor + Sized {
|
|||
|
||||
// TODO: notification
|
||||
}
|
||||
"Like" => {
|
||||
let liker = User::from_url(conn, act["actor"].as_str().unwrap().to_string());
|
||||
let post = Post::get_by_ap_url(conn, act["object"].as_str().unwrap().to_string());
|
||||
Like::insert(conn, NewLike {
|
||||
post_id: post.unwrap().id,
|
||||
user_id: liker.unwrap().id
|
||||
});
|
||||
},
|
||||
x => println!("Received unknow activity type: {}", x)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,31 @@
|
|||
use chrono;
|
||||
use diesel::{PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
|
||||
use schema::likes;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Like {
|
||||
id: i32,
|
||||
user_id: i32,
|
||||
post_id: i32,
|
||||
creation_date: chrono::NaiveDateTime
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub creation_date: chrono::NaiveDateTime
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "likes"]
|
||||
pub struct NewLike {
|
||||
user_id: i32,
|
||||
post_id: i32
|
||||
pub user_id: i32,
|
||||
pub post_id: i32
|
||||
}
|
||||
|
||||
impl Like {
|
||||
pub fn insert(conn: &PgConnection, new: NewLike) -> Like {
|
||||
diesel::insert_into(likes::table)
|
||||
.values(new)
|
||||
.get_result(conn)
|
||||
.expect("Unable to insert new like")
|
||||
}
|
||||
|
||||
pub fn get(conn: &PgConnection, id: i32) -> Option<Like> {
|
||||
likes::table.filter(likes::id.eq(id))
|
||||
.limit(1)
|
||||
|
|
Loading…
Reference in a new issue