Allow likes to be deleted with AP
This commit is contained in:
+20
-2
@@ -13,14 +13,16 @@ pub struct Like {
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub creation_date: chrono::NaiveDateTime
|
||||
pub creation_date: chrono::NaiveDateTime,
|
||||
pub ap_url: String
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "likes"]
|
||||
pub struct NewLike {
|
||||
pub user_id: i32,
|
||||
pub post_id: i32
|
||||
pub post_id: i32,
|
||||
pub ap_url: String
|
||||
}
|
||||
|
||||
impl Like {
|
||||
@@ -31,6 +33,14 @@ impl Like {
|
||||
.expect("Unable to insert new like")
|
||||
}
|
||||
|
||||
pub fn update_ap_url(&self, conn: &PgConnection) {
|
||||
if self.ap_url.len() == 0 {
|
||||
diesel::update(self)
|
||||
.set(likes::ap_url.eq(self.compute_id(conn)))
|
||||
.get_result::<Like>(conn).expect("Couldn't update AP URL");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(conn: &PgConnection, id: i32) -> Option<Like> {
|
||||
likes::table.filter(likes::id.eq(id))
|
||||
.limit(1)
|
||||
@@ -39,6 +49,14 @@ impl Like {
|
||||
.into_iter().nth(0)
|
||||
}
|
||||
|
||||
pub fn find_by_ap_url(conn: &PgConnection, ap_url: String) -> Option<Like> {
|
||||
likes::table.filter(likes::ap_url.eq(ap_url))
|
||||
.limit(1)
|
||||
.load::<Like>(conn)
|
||||
.expect("Error loading like by AP URL")
|
||||
.into_iter().nth(0)
|
||||
}
|
||||
|
||||
pub fn for_user_on_post(conn: &PgConnection, user: &User, post: &Post) -> Option<Like> {
|
||||
likes::table.filter(likes::post_id.eq(post.id))
|
||||
.filter(likes::user_id.eq(user.id))
|
||||
|
||||
Reference in New Issue
Block a user