Fix local notifications

This commit is contained in:
Bat 2018-06-18 12:32:03 +01:00
parent cdb8aba6ec
commit 36bf2e114c
6 changed files with 16 additions and 11 deletions

6
Cargo.lock generated
View File

@ -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)" = "<none>"
"checksum rocket_contrib 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)" = "<none>"
"checksum rocket_http 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket?rev=df7111143e466c18d1f56377a8d9530a5a306aba)" = "<none>"
"checksum rocket_i18n 0.1.1 (git+https://github.com/BaptisteGelez/rocket_i18n?rev=457b88c59ec31905a9193df43df58bee55b4b83d)" = "<none>"
"checksum rocket_i18n 0.1.1 (git+https://github.com/BaptisteGelez/rocket_i18n?rev=5b4225d5bed5769482dc926a7e6d6b79f1217be6)" = "<none>"
"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"

View File

@ -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
}

View File

@ -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<NewComment
spoiler_text: "".to_string()
});
Comment::notify(&*conn, comment.into_activity(&*conn), user.clone().into_id());
broadcast(&*conn, &user, comment.create_activity(&*conn), user.get_followers(&*conn));
Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id))

View File

@ -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::{
likes,
@ -16,12 +16,13 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> 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();

View File

@ -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();

View File

@ -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::<Id>(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))
}