From 36bf2e114c493385a823bf6346475008747b8031 Mon Sep 17 00:00:00 2001 From: Bat Date: Mon, 18 Jun 2018 12:32:03 +0100 Subject: [PATCH] Fix local notifications --- Cargo.lock | 6 +++--- src/models/instance.rs | 2 +- src/routes/comments.rs | 3 ++- src/routes/likes.rs | 9 +++++---- src/routes/reshares.rs | 3 ++- src/routes/user.rs | 4 +++- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6875108..272d796f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1014,7 +1014,7 @@ dependencies = [ "rocket 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)", "rocket_codegen 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)", "rocket_contrib 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)", - "rocket_i18n 0.1.1 (git+https://github.com/BaptisteGelez/rocket_i18n?rev=457b88c59ec31905a9193df43df58bee55b4b83d)", + "rocket_i18n 0.1.1 (git+https://github.com/BaptisteGelez/rocket_i18n?rev=5b4225d5bed5769482dc926a7e6d6b79f1217be6)", "serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.43 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1273,7 +1273,7 @@ dependencies = [ [[package]] name = "rocket_i18n" version = "0.1.1" -source = "git+https://github.com/BaptisteGelez/rocket_i18n?rev=457b88c59ec31905a9193df43df58bee55b4b83d#457b88c59ec31905a9193df43df58bee55b4b83d" +source = "git+https://github.com/BaptisteGelez/rocket_i18n?rev=5b4225d5bed5769482dc926a7e6d6b79f1217be6#5b4225d5bed5769482dc926a7e6d6b79f1217be6" dependencies = [ "gettext-rs 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rocket 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)", @@ -2097,7 +2097,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rocket_codegen_next 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)" = "" "checksum rocket_contrib 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)" = "" "checksum rocket_http 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)" = "" -"checksum rocket_i18n 0.1.1 (git+https://github.com/BaptisteGelez/rocket_i18n?rev=457b88c59ec31905a9193df43df58bee55b4b83d)" = "" +"checksum rocket_i18n 0.1.1 (git+https://github.com/BaptisteGelez/rocket_i18n?rev=5b4225d5bed5769482dc926a7e6d6b79f1217be6)" = "" "checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum schannel 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "85fd9df495640643ad2d00443b3d78aae69802ad488debab4f1dd52fc1806ade" diff --git a/src/models/instance.rs b/src/models/instance.rs index c3967092..c4861ee1 100644 --- a/src/models/instance.rs +++ b/src/models/instance.rs @@ -86,7 +86,7 @@ impl Instance { impl Inbox for Instance { fn received(&self, conn: &PgConnection, act: serde_json::Value) { - self.save(conn, act.clone()).unwrap(); + self.save(conn, act.clone()).expect("Shared Inbox: Couldn't save activity"); // TODO: add to stream, or whatever needs to be done } diff --git a/src/routes/comments.rs b/src/routes/comments.rs index 7c039ee7..56cbb805 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -4,7 +4,7 @@ use rocket::{ }; use rocket_contrib::Template; -use activity_pub::broadcast; +use activity_pub::{broadcast, IntoId, inbox::Notify}; use db_conn::DbConn; use models::{ comments::*, @@ -53,6 +53,7 @@ fn create(blog: String, slug: String, query: CommentQuery, data: Form Redirect { if !user.has_liked(&*conn, &post) { let like = likes::Like::insert(&*conn, likes::NewLike { - post_id: post.id, - user_id: user.id, - ap_url: "".to_string() + post_id: post.id, + user_id: user.id, + ap_url: "".to_string() }); like.update_ap_url(&*conn); + likes::Like::notify(&*conn, like.into_activity(&*conn), user.clone().into_id()); broadcast(&*conn, &user, like.into_activity(&*conn), user.get_followers(&*conn)); } else { let like = likes::Like::find_by_user_on_post(&*conn, &user, &post).unwrap(); diff --git a/src/routes/reshares.rs b/src/routes/reshares.rs index 50698645..cabe22ee 100644 --- a/src/routes/reshares.rs +++ b/src/routes/reshares.rs @@ -1,6 +1,6 @@ use rocket::response::{Redirect, Flash}; -use activity_pub::broadcast; +use activity_pub::{broadcast, IntoId, inbox::Notify}; use db_conn::DbConn; use models::{ posts::Post, @@ -22,6 +22,7 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect { }); reshare.update_ap_url(&*conn); + Reshare::notify(&*conn, reshare.into_activity(&*conn), user.clone().into_id()); broadcast(&*conn, &user, reshare.into_activity(&*conn), user.get_followers(&*conn)); } else { let reshare = Reshare::find_by_user_on_post(&*conn, &user, &post).unwrap(); diff --git a/src/routes/user.rs b/src/routes/user.rs index 2bc25ec6..50258360 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -10,7 +10,7 @@ use serde_json; use activity_pub::{ activity_pub, ActivityPub, ActivityStream, context, broadcast, Id, IntoId, - inbox::Inbox, + inbox::{Inbox, Notify}, actor::Actor }; use db_conn::DbConn; @@ -103,6 +103,8 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect { act.follow_props.set_actor_link::(user.clone().into_id()).unwrap(); act.follow_props.set_object_object(user.into_activity(&*conn)).unwrap(); act.object_props.set_id_string(format!("{}/follow/{}", user.ap_url, target.ap_url)).unwrap(); + + follows::Follow::notify(&*conn, act.clone(), user.clone().into_id()); broadcast(&*conn, &user, act, vec![target]); Redirect::to(format!("/@/{}/", name)) }