diff options
author | Lyra <teromene@teromene.fr> | 2019-12-19 22:59:13 +0100 |
---|---|---|
committer | Felix Ableitner <me@nutomic.com> | 2019-12-27 17:25:20 +0100 |
commit | 34def84d4307d1f4d822091a35d94ab090c558af (patch) | |
tree | 08eea0dcb5b020f9b4d80c16615853a9c8985cb5 /server/src/apub/mod.rs | |
parent | 104ac9b9501188d334f7106316d3c365a0dc8836 (diff) |
Add correct ActivityPub types conversion for Community and Post.
Diffstat (limited to 'server/src/apub/mod.rs')
-rw-r--r-- | server/src/apub/mod.rs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs new file mode 100644 index 00000000..9b861f45 --- /dev/null +++ b/server/src/apub/mod.rs @@ -0,0 +1,100 @@ +pub mod community; +pub mod post; +pub mod user; +use crate::Settings; + +use std::fmt::Display; + +#[cfg(test)] +mod tests { + use crate::db::community::Community; + use crate::db::post::Post; + use crate::db::user::User_; + use crate::db::{ListingType, SortType}; + use crate::{naive_now, Settings}; + + #[test] + fn test_person() { + let user = User_ { + id: 52, + name: "thom".into(), + fedi_name: "rrf".into(), + preferred_username: None, + password_encrypted: "here".into(), + email: None, + icon: None, + published: naive_now(), + admin: false, + banned: false, + updated: None, + show_nsfw: false, + theme: "darkly".into(), + default_sort_type: SortType::Hot as i16, + default_listing_type: ListingType::Subscribed as i16, + lang: "browser".into(), + }; + + let person = user.as_person(); + assert_eq!( + format!("https://{}/federation/u/thom", Settings::get().hostname), + person.object_props.id_string().unwrap() + ); + } + + #[test] + fn test_community() { + let community = Community { + id: 42, + name: "Test".into(), + title: "Test Title".into(), + description: Some("Test community".into()), + category_id: 32, + creator_id: 52, + removed: false, + published: naive_now(), + updated: Some(naive_now()), + deleted: false, + nsfw: false, + }; + + let group = community.as_group(); + assert_eq!( + format!("https://{}/federation/c/Test", Settings::get().hostname), + group.object_props.id_string().unwrap() + ); + } + + #[test] + fn test_post() { + let post = Post { + id: 62, + name: "A test post".into(), + url: None, + body: None, + creator_id: 52, + community_id: 42, + published: naive_now(), + removed: false, + locked: false, + stickied: false, + nsfw: false, + deleted: false, + updated: None, + }; + + let page = post.as_page(); + assert_eq!( + format!("https://{}/federation/post/62", Settings::get().hostname), + page.object_props.id_string().unwrap() + ); + } +} + +pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String { + format!( + "https://{}/federation/{}/{}", + Settings::get().hostname, + point, + value + ) +} |