From 2a34b7909a942ef2d20ba65d2a90b6bad30b1ce1 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 17 Jun 2018 19:42:17 +0100 Subject: [PATCH 1/4] Add a note for translators --- INTERNATIONALIZATION.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/INTERNATIONALIZATION.md b/INTERNATIONALIZATION.md index cbb04979..7b26e836 100644 --- a/INTERNATIONALIZATION.md +++ b/INTERNATIONALIZATION.md @@ -33,3 +33,7 @@ Then you should fill the two `msgstr` field, one with the singular form, the sec ## Interpolation Strings you translate may contain data from Plume (a username for instance). To tell Plume where to put these data, surround their identifier by `{{` and `}}`. The identifier is also present in this form in the English string to translate (this what you can see above, with the `{{ count }} posts` message). + +## Note + +When translating, please try to be as inclusive as possible. From 0ea8c882ad78ddfe3c4997bd334d89d0e9da1dfb Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 17 Jun 2018 20:37:10 +0100 Subject: [PATCH 2/4] Actually use the activity_pub::inbox::Notify trait for notifications It won't work for local events until we use AP internally too --- src/activity_pub/inbox.rs | 4 +-- src/models/comments.rs | 30 +++++++++++++++++++--- src/models/follows.rs | 21 ++++++++++++--- src/models/likes.rs | 27 +++++++++++++++++--- src/models/posts.rs | 2 +- src/models/reshares.rs | 28 ++++++++++++++++---- src/models/users.rs | 54 --------------------------------------- 7 files changed, 93 insertions(+), 73 deletions(-) diff --git a/src/activity_pub/inbox.rs b/src/activity_pub/inbox.rs index cbd67f39..1d8fe0a6 100644 --- a/src/activity_pub/inbox.rs +++ b/src/activity_pub/inbox.rs @@ -1,5 +1,5 @@ use activitypub::{ - Activity, Object, + Object, activity::{Create, Like, Undo} }; use diesel::PgConnection; @@ -40,7 +40,7 @@ pub trait FromActivity: Sized { } } -pub trait Notify { +pub trait Notify { fn notify(conn: &PgConnection, act: T, actor: Id); } diff --git a/src/models/comments.rs b/src/models/comments.rs index be66f878..ed15465d 100644 --- a/src/models/comments.rs +++ b/src/models/comments.rs @@ -9,11 +9,12 @@ use serde_json; use activity_pub::{ ap_url, Id, IntoId, PUBLIC_VISIBILTY, actor::Actor, - inbox::FromActivity, + inbox::{FromActivity, Notify}, object::Object }; use models::{ instance::Instance, + notifications::*, posts::Post, users::User }; @@ -128,7 +129,7 @@ impl FromActivity for Comment { fn from_activity(conn: &PgConnection, note: Note, actor: Id) -> Comment { let previous_url = note.object_props.in_reply_to.clone().unwrap().as_str().unwrap().to_string(); let previous_comment = Comment::find_by_ap_url(conn, previous_url.clone()); - Comment::insert(conn, NewComment { + let comm = Comment::insert(conn, NewComment { content: SafeString::new(¬e.object_props.content_string().unwrap()), spoiler_text: note.object_props.summary_string().unwrap_or(String::from("")), ap_url: note.object_props.id_string().ok(), @@ -136,9 +137,30 @@ impl FromActivity for Comment { post_id: previous_comment .map(|c| c.post_id) .unwrap_or_else(|| Post::find_by_ap_url(conn, previous_url).unwrap().id), - author_id: User::from_url(conn, actor.into()).unwrap().id, + author_id: User::from_url(conn, actor.clone().into()).unwrap().id, sensitive: false // "sensitive" is not a standard property, we need to think about how to support it with the activitypub crate - }) + }); + Comment::notify(conn, note, actor); + comm + } +} + +impl Notify for Comment { + fn notify(conn: &PgConnection, note: Note, _actor: Id) { + match Comment::find_by_ap_url(conn, note.object_props.id_string().unwrap()) { + Some(comment) => { + for author in comment.clone().get_post(conn).get_authors(conn) { + let comment = comment.clone(); + Notification::insert(conn, NewNotification { + title: format!("{} commented your article", comment.get_author(conn).display_name.clone()), + content: Some(comment.get_post(conn).title), + link: comment.ap_url, + user_id: author.id + }); + } + }, + None => println!("Couldn't find comment by AP id, to create a new notification") + }; } } diff --git a/src/models/follows.rs b/src/models/follows.rs index fa5f66fc..66005ed7 100644 --- a/src/models/follows.rs +++ b/src/models/follows.rs @@ -1,9 +1,12 @@ use activitypub::{Actor, activity::{Accept, Follow as FollowAct}}; use diesel::{self, PgConnection, ExpressionMethods, QueryDsl, RunQueryDsl}; -use activity_pub::{broadcast, Id, IntoId, actor::Actor as ApActor, inbox::{FromActivity, WithInbox}, sign::Signer}; -use models::blogs::Blog; -use models::users::User; +use activity_pub::{broadcast, Id, IntoId, actor::Actor as ApActor, inbox::{FromActivity, Notify, WithInbox}, sign::Signer}; +use models::{ + blogs::Blog, + notifications::*, + users::User +}; use schema::follows; #[derive(Queryable, Identifiable, Associations)] @@ -70,3 +73,15 @@ impl FromActivity for Follow { } } } + +impl Notify for Follow { + fn notify(conn: &PgConnection, follow: FollowAct, actor: Id) { + let follower = User::from_url(conn, actor.into()).unwrap(); + Notification::insert(conn, NewNotification { + title: format!("{} started following you", follower.display_name.clone()), + content: None, + link: Some(follower.ap_url), + user_id: User::from_url(conn, follow.follow_props.object_link::().unwrap().into()).unwrap().id + }); + } +} diff --git a/src/models/likes.rs b/src/models/likes.rs index 59bd48bc..6c8bb929 100644 --- a/src/models/likes.rs +++ b/src/models/likes.rs @@ -7,10 +7,11 @@ use activity_pub::{ Id, IntoId, actor::Actor, - inbox::{FromActivity, Deletable}, + inbox::{FromActivity, Deletable, Notify}, object::Object }; use models::{ + notifications::*, posts::Post, users::User }; @@ -97,14 +98,32 @@ impl Like { } impl FromActivity for Like { - fn from_activity(conn: &PgConnection, like: activity::Like, _actor: Id) -> Like { + fn from_activity(conn: &PgConnection, like: activity::Like, actor: Id) -> Like { let liker = User::from_url(conn, like.like_props.actor.as_str().unwrap().to_string()); let post = Post::find_by_ap_url(conn, like.like_props.object.as_str().unwrap().to_string()); - Like::insert(conn, NewLike { + let res = Like::insert(conn, NewLike { post_id: post.unwrap().id, user_id: liker.unwrap().id, ap_url: like.object_props.id_string().unwrap_or(String::from("")) - }) + }); + Like::notify(conn, like, actor); + res + } +} + +impl Notify for Like { + fn notify(conn: &PgConnection, like: activity::Like, actor: Id) { + let liker = User::from_url(conn, actor.into()).unwrap(); + let post = Post::find_by_ap_url(conn, like.like_props.object_link::().unwrap().into()).unwrap(); + for author in post.get_authors(conn) { + let post = post.clone(); + Notification::insert(conn, NewNotification { + title: format!("{} liked your article", liker.display_name.clone()), + content: Some(post.title), + link: Some(post.ap_url), + user_id: author.id + }); + } } } diff --git a/src/models/posts.rs b/src/models/posts.rs index 6e3f4899..b17a2340 100644 --- a/src/models/posts.rs +++ b/src/models/posts.rs @@ -24,7 +24,7 @@ use models::{ use schema::posts; use safe_string::SafeString; -#[derive(Queryable, Identifiable, Serialize)] +#[derive(Queryable, Identifiable, Serialize, Clone)] pub struct Post { pub id: i32, pub blog_id: i32, diff --git a/src/models/reshares.rs b/src/models/reshares.rs index 2e2896d8..8477243d 100644 --- a/src/models/reshares.rs +++ b/src/models/reshares.rs @@ -2,8 +2,8 @@ use activitypub::activity::{Announce, Undo}; use chrono::NaiveDateTime; use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods}; -use activity_pub::{Id, IntoId, actor::Actor, inbox::FromActivity, object::Object}; -use models::{posts::Post, users::User}; +use activity_pub::{Id, IntoId, actor::Actor, inbox::{FromActivity, Notify}, object::Object}; +use models::{notifications::*, posts::Post, users::User}; use schema::reshares; #[derive(Serialize, Deserialize, Queryable, Identifiable)] @@ -100,13 +100,31 @@ impl Reshare { } impl FromActivity for Reshare { - fn from_activity(conn: &PgConnection, announce: Announce, _actor: Id) -> Reshare { + fn from_activity(conn: &PgConnection, announce: Announce, actor: Id) -> Reshare { let user = User::from_url(conn, announce.announce_props.actor.as_str().unwrap().to_string()); let post = Post::find_by_ap_url(conn, announce.announce_props.object.as_str().unwrap().to_string()); - Reshare::insert(conn, NewReshare { + let reshare = Reshare::insert(conn, NewReshare { post_id: post.unwrap().id, user_id: user.unwrap().id, ap_url: announce.object_props.id_string().unwrap_or(String::from("")) - }) + }); + Reshare::notify(conn, announce, actor); + reshare + } +} + +impl Notify for Reshare { + fn notify(conn: &PgConnection, announce: Announce, actor: Id) { + let actor = User::from_url(conn, actor.into()).unwrap(); + let post = Post::find_by_ap_url(conn, announce.announce_props.object_link::().unwrap().into()).unwrap(); + for author in post.get_authors(conn) { + let post = post.clone(); + Notification::insert(conn, NewNotification { + title: format!("{} reshared your article", actor.display_name.clone()), + content: Some(post.title), + link: Some(post.ap_url), + user_id: author.id + }); + } } } diff --git a/src/models/users.rs b/src/models/users.rs index 0b10dfc4..78846ac8 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -37,10 +37,8 @@ use db_conn::DbConn; use models::{ blogs::Blog, blog_authors::BlogAuthor, - comments::Comment, follows::Follow, instance::Instance, - notifications::*, post_authors::PostAuthor, posts::Post }; @@ -458,58 +456,6 @@ impl Inbox for User { println!("Inbox error:\n{}\n{}\n\nActivity was: {}", err.cause(), err.backtrace(), act.to_string()); } - // Notifications - match act["type"].as_str().unwrap() { - "Announce" => { - let actor = User::from_url(conn, act["actor"].as_str().unwrap().to_string()).unwrap(); - let post = Post::find_by_ap_url(conn, act["object"].as_str().unwrap().to_string()).unwrap(); - Notification::insert(conn, NewNotification { - title: format!("{} reshared your article", actor.display_name.clone()), - content: Some(post.title), - link: Some(post.ap_url), - user_id: self.id - }); - }, - "Follow" => { - let follower = User::from_url(conn, act["actor"].as_str().unwrap().to_string()).unwrap(); - Notification::insert(conn, NewNotification { - title: format!("{} started following you", follower.display_name.clone()), - content: None, - link: Some(follower.ap_url), - user_id: self.id - }); - } - "Like" => { - let liker = User::from_url(conn, act["actor"].as_str().unwrap().to_string()).unwrap(); - let post = Post::find_by_ap_url(conn, act["object"].as_str().unwrap().to_string()).unwrap(); - Notification::insert(conn, NewNotification { - title: format!("{} liked your article", liker.display_name.clone()), - content: Some(post.title), - link: Some(post.ap_url), - user_id: self.id - }); - }, - "Create" => { - match act["object"]["type"].as_str().unwrap() { - "Note" => { - match Comment::find_by_ap_url(conn, act["object"]["id"].as_str().unwrap().to_string()) { - Some(comment) => { - Notification::insert(conn, NewNotification { - title: format!("{} commented your article", comment.get_author(conn).display_name.clone()), - content: Some(comment.get_post(conn).title), - link: comment.ap_url, - user_id: self.id - }); - }, - None => println!("Couldn't find comment by AP id, to create a new notification") - }; - } - _ => {} - } - } - _ => {} - } - // TODO: add to stream, or whatever needs to be done } } From c3d0b0f9d294aabd02e0cfd023ed3ea175170554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Miko=C5=82ajczak?= Date: Sun, 17 Jun 2018 21:45:26 +0200 Subject: [PATCH 3/4] i18n: Add Polish translation --- po/pl.po | 254 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 po/pl.po diff --git a/po/pl.po b/po/pl.po new file mode 100644 index 00000000..9340090a --- /dev/null +++ b/po/pl.po @@ -0,0 +1,254 @@ +msgid "" +msgstr "" +"Project-Id-Version: plume\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-06-15 16:33-0700\n" +"PO-Revision-Date: 2018-06-17 20:57+0200\n" +"Last-Translator: Marcin Mikołajczak \n" +"Language-Team: none\n" +"Language: pl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " "|| n%100>=20) ? 1 : 2);\n" + +msgid "Latest articles" +msgstr "Najnowsze artykuły" + +msgid "No posts to see here yet." +msgstr "Brak wpisów do wyświetlenia." + +msgid "New article" +msgstr "Nowy artykuł" + +msgid "New blog" +msgstr "Nowy blog" + +msgid "Create a blog" +msgstr "Utwórz blog" + +msgid "Title" +msgstr "Tytuł" + +msgid "Create blog" +msgstr "Utwórz blog" + +msgid "Comment \"{{ post }}\"" +msgstr "Komentarz „{{ post }}”" + +msgid "Content" +msgstr "Zawartość" + +msgid "Submit comment" +msgstr "Wyślij komentarz" + +msgid "Something broke on our side." +msgstr "Coś poszło nie tak." + +msgid "Sorry about that. If you think this is a bug, please report it." +msgstr "Przepraszamy. Jeżeli uważasz że wystąpił błąd, prosimy o zgłoszenie go." + +msgid "Configuration" +msgstr "Konfiguracja" + +msgid "Configure your instance" +msgstr "Skonfiguruj swoją instancję" + +msgid "Name" +msgstr "Nazwa" + +msgid "Let's go!" +msgstr "Przejdźmy dalej!" + +msgid "Welcome on {{ instance_name }}" +msgstr "Witamy na {{ instance_name }}" + +msgid "Notifications" +msgstr "Powiadomienia" + +msgid "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" +msgstr "Napisano przez {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" + +msgid "This article is under the {{ license }} license." +msgstr "Ten artykuł został opublikowany na licencji {{ license }}." + +msgid "One like" +msgid_plural "{{ count }} likes" +msgstr[0] "Jedno polubienie" +msgstr[1] "{{ count }} polubienia" +msgstr[2] "{{ count }} polubień" + +msgid "I don't like this anymore" +msgstr "Już tego nie lubię" + +msgid "Add yours" +msgstr "Dodaj swoje" + +msgid "One reshare" +msgid_plural "{{ count }} reshares" +msgstr[0] "Jedno udostępnienie" +msgstr[1] "{{ count }} udostępnienia" +msgstr[2] "{{ count }} udostępnień" + +msgid "I don't want to reshare this anymore" +msgstr "Cofnij udostępnienie" + +msgid "Reshare" +msgstr "Udostępnij" + +msgid "Comments" +msgstr "Komentarze" + +msgid "Respond" +msgstr "Odpowiedz" + +msgid "Comment" +msgstr "Skomentuj" + +msgid "New post" +msgstr "Nowy wpis" + +msgid "Create a post" +msgstr "Utwórz wpis" + +msgid "Publish" +msgstr "Opublikuj" + +msgid "Logowanie" +msgstr "Zaloguj się" + +msgid "Username or email" +msgstr "Nazwa użytkownika lub adres e-mail" + +msgid "Password" +msgstr "Hasło" + +msgid "Dashboard" +msgstr "Panel" + +msgid "Your Dashboard" +msgstr "Twój panel" + +msgid "Your Blogs" +msgstr "Twoje blogi" + +msgid "You don't have any blog yet. Create your own, or ask to join one." +msgstr "Nie posiadasz żadnego bloga. Utwórz własny, lub poproś o dołączanie do istniejącego." + +msgid "Start a new blog" +msgstr "Utwórz nowy blog" + +msgid "Admin" +msgstr "Administrator" + +msgid "It is you" +msgstr "To Ty" + +msgid "Edit your profile" +msgstr "Edytuj swój profil" + +msgid "Open on {{ instance_url }}" +msgstr "Otwórz na {{ instance_url }}" + +msgid "Follow" +msgstr "Obserwuj" + +msgid "Unfollow" +msgstr "Przestań obserwować" + +msgid "Recently reshared" +msgstr "Ostatnio udostępniono" + +msgid "One follower" +msgid_plural "{{ count }} followers" +msgstr[0] "Jeden obserwujący" +msgstr[1] "{{ count }} obserwujących" +msgstr[2] "{{ count }} obserwujących" + +msgid "Edit your account" +msgstr "Edytuj swoje konto" + +msgid "Your Profile" +msgstr "Twój profil" + +msgid "Display Name" +msgstr "Nazwa wyświetlana" + +msgid "Email" +msgstr "Adres e-mail" + +msgid "Summary" +msgstr "Opis" + +msgid "Update account" +msgstr "Aktualizuj konto" + +msgid "{{ name }}'s followers" +msgstr "Osoby śledzące {{ name }}" + +msgid "Followers" +msgstr "Śledzący" + +msgid "New Account" +msgstr "Nowe konto" + +msgid "Create an account" +msgstr "Utwórz nowe konto" + +msgid "Username" +msgstr "Nazwa użytkownika" + +msgid "Password confirmation" +msgstr "Potwierdzenie hasła" + +msgid "Create account" +msgstr "Utwórz konto" + +msgid "Plume" +msgstr "Plume" + +msgid "Menu" +msgstr "Menu" + +msgid "My account" +msgstr "Moje konto" + +msgid "Log Out" +msgstr "Wyloguj się" + +msgid "Log In" +msgstr "Zaloguj się" + +msgid "Register" +msgstr "Zarejestruj się" + +msgid "You need to be logged in order to create a new blog" +msgstr "Musisz się zalogować, aby utworzyć nowy blog" + +msgid "You need to be logged in order to post a comment" +msgstr "Musisz się zalogować, aby umieścić komentarz" + +msgid "You need to be logged in order to like a post" +msgstr "Musisz się zalogować, aby polubić wpis" + +msgid "You need to be logged in order to see your notifications" +msgstr "Musisz się zalogować, aby zobaczyć swoje powiadomienia" + +msgid "You need to be logged in order to write a new post" +msgstr "Musisz się zalogować, aby utworzyć wpis" + +msgid "You need to be logged in order to reshare a post" +msgstr "Musisz się zalogować, aby udostępnić wpis" + +msgid "Invalid username or password" +msgstr "Nieprawidłowa nazwa użytkownika lub hasło" + +msgid "You need to be logged in order to access your dashboard" +msgstr "Musisz się zalogować, aby uzyskać dostęp do panelu" + +msgid "You need to be logged in order to follow someone" +msgstr "Musisz się zalogować, aby zacząć obserwować innych" + +msgid "You need to be logged in order to edit your profile" +msgstr "Musisz się zalogować , aby móc edytować swój profil" + From 8b14d5d57391bad59e1cea56b0fea214fabd5672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Miko=C5=82ajczak?= Date: Sun, 17 Jun 2018 21:47:33 +0200 Subject: [PATCH 4/4] Update LINGUAS --- po/LINGUAS | 1 + 1 file changed, 1 insertion(+) diff --git a/po/LINGUAS b/po/LINGUAS index 7e6d9e40..4fec581d 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -1,2 +1,3 @@ en fr +pl