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 -13
View File
@@ -35,19 +35,6 @@ impl Like {
find_by!(likes, find_by_ap_url, ap_url as &str);
find_by!(likes, find_by_user_on_post, user_id as i32, post_id as i32);
pub fn update_ap_url(&self, conn: &Connection) {
if self.ap_url.is_empty() {
diesel::update(self)
.set(likes::ap_url.eq(format!(
"{}/like/{}",
User::get(conn, self.user_id).expect("Like::update_ap_url: user error").ap_url,
Post::get(conn, self.post_id).expect("Like::update_ap_url: post error").ap_url
)))
.execute(conn)
.expect("Like::update_ap_url: update error");
}
}
pub fn to_activity(&self, conn: &Connection) -> activity::Like {
let mut act = activity::Like::default();
act.like_props
@@ -170,3 +157,14 @@ impl Deletable<Connection, activity::Undo> for Like {
}
}
}
impl NewLike {
pub fn new(p: &Post, u: &User) -> Self {
let ap_url = format!("{}/like/{}", u.ap_url, p.ap_url);
NewLike {
post_id: p.id,
user_id: u.id,
ap_url
}
}
}
+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
}
}
}