Give reshare and like ap_url before inserting (#369)

Fix #367
This commit is contained in:
fdb-hiroshima
2018-12-23 11:13:02 +01:00
committed by GitHub
parent 0ea1d57e48
commit 0df9c4d400
4 changed files with 24 additions and 42 deletions
+11 -17
View File
@@ -40,23 +40,6 @@ impl Reshare {
post_id as i32
);
pub fn update_ap_url(&self, conn: &Connection) {
if self.ap_url.is_empty() {
diesel::update(self)
.set(reshares::ap_url.eq(format!(
"{}/reshare/{}",
User::get(conn, self.user_id)
.expect("Reshare::update_ap_url: user error")
.ap_url,
Post::get(conn, self.post_id)
.expect("Reshare::update_ap_url: post error")
.ap_url
)))
.execute(conn)
.expect("Reshare::update_ap_url: update error");
}
}
pub fn get_recents_for_author(conn: &Connection, user: &User, limit: i64) -> Vec<Reshare> {
reshares::table
.filter(reshares::user_id.eq(user.id))
@@ -201,3 +184,14 @@ impl Deletable<Connection, Undo> for Reshare {
}
}
}
impl NewReshare {
pub fn new(p: &Post, u: &User) -> Self {
let ap_url = format!("{}/reshare/{}", u.ap_url, p.ap_url);
NewReshare {
post_id: p.id,
user_id: u.id,
ap_url
}
}
}