├── .github ├── FUNDING.yml └── workflows │ ├── build.yml │ ├── example.yml │ └── release.yml ├── .gitignore ├── .tool-versions ├── Cargo.lock ├── Cargo.toml ├── LICENSE.txt ├── README.md ├── examples ├── detector.rs ├── firefish_authorization.rs ├── firefish_credentials.rs ├── firefish_custom_emojis.rs ├── firefish_favourite.rs ├── firefish_home.rs ├── firefish_instance.rs ├── firefish_media.rs ├── firefish_notifications.rs ├── firefish_post_with_media.rs ├── firefish_search.rs ├── firefish_streaming.rs ├── friendica_authorization.rs ├── friendica_credentials.rs ├── friendica_favourite.rs ├── friendica_follow_requests.rs ├── friendica_home.rs ├── friendica_instance.rs ├── friendica_marker.rs ├── friendica_media.rs ├── friendica_post_with_media.rs ├── friendica_post_with_schedule.rs ├── friendica_reblog.rs ├── friendica_relationship.rs ├── gotosocial_authorization.rs ├── gotosocial_credentials.rs ├── gotosocial_home.rs ├── gotosocial_instance.rs ├── gotosocial_post.rs ├── gotosocial_streaming.rs ├── mastodon_authorization.rs ├── mastodon_credentials.rs ├── mastodon_instance.rs ├── mastodon_marker.rs ├── mastodon_media.rs ├── mastodon_post_with_media.rs ├── mastodon_post_with_schedule.rs ├── mastodon_relationship.rs ├── mastodon_search.rs ├── mastodon_streaming.rs ├── mastodon_unauthorized_local.rs ├── mastodon_update_credentials.rs ├── pixelfed_authorization.rs ├── pixelfed_credential.rs ├── pixelfed_instance.rs ├── pixelfed_notifications.rs ├── pixelfed_streaming.rs ├── pixelfed_timeline.rs ├── pleroma_authorization.rs ├── pleroma_conversations.rs ├── pleroma_credentials.rs ├── pleroma_delete_status.rs ├── pleroma_instance.rs ├── pleroma_marker.rs ├── pleroma_notifications.rs ├── pleroma_post_with_media.rs ├── pleroma_post_with_schedule.rs ├── pleroma_relationship.rs └── pleroma_streaming.rs ├── renovate.json ├── sample.jpg ├── sample2.jpg └── src ├── default.rs ├── detector.rs ├── entities ├── account.rs ├── activity.rs ├── announcement.rs ├── application.rs ├── async_attachment.rs ├── attachment.rs ├── card.rs ├── context.rs ├── conversation.rs ├── emoji.rs ├── featured_tag.rs ├── field.rs ├── filter.rs ├── follow_request.rs ├── history.rs ├── identity_proof.rs ├── instance.rs ├── list.rs ├── marker.rs ├── mention.rs ├── mod.rs ├── notification.rs ├── poll.rs ├── poll_option.rs ├── preferences.rs ├── push_subscription.rs ├── reaction.rs ├── relationship.rs ├── report.rs ├── results.rs ├── role.rs ├── scheduled_status.rs ├── source.rs ├── stats.rs ├── status.rs ├── status_params.rs ├── status_source.rs ├── tag.rs ├── token.rs └── urls.rs ├── error.rs ├── firefish ├── api_client.rs ├── entities │ ├── account.rs │ ├── announcement.rs │ ├── app.rs │ ├── blocking.rs │ ├── created_note.rs │ ├── emoji.rs │ ├── favorite.rs │ ├── field.rs │ ├── file.rs │ ├── follow.rs │ ├── follow_request.rs │ ├── hashtag.rs │ ├── instance.rs │ ├── list.rs │ ├── meta.rs │ ├── mod.rs │ ├── mute.rs │ ├── note.rs │ ├── notification.rs │ ├── poll.rs │ ├── preferences.rs │ ├── reaction.rs │ ├── relation.rs │ ├── session.rs │ ├── stats.rs │ ├── user.rs │ └── user_detail.rs ├── firefish.rs ├── mod.rs ├── oauth.rs └── web_socket.rs ├── friendica ├── api_client.rs ├── entities │ ├── account.rs │ ├── activity.rs │ ├── application.rs │ ├── attachment.rs │ ├── card.rs │ ├── context.rs │ ├── conversation.rs │ ├── emoji.rs │ ├── featured_tag.rs │ ├── field.rs │ ├── filter.rs │ ├── follow_request.rs │ ├── history.rs │ ├── identity_proof.rs │ ├── instance.rs │ ├── list.rs │ ├── marker.rs │ ├── mention.rs │ ├── mod.rs │ ├── notification.rs │ ├── poll.rs │ ├── poll_option.rs │ ├── preferences.rs │ ├── push_subscription.rs │ ├── relationship.rs │ ├── report.rs │ ├── results.rs │ ├── scheduled_status.rs │ ├── source.rs │ ├── stats.rs │ ├── status.rs │ ├── status_params.rs │ ├── tag.rs │ ├── token.rs │ └── urls.rs ├── friendica.rs ├── mod.rs ├── oauth.rs └── web_socket.rs ├── gotosocial ├── api_client.rs ├── entities │ ├── account.rs │ ├── application.rs │ ├── attachment.rs │ ├── card.rs │ ├── context.rs │ ├── emoji.rs │ ├── field.rs │ ├── filter.rs │ ├── instance.rs │ ├── list.rs │ ├── marker.rs │ ├── mention.rs │ ├── mod.rs │ ├── notification.rs │ ├── poll.rs │ ├── poll_option.rs │ ├── preferences.rs │ ├── relationship.rs │ ├── report.rs │ ├── results.rs │ ├── role.rs │ ├── scheduled_status.rs │ ├── source.rs │ ├── stats.rs │ ├── status.rs │ ├── status_params.rs │ ├── status_source.rs │ ├── tag.rs │ ├── token.rs │ └── urls.rs ├── gotosocial.rs ├── mod.rs ├── oauth.rs └── web_socket.rs ├── lib.rs ├── mastodon ├── api_client.rs ├── entities │ ├── account.rs │ ├── activity.rs │ ├── announcement.rs │ ├── application.rs │ ├── attachment.rs │ ├── card.rs │ ├── context.rs │ ├── conversation.rs │ ├── emoji.rs │ ├── featured_tag.rs │ ├── field.rs │ ├── filter.rs │ ├── history.rs │ ├── identity_proof.rs │ ├── instance.rs │ ├── list.rs │ ├── marker.rs │ ├── mention.rs │ ├── mod.rs │ ├── notification.rs │ ├── poll.rs │ ├── poll_option.rs │ ├── preferences.rs │ ├── push_subscription.rs │ ├── relationship.rs │ ├── report.rs │ ├── results.rs │ ├── role.rs │ ├── scheduled_status.rs │ ├── source.rs │ ├── stats.rs │ ├── status.rs │ ├── status_params.rs │ ├── status_source.rs │ ├── tag.rs │ ├── token.rs │ └── urls.rs ├── mastodon.rs ├── mod.rs ├── oauth.rs └── web_socket.rs ├── megalodon.rs ├── oauth.rs ├── pixelfed ├── api_client.rs ├── entities │ ├── account.rs │ ├── announcement.rs │ ├── application.rs │ ├── attachment.rs │ ├── context.rs │ ├── conversation.rs │ ├── emoji.rs │ ├── field.rs │ ├── filter.rs │ ├── history.rs │ ├── instance.rs │ ├── marker.rs │ ├── mention.rs │ ├── mod.rs │ ├── notification.rs │ ├── poll.rs │ ├── poll_option.rs │ ├── preferences.rs │ ├── relationship.rs │ ├── report.rs │ ├── results.rs │ ├── scheduled_status.rs │ ├── source.rs │ ├── stats.rs │ ├── status.rs │ ├── status_params.rs │ ├── tag.rs │ └── token.rs ├── mod.rs ├── oauth.rs ├── pixelfed.rs └── web_socket.rs ├── pleroma ├── api_client.rs ├── entities │ ├── account.rs │ ├── activity.rs │ ├── announcement.rs │ ├── application.rs │ ├── attachment.rs │ ├── card.rs │ ├── context.rs │ ├── conversation.rs │ ├── emoji.rs │ ├── featured_tag.rs │ ├── field.rs │ ├── filter.rs │ ├── history.rs │ ├── identity_proof.rs │ ├── instance.rs │ ├── list.rs │ ├── marker.rs │ ├── mention.rs │ ├── mod.rs │ ├── notification.rs │ ├── poll.rs │ ├── poll_option.rs │ ├── preferences.rs │ ├── push_subscription.rs │ ├── reaction.rs │ ├── relationship.rs │ ├── report.rs │ ├── results.rs │ ├── scheduled_status.rs │ ├── source.rs │ ├── stats.rs │ ├── status.rs │ ├── status_params.rs │ ├── status_source.rs │ ├── tag.rs │ ├── token.rs │ └── urls.rs ├── mod.rs ├── oauth.rs ├── pleroma.rs └── web_socket.rs ├── response.rs └── streaming.rs /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: h3poteto 2 | patreon: h3poteto 3 | liberapay: h3poteto 4 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: dtolnay/rust-toolchain@stable 20 | with: 21 | toolchain: stable 22 | - name: Build 23 | run: cargo build --verbose 24 | - name: Run tests 25 | run: cargo test --verbose 26 | -------------------------------------------------------------------------------- /.github/workflows/example.yml: -------------------------------------------------------------------------------- 1 | name: Examle 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | MASTODON_URL: https://mastodon.social 12 | 13 | jobs: 14 | example: 15 | 16 | runs-on: ubuntu-latest 17 | strategy: 18 | matrix: 19 | features: [native-tls, rustls-tls] 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: dtolnay/rust-toolchain@stable 23 | with: 24 | toolchain: stable 25 | - name: Run example 26 | run: cargo run --example mastodon_instance --features ${{ matrix.features }} 27 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | release: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 13 | - uses: dtolnay/rust-toolchain@stable 14 | with: 15 | toolchain: stable 16 | - name: Publish 17 | env: 18 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} 19 | run: | 20 | cargo publish 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | rust 1.86.0 2 | -------------------------------------------------------------------------------- /examples/detector.rs: -------------------------------------------------------------------------------- 1 | use megalodon::detector; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | let sns = detector(url.as_str()).await; 13 | println!("{:#?}", sns); 14 | } 15 | -------------------------------------------------------------------------------- /examples/firefish_credentials.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FIREFISH_URL") else { 9 | println!("Specify FIREFISH_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("FIREFISH_ACCESS_TOKEN") else { 13 | println!("Specify FIREFISH_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | match verify_credentials(url.as_str(), token).await { 17 | Ok(response) => { 18 | println!("{:#?}", response); 19 | } 20 | Err(err) => { 21 | println!("{:#?}", err); 22 | } 23 | } 24 | } 25 | async fn verify_credentials( 26 | url: &str, 27 | access_token: String, 28 | ) -> Result { 29 | let client = generator(SNS::Firefish, url.to_string(), Some(access_token), None)?; 30 | let res = client.verify_account_credentials().await?; 31 | Ok(res.json()) 32 | } 33 | -------------------------------------------------------------------------------- /examples/firefish_custom_emojis.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FIREFISH_URL") else { 9 | println!("Specify FIREFISH_URL!!"); 10 | return; 11 | }; 12 | match emojis(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn emojis(url: &str) -> Result, error::Error> { 23 | let client = generator(SNS::Firefish, url.to_string(), None, None)?; 24 | let res = client.get_instance_custom_emojis().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/firefish_favourite.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FIREFISH_URL") else { 10 | println!("Specify FIREFISH_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FIREFISH_ACCESS_TOKEN") else { 14 | println!("Specify FIREFISH_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | let Ok(status_id) = env::var("STATUS_ID") else { 18 | println!("Specify STATUS_ID!!"); 19 | return; 20 | }; 21 | 22 | let res = favourite_status(url.as_str(), token, status_id).await; 23 | match res { 24 | Ok(res) => { 25 | println!("{:#?}", res); 26 | } 27 | Err(err) => { 28 | println!("{:#?}", err); 29 | } 30 | } 31 | } 32 | 33 | async fn favourite_status( 34 | url: &str, 35 | access_token: String, 36 | status_id: String, 37 | ) -> Result { 38 | let client = generator( 39 | megalodon::SNS::Firefish, 40 | url.to_string(), 41 | Some(access_token), 42 | None, 43 | )?; 44 | let res = client.favourite_status(status_id).await?; 45 | 46 | Ok(res.json()) 47 | } 48 | -------------------------------------------------------------------------------- /examples/firefish_home.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FIREFISH_URL") else { 10 | println!("Specify FIREFISH_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FIREFISH_ACCESS_TOKEN") else { 14 | println!("Specify FIREFISH_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = home_timeline(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn home_timeline( 30 | url: &str, 31 | access_token: String, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Firefish, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_home_timeline(None).await?; 40 | 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/firefish_instance.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FIREFISH_URL") else { 9 | println!("Specify FIREFISH_URL!!"); 10 | return; 11 | }; 12 | match instance(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn instance(url: &str) -> Result { 23 | let client = generator(SNS::Firefish, url.to_string(), None, None)?; 24 | let res = client.get_instance().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/firefish_media.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FIREFISH_URL") else { 9 | println!("Specify FIREFISH_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("FIREFISH_ACCESS_TOKEN") else { 13 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let file_path = "./sample.jpg".to_string(); 18 | let res = upload_media(url.as_str(), token.to_owned(), file_path).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn upload_media( 30 | url: &str, 31 | access_token: String, 32 | file_path: String, 33 | ) -> Result { 34 | let client = generator( 35 | megalodon::SNS::Firefish, 36 | url.to_string(), 37 | Some(access_token), 38 | None, 39 | )?; 40 | let res = client.upload_media(file_path, None).await?; 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/firefish_notifications.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FIREFISH_URL") else { 10 | println!("Specify FIREFISH_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FIREFISH_ACCESS_TOKEN") else { 14 | println!("Specify FIREFISH_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = get_notifications(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn get_notifications( 30 | url: &str, 31 | access_token: String, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Firefish, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_notifications(None).await?; 40 | Ok(res.json()) 41 | } 42 | -------------------------------------------------------------------------------- /examples/firefish_search.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FIREFISH_URL") else { 10 | println!("Specify FIREFISH_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FIREFISH_ACCESS_TOKEN") else { 14 | println!("Specify FIREFISH_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = search(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn search(url: &str, access_token: String) -> Result { 30 | let client = generator( 31 | megalodon::SNS::Firefish, 32 | url.to_string(), 33 | Some(access_token), 34 | None, 35 | )?; 36 | let res = client.search(String::from("h3poteto"), None).await?; 37 | 38 | Ok(res.json()) 39 | } 40 | -------------------------------------------------------------------------------- /examples/friendica_credentials.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FRIENDICA_URL") else { 9 | println!("Specify FRIENDICA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 13 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | match verify_credentials(url.as_str(), token).await { 17 | Ok(response) => { 18 | println!("{:#?}", response); 19 | } 20 | Err(err) => { 21 | println!("{:#?}", err); 22 | } 23 | } 24 | } 25 | async fn verify_credentials( 26 | url: &str, 27 | access_token: String, 28 | ) -> Result { 29 | let client = generator(SNS::Friendica, url.to_string(), Some(access_token), None)?; 30 | let res = client.verify_account_credentials().await?; 31 | Ok(res.json()) 32 | } 33 | -------------------------------------------------------------------------------- /examples/friendica_favourite.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FRIENDICA_URL") else { 10 | println!("Specify FRIENDICA_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 14 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | let Ok(status_id) = env::var("STATUS_ID") else { 18 | println!("Specify STATUS_ID!!"); 19 | return; 20 | }; 21 | 22 | let res = favourite_status(url.as_str(), token, status_id).await; 23 | match res { 24 | Ok(res) => { 25 | println!("{:#?}", res); 26 | } 27 | Err(err) => { 28 | println!("{:#?}", err); 29 | } 30 | } 31 | } 32 | 33 | async fn favourite_status( 34 | url: &str, 35 | access_token: String, 36 | status_id: String, 37 | ) -> Result { 38 | let client = generator( 39 | megalodon::SNS::Friendica, 40 | url.to_string(), 41 | Some(access_token), 42 | None, 43 | )?; 44 | let res = client.favourite_status(status_id).await?; 45 | 46 | Ok(res.json()) 47 | } 48 | -------------------------------------------------------------------------------- /examples/friendica_follow_requests.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{error, generator, megalodon::FollowRequestOutput}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FRIENDICA_URL") else { 10 | println!("Specify FRIENDICA_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 14 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = follow_requests(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => res 21 | .into_iter() 22 | .map(|f| match f { 23 | FollowRequestOutput::FollowRequest(req) => println!("FollowRequest: {:#?}", req), 24 | FollowRequestOutput::Account(acct) => println!("Account: {:#?}", acct), 25 | }) 26 | .collect(), 27 | Err(err) => { 28 | println!("{:#?}", err); 29 | } 30 | } 31 | } 32 | 33 | async fn follow_requests( 34 | url: &str, 35 | access_token: String, 36 | ) -> Result, error::Error> { 37 | let client = generator( 38 | megalodon::SNS::Friendica, 39 | url.to_string(), 40 | Some(access_token), 41 | None, 42 | )?; 43 | let res = client.get_follow_requests(None).await?; 44 | 45 | Ok(res.json()) 46 | } 47 | -------------------------------------------------------------------------------- /examples/friendica_home.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FRIENDICA_URL") else { 10 | println!("Specify FRIENDICA_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 14 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = home_timeline(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn home_timeline( 30 | url: &str, 31 | access_token: String, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Friendica, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_home_timeline(None).await?; 40 | 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/friendica_instance.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FRIENDICA_URL") else { 9 | println!("Specify FRIENDICA_URL!!"); 10 | return; 11 | }; 12 | match instance(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn instance(url: &str) -> Result { 23 | let client = generator(SNS::Friendica, url.to_string(), None, None)?; 24 | let res = client.get_instance().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/friendica_media.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FRIENDICA_URL") else { 9 | println!("Specify FRIENDICA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 13 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let file_path = "./sample.jpg".to_string(); 18 | let res = upload_media(url.as_str(), token.to_owned(), file_path).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn upload_media( 30 | url: &str, 31 | access_token: String, 32 | file_path: String, 33 | ) -> Result { 34 | let client = generator( 35 | megalodon::SNS::Friendica, 36 | url.to_string(), 37 | Some(access_token), 38 | None, 39 | )?; 40 | let res = client.upload_media(file_path, None).await?; 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/friendica_post_with_schedule.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use chrono::{DateTime, Duration, Utc}; 4 | use megalodon::{error, generator, megalodon::PostStatusInputOptions}; 5 | 6 | #[tokio::main] 7 | async fn main() { 8 | tracing_subscriber::fmt::init(); 9 | 10 | let Ok(url) = env::var("FRIENDICA_URL") else { 11 | println!("Specify FRIENDICA_URL!!"); 12 | return; 13 | }; 14 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 15 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 16 | return; 17 | }; 18 | 19 | let client = generator(megalodon::SNS::Friendica, url, Some(token), None).unwrap(); 20 | 21 | let scheduled_at = Utc::now() + Duration::try_minutes(6).unwrap(); 22 | println!("scheduled at {:#?}", scheduled_at); 23 | 24 | match post_status(&client, "Test", scheduled_at).await { 25 | Ok(res) => { 26 | println!("{:#?}", res); 27 | } 28 | Err(err) => { 29 | println!("{:#?}", err); 30 | } 31 | } 32 | } 33 | 34 | async fn post_status( 35 | client: &Box, 36 | status: &str, 37 | scheduled_at: DateTime, 38 | ) -> Result { 39 | let res = client 40 | .post_status( 41 | status.to_string(), 42 | Some(&PostStatusInputOptions { 43 | scheduled_at: Some(scheduled_at), 44 | ..Default::default() 45 | }), 46 | ) 47 | .await?; 48 | 49 | Ok(res.json()) 50 | } 51 | -------------------------------------------------------------------------------- /examples/friendica_reblog.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("FRIENDICA_URL") else { 10 | println!("Specify FRIENDICA_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 14 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | let Ok(status_id) = env::var("STATUS_ID") else { 18 | println!("Specify STATUS_ID!!"); 19 | return; 20 | }; 21 | 22 | let res = reblog_status(url.as_str(), token, status_id).await; 23 | match res { 24 | Ok(res) => { 25 | println!("{:#?}", res); 26 | } 27 | Err(err) => { 28 | println!("{:#?}", err); 29 | } 30 | } 31 | } 32 | 33 | async fn reblog_status( 34 | url: &str, 35 | access_token: String, 36 | status_id: String, 37 | ) -> Result { 38 | let client = generator( 39 | megalodon::SNS::Friendica, 40 | url.to_string(), 41 | Some(access_token), 42 | None, 43 | )?; 44 | let res = client.reblog_status(status_id).await?; 45 | 46 | Ok(res.json()) 47 | } 48 | -------------------------------------------------------------------------------- /examples/friendica_relationship.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("FRIENDICA_URL") else { 9 | println!("Specify FRIENDICA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("FRIENDICA_ACCESS_TOKEN") else { 13 | println!("Specify FRIENDICA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_relationship(url.as_str(), token, "2245768").await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_relationship( 29 | url: &str, 30 | access_token: String, 31 | id: &str, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Friendica, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_relationships([id.to_string()].to_vec()).await?; 40 | Ok(res.json()) 41 | } 42 | -------------------------------------------------------------------------------- /examples/gotosocial_credentials.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("GOTOSOCIAL_URL") else { 9 | println!("Specify GOTOSOCIAL_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("GOTOSOCIAL_ACCESS_TOKEN") else { 13 | println!("Specify GOTOSOCIAL_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | match verify_credentials(url.as_str(), token).await { 17 | Ok(response) => { 18 | println!("{:#?}", response); 19 | } 20 | Err(err) => { 21 | println!("{:#?}", err); 22 | } 23 | } 24 | } 25 | async fn verify_credentials( 26 | url: &str, 27 | access_token: String, 28 | ) -> Result { 29 | let client = generator(SNS::Gotosocial, url.to_string(), Some(access_token), None)?; 30 | let res = client.verify_account_credentials().await?; 31 | Ok(res.json()) 32 | } 33 | -------------------------------------------------------------------------------- /examples/gotosocial_home.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("GOTOSOCIAL_URL") else { 10 | println!("Specify GOTOSOCIAL_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("GOTOSOCIAL_ACCESS_TOKEN") else { 14 | println!("Specify GOTOSOCIAL_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = home_timeline(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn home_timeline( 30 | url: &str, 31 | access_token: String, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Gotosocial, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_home_timeline(None).await?; 40 | 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/gotosocial_instance.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("GOTOSOCIAL_URL") else { 9 | println!("Specify GOTOSOCIAL_URL!!"); 10 | return; 11 | }; 12 | match instance(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn instance(url: &str) -> Result { 23 | let client = generator(SNS::Gotosocial, url.to_string(), None, None)?; 24 | let res = client.get_instance().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/gotosocial_post.rs: -------------------------------------------------------------------------------- 1 | use megalodon::generator; 2 | use std::{env, io}; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("GOTOSOCIAL_URL") else { 9 | println!("Specify GOTOSOCIAL_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("GOTOSOCIAL_ACCESS_TOKEN") else { 13 | println!("Specify GOTOSOCIAL_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let client = generator(megalodon::SNS::Gotosocial, url, Some(token), None).unwrap(); 18 | 19 | let res = post_status(&client).await; 20 | match res { 21 | Ok(res) => { 22 | println!("{:#?}", res); 23 | } 24 | Err(err) => { 25 | println!("{:#?}", err); 26 | } 27 | } 28 | } 29 | 30 | async fn post_status( 31 | client: &Box, 32 | ) -> Result { 33 | println!("Input text:"); 34 | let mut buffer = String::new(); 35 | io::stdin() 36 | .read_line(&mut buffer) 37 | .expect("failed to read from stdin"); 38 | let text = buffer.trim().to_string(); 39 | let options = megalodon::megalodon::PostStatusInputOptions { 40 | visibility: Some(megalodon::entities::StatusVisibility::Public), 41 | ..Default::default() 42 | }; 43 | let res = client.post_status(text, Some(&options)).await?; 44 | 45 | Ok(res.json()) 46 | } 47 | -------------------------------------------------------------------------------- /examples/mastodon_credentials.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 13 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | match verify_credentials(url.as_str(), token).await { 17 | Ok(response) => { 18 | println!("{:#?}", response); 19 | } 20 | Err(err) => { 21 | println!("{:#?}", err); 22 | } 23 | } 24 | } 25 | async fn verify_credentials( 26 | url: &str, 27 | access_token: String, 28 | ) -> Result { 29 | let client = generator(SNS::Mastodon, url.to_string(), Some(access_token), None)?; 30 | let res = client.verify_account_credentials().await?; 31 | Ok(res.json()) 32 | } 33 | -------------------------------------------------------------------------------- /examples/mastodon_instance.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | match instance(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn instance(url: &str) -> Result { 23 | let client = generator(SNS::Mastodon, url.to_string(), None, None)?; 24 | let res = client.get_instance().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/mastodon_marker.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 13 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_markers(url.as_str(), token).await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_markers(url: &str, access_token: String) -> Result { 29 | let client = generator( 30 | megalodon::SNS::Mastodon, 31 | url.to_string(), 32 | Some(access_token), 33 | None, 34 | )?; 35 | let res = client 36 | .get_markers(vec![String::from("home"), String::from("notifications")]) 37 | .await?; 38 | Ok(res.json()) 39 | } 40 | -------------------------------------------------------------------------------- /examples/mastodon_media.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 13 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let file_path = "./sample.jpg".to_string(); 18 | let res = upload_media(url.as_str(), token.to_owned(), file_path).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn upload_media( 30 | url: &str, 31 | access_token: String, 32 | file_path: String, 33 | ) -> Result { 34 | let client = generator( 35 | megalodon::SNS::Mastodon, 36 | url.to_string(), 37 | Some(access_token), 38 | None, 39 | )?; 40 | let res = client.upload_media(file_path, None).await?; 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/mastodon_post_with_schedule.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use chrono::{DateTime, Duration, Utc}; 4 | use megalodon::{error, generator, megalodon::PostStatusInputOptions}; 5 | 6 | #[tokio::main] 7 | async fn main() { 8 | tracing_subscriber::fmt::init(); 9 | 10 | let Ok(url) = env::var("MASTODON_URL") else { 11 | println!("Specify MASTODON_URL!!"); 12 | return; 13 | }; 14 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 15 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 16 | return; 17 | }; 18 | 19 | let client = generator(megalodon::SNS::Mastodon, url, Some(token), None).unwrap(); 20 | 21 | let scheduled_at = Utc::now() + Duration::try_minutes(6).unwrap(); 22 | println!("scheduled at {:#?}", scheduled_at); 23 | 24 | match post_status(&client, "Test", scheduled_at).await { 25 | Ok(res) => { 26 | println!("{:#?}", res); 27 | } 28 | Err(err) => { 29 | println!("{:#?}", err); 30 | } 31 | } 32 | } 33 | 34 | async fn post_status( 35 | client: &Box, 36 | status: &str, 37 | scheduled_at: DateTime, 38 | ) -> Result { 39 | let res = client 40 | .post_status( 41 | status.to_string(), 42 | Some(&PostStatusInputOptions { 43 | scheduled_at: Some(scheduled_at), 44 | ..Default::default() 45 | }), 46 | ) 47 | .await?; 48 | 49 | Ok(res.json()) 50 | } 51 | -------------------------------------------------------------------------------- /examples/mastodon_relationship.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 13 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_relationship(url.as_str(), token, "109314016387492241").await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_relationship( 29 | url: &str, 30 | access_token: String, 31 | id: &str, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Mastodon, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_relationships([id.to_string()].to_vec()).await?; 40 | Ok(res.json()) 41 | } 42 | -------------------------------------------------------------------------------- /examples/mastodon_search.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{ 4 | entities, error, generator, 5 | megalodon::{SearchInputOptions, SearchType}, 6 | }; 7 | 8 | #[tokio::main] 9 | async fn main() { 10 | tracing_subscriber::fmt::init(); 11 | 12 | let Ok(url) = env::var("MASTODON_URL") else { 13 | println!("Specify MASTODON_URL!!"); 14 | return; 15 | }; 16 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 17 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 18 | return; 19 | }; 20 | 21 | let res = search(url.as_str(), token, "h3poteto").await; 22 | match res { 23 | Ok(res) => { 24 | println!("{:#?}", res); 25 | } 26 | Err(err) => { 27 | println!("{:#?}", err); 28 | } 29 | } 30 | } 31 | 32 | async fn search( 33 | url: &str, 34 | access_token: String, 35 | query: &str, 36 | ) -> Result { 37 | let client = generator( 38 | megalodon::SNS::Mastodon, 39 | url.to_string(), 40 | Some(access_token), 41 | None, 42 | )?; 43 | let options = SearchInputOptions { 44 | r#type: Some(SearchType::Accounts), 45 | limit: None, 46 | max_id: None, 47 | min_id: None, 48 | resolve: Some(true), 49 | offset: None, 50 | following: None, 51 | account_id: None, 52 | exclude_unreviewed: None, 53 | }; 54 | let res = client.search(query.to_string(), Some(&options)).await?; 55 | Ok(res.json()) 56 | } 57 | -------------------------------------------------------------------------------- /examples/mastodon_update_credentials.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("MASTODON_URL") else { 9 | println!("Specify MASTODON_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("MASTODON_ACCESS_TOKEN") else { 13 | println!("Specify MASTODON_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let client = generator(SNS::Mastodon, url, Some(token), None).unwrap(); 18 | 19 | let update_creds = megalodon::megalodon::UpdateCredentialsInputOptions { 20 | fields_attributes: Some(vec![megalodon::megalodon::CredentialsFieldAttribute { 21 | name: "Test".to_string(), 22 | value: "test".to_string(), 23 | }]), 24 | ..Default::default() 25 | }; 26 | 27 | let res = client 28 | .update_credentials(Some(&update_creds)) 29 | .await 30 | .unwrap(); 31 | 32 | println!("{:#?}", res.json()) 33 | } 34 | -------------------------------------------------------------------------------- /examples/pixelfed_credential.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PIXELFED_URL") else { 9 | println!("Specify PIXELFED_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PIXELFED_ACCESS_TOKEN") else { 13 | println!("Specify PIXELFED_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | match verify_credentials(url.as_str(), token).await { 17 | Ok(response) => { 18 | println!("{:#?}", response); 19 | } 20 | Err(err) => { 21 | println!("{:#?}", err); 22 | } 23 | } 24 | } 25 | async fn verify_credentials( 26 | url: &str, 27 | access_token: String, 28 | ) -> Result { 29 | let client = generator(SNS::Pixelfed, url.to_string(), Some(access_token), None)?; 30 | let res = client.verify_account_credentials().await?; 31 | Ok(res.json()) 32 | } 33 | -------------------------------------------------------------------------------- /examples/pixelfed_instance.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PIXELFED_URL") else { 9 | println!("Specify PIXELFED_URL!!"); 10 | return; 11 | }; 12 | match instance(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn instance(url: &str) -> Result { 23 | let client = generator(SNS::Pixelfed, url.to_string(), None, None)?; 24 | let res = client.get_instance().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/pixelfed_notifications.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PIXELFED_URL") else { 9 | println!("Specify PIXELFED_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PIXELFED_ACCESS_TOKEN") else { 13 | println!("Specify PIXELFED_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_notifications(url.as_str(), token).await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_notifications( 29 | url: &str, 30 | access_token: String, 31 | ) -> Result, error::Error> { 32 | let client = generator( 33 | megalodon::SNS::Pixelfed, 34 | url.to_string(), 35 | Some(access_token), 36 | None, 37 | )?; 38 | let res = client.get_notifications(None).await?; 39 | Ok(res.json()) 40 | } 41 | -------------------------------------------------------------------------------- /examples/pixelfed_timeline.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::{entities, error, generator}; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("PIXELFED_URL") else { 10 | println!("Specify PIXELFED_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("PIXELFED_ACCESS_TOKEN") else { 14 | println!("Specify PIXELFED_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | 18 | let res = home_timeline(url.as_str(), token).await; 19 | match res { 20 | Ok(res) => { 21 | println!("{:#?}", res); 22 | } 23 | Err(err) => { 24 | println!("{:#?}", err); 25 | } 26 | } 27 | } 28 | 29 | async fn home_timeline( 30 | url: &str, 31 | access_token: String, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Pixelfed, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_public_timeline(None).await?; 40 | 41 | Ok(res.json()) 42 | } 43 | -------------------------------------------------------------------------------- /examples/pleroma_conversations.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PLEROMA_URL") else { 9 | println!("Specify PLEROMA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PLEROMA_ACCESS_TOKEN") else { 13 | println!("Specify PLEROMA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_conversations(url.as_str(), token).await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_conversations( 29 | url: &str, 30 | access_token: String, 31 | ) -> Result, error::Error> { 32 | let client = generator( 33 | megalodon::SNS::Pleroma, 34 | url.to_string(), 35 | Some(access_token), 36 | None, 37 | )?; 38 | let res = client.get_conversation_timeline(None).await?; 39 | Ok(res.json()) 40 | } 41 | -------------------------------------------------------------------------------- /examples/pleroma_credentials.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PLEROMA_URL") else { 9 | println!("Specify PLEROMA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PLEROMA_ACCESS_TOKEN") else { 13 | println!("Specify PLEROMA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | match verify_credentials(url.as_str(), token).await { 18 | Ok(response) => { 19 | println!("{:#?}", response); 20 | } 21 | Err(err) => { 22 | println!("{:#?}", err); 23 | } 24 | } 25 | } 26 | 27 | async fn verify_credentials( 28 | url: &str, 29 | access_token: String, 30 | ) -> Result { 31 | let client = generator(SNS::Pleroma, url.to_string(), Some(access_token), None)?; 32 | let res = client.verify_account_credentials().await?; 33 | Ok(res.json()) 34 | } 35 | -------------------------------------------------------------------------------- /examples/pleroma_delete_status.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | use megalodon::generator; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | tracing_subscriber::fmt::init(); 8 | 9 | let Ok(url) = env::var("PLEROMA_URL") else { 10 | println!("Specify PLEROMA_URL!!"); 11 | return; 12 | }; 13 | let Ok(token) = env::var("PLEROMA_ACCESS_TOKEN") else { 14 | println!("Specify PLEROMA_ACCESS_TOKEN!!"); 15 | return; 16 | }; 17 | let client = generator(megalodon::SNS::Pleroma, url.to_string(), Some(token), None).unwrap(); 18 | println!("Target status_id: "); 19 | let mut status_id = String::new(); 20 | std::io::stdin().read_line(&mut status_id).ok(); 21 | 22 | match client.delete_status(status_id).await { 23 | Ok(res) => { 24 | println!("{:#?}", res); 25 | } 26 | Err(err) => { 27 | println!("{:#?}", err) 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/pleroma_instance.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator, SNS}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PLEROMA_URL") else { 9 | println!("Specify PLEROMA_URL!!"); 10 | return; 11 | }; 12 | match instance(url.as_str()).await { 13 | Ok(response) => { 14 | println!("{:#?}", response); 15 | } 16 | Err(err) => { 17 | println!("{:#?}", err); 18 | } 19 | } 20 | } 21 | 22 | async fn instance(url: &str) -> Result { 23 | let client = generator(SNS::Pleroma, url.to_string(), None, None)?; 24 | let res = client.get_instance().await?; 25 | Ok(res.json()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/pleroma_marker.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PLEROMA_URL") else { 9 | println!("Specify PLEROMA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PLEROMA_ACCESS_TOKEN") else { 13 | println!("Specify PLEROMA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_markers(url.as_str(), token).await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_markers(url: &str, access_token: String) -> Result { 29 | let client = generator( 30 | megalodon::SNS::Pleroma, 31 | url.to_string(), 32 | Some(access_token), 33 | None, 34 | )?; 35 | let res = client 36 | .get_markers(vec![String::from("notifications")]) 37 | .await?; 38 | Ok(res.json()) 39 | } 40 | -------------------------------------------------------------------------------- /examples/pleroma_notifications.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PLEROMA_URL") else { 9 | println!("Specify PLEROMA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PLEROMA_ACCESS_TOKEN") else { 13 | println!("Specify PLEROMA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_notifications(url.as_str(), token).await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_notifications( 29 | url: &str, 30 | access_token: String, 31 | ) -> Result, error::Error> { 32 | let client = generator( 33 | megalodon::SNS::Pleroma, 34 | url.to_string(), 35 | Some(access_token), 36 | None, 37 | )?; 38 | let res = client.get_notifications(None).await?; 39 | Ok(res.json()) 40 | } 41 | -------------------------------------------------------------------------------- /examples/pleroma_relationship.rs: -------------------------------------------------------------------------------- 1 | use megalodon::{entities, error, generator}; 2 | use std::env; 3 | 4 | #[tokio::main] 5 | async fn main() { 6 | tracing_subscriber::fmt::init(); 7 | 8 | let Ok(url) = env::var("PLEROMA_URL") else { 9 | println!("Specify PLEROMA_URL!!"); 10 | return; 11 | }; 12 | let Ok(token) = env::var("PLEROMA_ACCESS_TOKEN") else { 13 | println!("Specify PLEROMA_ACCESS_TOKEN!!"); 14 | return; 15 | }; 16 | 17 | let res = get_relationship(url.as_str(), token, "4").await; 18 | match res { 19 | Ok(res) => { 20 | println!("{:#?}", res); 21 | } 22 | Err(err) => { 23 | println!("{:#?}", err); 24 | } 25 | } 26 | } 27 | 28 | async fn get_relationship( 29 | url: &str, 30 | access_token: String, 31 | id: &str, 32 | ) -> Result, error::Error> { 33 | let client = generator( 34 | megalodon::SNS::Pleroma, 35 | url.to_string(), 36 | Some(access_token), 37 | None, 38 | )?; 39 | let res = client.get_relationships([id.to_string()].to_vec()).await?; 40 | Ok(res.json()) 41 | } 42 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h3poteto/megalodon-rs/19cf01f5f64f5b6c58f47b0277e8f1d0f16ce2e4/sample.jpg -------------------------------------------------------------------------------- /sample2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h3poteto/megalodon-rs/19cf01f5f64f5b6c58f47b0277e8f1d0f16ce2e4/sample2.jpg -------------------------------------------------------------------------------- /src/default.rs: -------------------------------------------------------------------------------- 1 | //! Default values 2 | 3 | /// A static value for no redirect url. 4 | /// Please use this value when you get an access token. 5 | pub static NO_REDIRECT: &str = "urn:ietf:wg:oauth:2.0:oob"; 6 | /// Default User-Agent value. 7 | pub static DEFAULT_UA: &str = "megalodon"; 8 | /// Default scopes value for register app. 9 | pub static DEFAULT_SCOPES: &'static [&str] = &["read", "write", "follow"]; 10 | -------------------------------------------------------------------------------- /src/entities/account.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, Field, Role, Source}; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 6 | pub struct Account { 7 | pub id: String, 8 | pub username: String, 9 | pub acct: String, 10 | pub display_name: String, 11 | pub locked: bool, 12 | pub discoverable: Option, 13 | pub group: Option, 14 | pub noindex: Option, 15 | pub moved: Option>, 16 | pub suspended: Option, 17 | pub limited: Option, 18 | pub created_at: DateTime, 19 | pub followers_count: i32, 20 | pub following_count: u32, 21 | pub statuses_count: u32, 22 | pub note: String, 23 | pub url: String, 24 | pub avatar: String, 25 | pub avatar_static: String, 26 | pub header: String, 27 | pub header_static: String, 28 | pub emojis: Vec, 29 | pub fields: Vec, 30 | pub bot: bool, 31 | pub source: Option, 32 | pub role: Option, 33 | pub mute_expires_at: Option>, 34 | } 35 | -------------------------------------------------------------------------------- /src/entities/activity.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct Activity { 5 | pub week: String, 6 | pub statuses: String, 7 | pub logins: String, 8 | pub registrations: String, 9 | } 10 | -------------------------------------------------------------------------------- /src/entities/announcement.rs: -------------------------------------------------------------------------------- 1 | use super::{status, Emoji}; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct Announcement { 7 | pub id: String, 8 | pub content: String, 9 | pub starts_at: Option>, 10 | pub ends_at: Option>, 11 | pub published: bool, 12 | pub all_day: bool, 13 | pub published_at: DateTime, 14 | // Firefish provides updated_at as optional. 15 | pub updated_at: Option>, 16 | pub read: Option, 17 | pub mentions: Vec, 18 | pub statuses: Vec, 19 | pub tags: Vec, 20 | pub emojis: Vec, 21 | pub reactions: Vec, 22 | } 23 | 24 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 25 | pub struct Account { 26 | pub id: String, 27 | pub username: String, 28 | pub url: String, 29 | pub acct: String, 30 | } 31 | 32 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 33 | pub struct Status { 34 | pub id: String, 35 | pub url: String, 36 | } 37 | 38 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 39 | pub struct Reaction { 40 | pub name: String, 41 | pub count: i64, 42 | pub me: Option, 43 | pub url: Option, 44 | pub static_url: Option, 45 | } 46 | -------------------------------------------------------------------------------- /src/entities/application.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct Application { 5 | pub name: String, 6 | pub website: Option, 7 | pub vapid_key: Option, 8 | } 9 | -------------------------------------------------------------------------------- /src/entities/async_attachment.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::{ 4 | attachment::{AttachmentMeta, AttachmentType}, 5 | Attachment, 6 | }; 7 | 8 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 9 | pub struct AsyncAttachment { 10 | pub id: String, 11 | pub r#type: AttachmentType, 12 | pub url: Option, 13 | pub remote_url: Option, 14 | pub preview_url: Option, 15 | pub text_url: Option, 16 | pub meta: Option, 17 | pub description: Option, 18 | pub blurhash: Option, 19 | } 20 | 21 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 22 | pub enum UploadMedia { 23 | Attachment(Attachment), 24 | AsyncAttachment(AsyncAttachment), 25 | } 26 | -------------------------------------------------------------------------------- /src/entities/card.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct Card { 5 | pub url: String, 6 | pub title: String, 7 | pub description: String, 8 | pub r#type: CardType, 9 | pub image: Option, 10 | pub author_name: Option, 11 | pub author_url: Option, 12 | pub provider_name: String, 13 | pub provider_url: String, 14 | pub html: Option, 15 | pub width: Option, 16 | pub height: Option, 17 | pub embed_url: Option, 18 | pub blurhash: Option, 19 | } 20 | 21 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 22 | #[serde(rename_all = "lowercase")] 23 | pub enum CardType { 24 | Link, 25 | Photo, 26 | Video, 27 | Rich, 28 | } 29 | -------------------------------------------------------------------------------- /src/entities/context.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::Status; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct Context { 7 | pub ancestors: Vec, 8 | pub descendants: Vec, 9 | } 10 | -------------------------------------------------------------------------------- /src/entities/conversation.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::{Account, Status}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct Conversation { 7 | pub id: String, 8 | pub accounts: Vec, 9 | pub last_status: Option, 10 | pub unread: bool, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 4 | pub struct Emoji { 5 | pub shortcode: String, 6 | pub static_url: String, 7 | pub url: String, 8 | pub visible_in_picker: bool, 9 | pub category: Option, 10 | } 11 | -------------------------------------------------------------------------------- /src/entities/featured_tag.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use chrono::{DateTime, Utc}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct FeaturedTag { 7 | pub id: String, 8 | pub name: String, 9 | pub statuses_count: u32, 10 | pub last_status_at: DateTime, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/field.rs: -------------------------------------------------------------------------------- 1 | use chrono::{DateTime, Utc}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 5 | pub struct Field { 6 | pub name: String, 7 | pub value: String, 8 | pub verified_at: Option>, 9 | pub verified: Option, 10 | } 11 | -------------------------------------------------------------------------------- /src/entities/filter.rs: -------------------------------------------------------------------------------- 1 | use chrono::{DateTime, Utc}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 5 | pub struct Filter { 6 | pub id: String, 7 | pub phrase: String, 8 | pub context: Vec, 9 | pub expires_at: Option>, 10 | pub irreversible: bool, 11 | pub whole_word: bool, 12 | } 13 | 14 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 15 | #[serde(rename_all = "lowercase")] 16 | pub enum FilterContext { 17 | Home, 18 | Notifications, 19 | Public, 20 | Thread, 21 | } 22 | -------------------------------------------------------------------------------- /src/entities/follow_request.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, Field}; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] 6 | pub struct FollowRequest { 7 | pub id: u64, 8 | pub username: String, 9 | pub acct: String, 10 | pub display_name: String, 11 | pub locked: bool, 12 | pub bot: bool, 13 | pub discoverable: Option, 14 | pub group: bool, 15 | pub created_at: DateTime, 16 | pub note: String, 17 | pub url: String, 18 | pub avatar: String, 19 | pub avatar_static: String, 20 | pub header: String, 21 | pub header_static: String, 22 | pub followers_count: i32, 23 | pub following_count: u32, 24 | pub statuses_count: u32, 25 | pub emojis: Vec, 26 | pub fields: Vec, 27 | } 28 | -------------------------------------------------------------------------------- /src/entities/history.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct History { 5 | pub day: u64, 6 | pub uses: usize, 7 | pub accounts: usize, 8 | } 9 | 10 | pub fn parse_from_string<'de, T, D>(deserializer: D) -> Result 11 | where 12 | D: serde::Deserializer<'de>, 13 | T: std::str::FromStr, 14 | ::Err: std::fmt::Display, 15 | { 16 | Ok(String::deserialize(deserializer)? 17 | .parse() 18 | .map_err(serde::de::Error::custom)?) 19 | } 20 | -------------------------------------------------------------------------------- /src/entities/identity_proof.rs: -------------------------------------------------------------------------------- 1 | use chrono::{DateTime, Utc}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 5 | pub struct IdentityProof { 6 | pub provider: String, 7 | pub provider_username: String, 8 | pub updated_at: DateTime, 9 | pub proof_url: String, 10 | pub profile_url: String, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/instance.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Stats, URLs}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 5 | pub struct Instance { 6 | pub uri: String, 7 | pub title: String, 8 | pub description: String, 9 | pub email: String, 10 | pub version: String, 11 | pub thumbnail: Option, 12 | pub urls: Option, 13 | pub stats: Stats, 14 | pub languages: Vec, 15 | pub registrations: bool, 16 | pub approval_required: bool, 17 | pub invites_enabled: Option, 18 | pub configuration: InstanceConfig, 19 | pub contact_account: Option, 20 | pub rules: Option>, 21 | } 22 | 23 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 24 | pub struct InstanceConfig { 25 | pub statuses: Statuses, 26 | pub polls: Option, 27 | } 28 | 29 | #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] 30 | pub struct Statuses { 31 | pub max_characters: u32, 32 | pub max_media_attachments: Option, 33 | pub characters_reserved_per_url: Option, 34 | } 35 | 36 | #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] 37 | pub struct Polls { 38 | pub max_options: u32, 39 | pub max_characters_per_option: u32, 40 | pub min_expiration: u32, 41 | pub max_expiration: u32, 42 | } 43 | 44 | #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] 45 | pub struct InstanceRule { 46 | pub id: String, 47 | pub text: String, 48 | } 49 | -------------------------------------------------------------------------------- /src/entities/list.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct List { 7 | pub id: String, 8 | pub title: String, 9 | pub replies_policy: Option, 10 | } 11 | 12 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 13 | #[serde(rename_all = "snake_case")] 14 | pub enum RepliesPolicy { 15 | Followed, 16 | List, 17 | None, 18 | } 19 | 20 | impl fmt::Display for RepliesPolicy { 21 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 22 | match self { 23 | RepliesPolicy::Followed => write!(f, "followed"), 24 | RepliesPolicy::List => write!(f, "list"), 25 | RepliesPolicy::None => write!(f, "none"), 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/entities/marker.rs: -------------------------------------------------------------------------------- 1 | use chrono::{DateTime, Utc}; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 5 | pub struct Marker { 6 | pub home: Option, 7 | pub notifications: Option, 8 | } 9 | 10 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 11 | pub struct InnerMarker { 12 | pub last_read_id: String, 13 | pub version: u32, 14 | pub updated_at: DateTime, 15 | pub unread_count: Option, 16 | } 17 | -------------------------------------------------------------------------------- /src/entities/mention.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct Mention { 5 | pub id: String, 6 | pub username: String, 7 | pub url: String, 8 | pub acct: String, 9 | } 10 | -------------------------------------------------------------------------------- /src/entities/poll.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::{Emoji, PollOption}; 4 | use chrono::{DateTime, Utc}; 5 | 6 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 7 | pub struct Poll { 8 | pub id: String, 9 | pub expires_at: Option>, 10 | pub expired: bool, 11 | pub multiple: bool, 12 | pub votes_count: u32, 13 | pub voters_count: Option, 14 | pub options: Vec, 15 | pub voted: Option, 16 | pub emojis: Vec, 17 | } 18 | -------------------------------------------------------------------------------- /src/entities/poll_option.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct PollOption { 5 | pub title: String, 6 | pub votes_count: Option, 7 | } 8 | -------------------------------------------------------------------------------- /src/entities/push_subscription.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct PushSubscription { 5 | pub id: String, 6 | pub endpoint: String, 7 | pub server_key: String, 8 | pub alerts: Alerts, 9 | } 10 | 11 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 12 | pub struct Alerts { 13 | pub follow: bool, 14 | pub favourite: bool, 15 | pub mention: bool, 16 | pub reblog: bool, 17 | pub poll: bool, 18 | } 19 | -------------------------------------------------------------------------------- /src/entities/reaction.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::Account; 4 | 5 | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] 6 | pub struct Reaction { 7 | pub count: u32, 8 | pub me: bool, 9 | pub name: String, 10 | pub url: Option, 11 | pub static_url: Option, 12 | pub accounts: Option>, 13 | pub account_ids: Option>, 14 | } 15 | -------------------------------------------------------------------------------- /src/entities/relationship.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct Relationship { 5 | pub id: String, 6 | pub following: bool, 7 | pub followed_by: bool, 8 | pub blocking: bool, 9 | pub blocked_by: bool, 10 | pub muting: bool, 11 | pub muting_notifications: bool, 12 | pub requested: bool, 13 | pub domain_blocking: bool, 14 | pub showing_reblogs: bool, 15 | pub endorsed: bool, 16 | pub notifying: bool, 17 | // Friendica returns null as note. 18 | pub note: Option, 19 | } 20 | -------------------------------------------------------------------------------- /src/entities/report.rs: -------------------------------------------------------------------------------- 1 | use core::fmt; 2 | 3 | use chrono::{DateTime, Utc}; 4 | use serde::{Deserialize, Serialize}; 5 | 6 | use super::Account; 7 | 8 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 9 | pub struct Report { 10 | pub id: String, 11 | pub action_taken: bool, 12 | pub action_taken_at: Option>, 13 | pub status_ids: Option>, 14 | pub rule_ids: Option>, 15 | // These parameters are optional in Pleroma. 16 | pub category: Option, 17 | pub comment: Option, 18 | pub forwarded: Option, 19 | pub target_account: Option, 20 | } 21 | 22 | #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] 23 | #[serde(rename_all = "lowercase")] 24 | pub enum Category { 25 | Spam, 26 | Violation, 27 | Other, 28 | } 29 | 30 | impl fmt::Display for Category { 31 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 32 | match self { 33 | Category::Spam => write!(f, "spam"), 34 | Category::Violation => write!(f, "violation"), 35 | Category::Other => write!(f, "other"), 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/entities/results.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::{Account, Status, Tag}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct Results { 7 | pub accounts: Vec, 8 | pub statuses: Vec, 9 | pub hashtags: Vec, 10 | } 11 | -------------------------------------------------------------------------------- /src/entities/role.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 4 | pub struct Role { 5 | pub name: String, 6 | } 7 | -------------------------------------------------------------------------------- /src/entities/scheduled_status.rs: -------------------------------------------------------------------------------- 1 | use super::{Attachment, StatusParams}; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct ScheduledStatus { 7 | pub id: String, 8 | pub scheduled_at: DateTime, 9 | pub params: StatusParams, 10 | pub media_attachments: Option>, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/source.rs: -------------------------------------------------------------------------------- 1 | use super::Field; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 5 | pub struct Source { 6 | pub privacy: Option, 7 | pub sensitive: Option, 8 | pub language: Option, 9 | pub note: String, 10 | pub fields: Option>, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] 4 | pub struct Stats { 5 | pub user_count: u32, 6 | pub status_count: u64, 7 | pub domain_count: u32, 8 | } 9 | -------------------------------------------------------------------------------- /src/entities/status_params.rs: -------------------------------------------------------------------------------- 1 | use super::StatusVisibility; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct StatusParams { 7 | pub text: String, 8 | pub in_reply_to_id: Option, 9 | pub media_ids: Option>, 10 | pub sensitive: Option, 11 | pub spoiler_text: Option, 12 | pub visibility: Option, 13 | pub scheduled_at: Option>, 14 | pub application_id: Option, 15 | } 16 | -------------------------------------------------------------------------------- /src/entities/status_source.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct StatusSource { 5 | // ID of the status in the database 6 | pub id: String, 7 | // The plain text used to compose the status 8 | pub text: String, 9 | // The plain text used to compose the status’s subject or content warning 10 | pub spoiler_text: String, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/tag.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use super::History; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 6 | pub struct Tag { 7 | pub name: String, 8 | pub url: String, 9 | pub history: Vec, 10 | pub following: Option, 11 | } 12 | -------------------------------------------------------------------------------- /src/entities/token.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 4 | pub struct Token { 5 | pub access_token: String, 6 | pub token_type: String, 7 | pub scope: String, 8 | pub created_at: u64, 9 | } 10 | -------------------------------------------------------------------------------- /src/entities/urls.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] 4 | pub struct URLs { 5 | pub streaming_api: String, 6 | } 7 | -------------------------------------------------------------------------------- /src/firefish/entities/announcement.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Announcement { 8 | id: String, 9 | created_at: DateTime, 10 | updated_at: Option>, 11 | text: String, 12 | title: String, 13 | // image_url: Option, 14 | is_read: Option, 15 | // show_popup: bool, 16 | // is_good_news: bool, 17 | } 18 | 19 | impl From for MegalodonEntities::Announcement { 20 | fn from(val: Announcement) -> Self { 21 | MegalodonEntities::Announcement { 22 | id: val.id, 23 | content: format!("{}\n{}", val.title, val.text), 24 | starts_at: None, 25 | ends_at: None, 26 | published: true, 27 | all_day: true, 28 | published_at: val.created_at, 29 | updated_at: val.updated_at, 30 | read: val.is_read, 31 | mentions: [].to_vec(), 32 | statuses: [].to_vec(), 33 | tags: [].to_vec(), 34 | emojis: [].to_vec(), 35 | reactions: [].to_vec(), 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/firefish/entities/app.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | #[derive(Debug, Deserialize, Clone)] 4 | #[serde(rename_all = "camelCase")] 5 | pub struct App { 6 | // id: String, 7 | // name: String, 8 | // callback_url: Option, 9 | // permission: Vec, 10 | // secret: Option, 11 | // is_authorized: Option, 12 | } 13 | -------------------------------------------------------------------------------- /src/firefish/entities/blocking.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use super::UserDetail; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Blocking { 8 | // id: String, 9 | // created_at: DateTime, 10 | // blockee_id: String, 11 | pub blockee: UserDetail, 12 | } 13 | -------------------------------------------------------------------------------- /src/firefish/entities/created_note.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use super::Note; 4 | use crate::{entities as MegalodonEntities, megalodon}; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | #[serde(rename_all = "camelCase")] 8 | pub struct CreatedNote { 9 | created_note: Note, 10 | } 11 | 12 | impl From for MegalodonEntities::Status { 13 | fn from(val: CreatedNote) -> Self { 14 | val.created_note.into() 15 | } 16 | } 17 | 18 | impl From for megalodon::PostStatusOutput { 19 | fn from(val: CreatedNote) -> Self { 20 | megalodon::PostStatusOutput::Status(val.into()) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/firefish/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Emoji { 6 | pub(crate) name: String, 7 | pub(crate) url: String, 8 | pub(crate) category: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Emoji { 12 | fn from(val: Emoji) -> Self { 13 | MegalodonEntities::Emoji { 14 | shortcode: val.name, 15 | static_url: val.url.clone(), 16 | url: val.url, 17 | visible_in_picker: true, 18 | category: val.category, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/firefish/entities/favorite.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use super::Note; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Favorite { 8 | // id: String, 9 | // created_at: String, 10 | // note_id: String, 11 | pub note: Note, 12 | } 13 | -------------------------------------------------------------------------------- /src/firefish/entities/field.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Field { 6 | name: String, 7 | value: String, 8 | verified: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Field { 12 | fn from(val: Field) -> Self { 13 | MegalodonEntities::Field { 14 | name: val.name, 15 | value: val.value, 16 | verified_at: None, 17 | verified: val.verified, 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/firefish/entities/follow.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use super::UserDetail; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Follow { 8 | // id: String, 9 | // created_at: DateTime, 10 | // followee_id: String, 11 | // follower_id: String, 12 | pub follower: UserDetail, 13 | pub followee: UserDetail, 14 | } 15 | -------------------------------------------------------------------------------- /src/firefish/entities/follow_request.rs: -------------------------------------------------------------------------------- 1 | use super::User; 2 | use serde::Deserialize; 3 | 4 | use crate::{entities as MegalodonEntities, megalodon}; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | #[serde(rename_all = "camelCase")] 8 | pub struct FollowRequest { 9 | // id: String, 10 | follower: User, 11 | // followee: User, 12 | } 13 | 14 | impl From for MegalodonEntities::Account { 15 | fn from(val: FollowRequest) -> Self { 16 | val.follower.into() 17 | } 18 | } 19 | 20 | impl From for megalodon::FollowRequestOutput { 21 | fn from(val: FollowRequest) -> Self { 22 | megalodon::FollowRequestOutput::Account(val.into()) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/firefish/entities/hashtag.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | #[serde(rename_all = "camelCase")] 6 | pub struct Hashtag { 7 | pub tag: String, 8 | } 9 | 10 | impl From for MegalodonEntities::Tag { 11 | fn from(val: Hashtag) -> Self { 12 | MegalodonEntities::Tag { 13 | name: val.tag.clone(), 14 | url: val.tag, 15 | history: [].to_vec(), 16 | following: None, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/firefish/entities/list.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | #[serde(rename_all = "camelCase")] 6 | pub struct List { 7 | id: String, 8 | // created_at: DateTime, 9 | name: String, 10 | pub user_ids: Option>, 11 | } 12 | 13 | impl From for MegalodonEntities::List { 14 | fn from(val: List) -> Self { 15 | MegalodonEntities::List { 16 | id: val.id, 17 | title: val.name, 18 | replies_policy: None, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/firefish/entities/meta.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use super::Emoji; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Meta { 8 | pub emojis: Vec, 9 | } 10 | -------------------------------------------------------------------------------- /src/firefish/entities/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod account; 2 | pub mod announcement; 3 | pub mod app; 4 | pub mod blocking; 5 | pub mod created_note; 6 | pub mod emoji; 7 | pub mod favorite; 8 | pub mod field; 9 | pub mod file; 10 | pub mod follow; 11 | pub mod follow_request; 12 | pub mod hashtag; 13 | pub mod instance; 14 | pub mod list; 15 | pub mod meta; 16 | pub mod mute; 17 | pub mod note; 18 | pub mod notification; 19 | pub mod poll; 20 | pub mod preferences; 21 | pub mod reaction; 22 | pub mod relation; 23 | pub mod session; 24 | pub mod stats; 25 | pub mod user; 26 | pub mod user_detail; 27 | 28 | pub use account::Account; 29 | pub use announcement::Announcement; 30 | #[allow(unused_imports)] 31 | pub use app::App; 32 | pub use blocking::Blocking; 33 | pub use created_note::CreatedNote; 34 | pub use emoji::Emoji; 35 | pub use favorite::Favorite; 36 | pub use field::Field; 37 | pub use file::File; 38 | pub use follow::Follow; 39 | pub use follow_request::FollowRequest; 40 | pub use hashtag::Hashtag; 41 | pub use instance::Instance; 42 | pub use list::List; 43 | pub use meta::Meta; 44 | pub use mute::Mute; 45 | pub use note::Note; 46 | pub use notification::Notification; 47 | #[allow(unused_imports)] 48 | pub use poll::Poll; 49 | #[allow(unused_imports)] 50 | pub use reaction::Reaction; 51 | pub use relation::Relation; 52 | pub use session::Session; 53 | #[allow(unused_imports)] 54 | pub use stats::Stats; 55 | pub use user::User; 56 | pub use user_detail::UserDetail; 57 | -------------------------------------------------------------------------------- /src/firefish/entities/mute.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use super::UserDetail; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Mute { 8 | // id: String, 9 | // created_at: DateTime, 10 | // mutee_id: String, 11 | pub mutee: UserDetail, 12 | } 13 | -------------------------------------------------------------------------------- /src/firefish/entities/preferences.rs: -------------------------------------------------------------------------------- 1 | use super::UserDetail; 2 | use crate::entities as MegalodonEntities; 3 | 4 | pub fn convert_preferences( 5 | user_detail: UserDetail, 6 | visibility: MegalodonEntities::StatusVisibility, 7 | ) -> MegalodonEntities::Preferences { 8 | let nsfw = if let Some(n) = user_detail.always_mark_nsfw { 9 | n 10 | } else { 11 | false 12 | }; 13 | 14 | MegalodonEntities::Preferences { 15 | posting_default_visibility: visibility, 16 | posting_default_sensitive: nsfw, 17 | posting_default_language: user_detail.lang, 18 | reading_expand_media: MegalodonEntities::preferences::ExpandMedia::Default, 19 | reading_expand_spoilers: false, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/firefish/entities/relation.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | use crate::entities as MegalodonEntities; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | #[serde(rename_all = "camelCase")] 7 | pub struct Relation { 8 | id: String, 9 | is_following: bool, 10 | has_pending_follow_request_from_you: bool, 11 | // has_pending_follow_request_to_you: bool, 12 | is_followed: bool, 13 | is_blocking: bool, 14 | is_blocked: bool, 15 | is_muted: bool, 16 | is_renote_muted: bool, 17 | } 18 | 19 | impl From for MegalodonEntities::Relationship { 20 | fn from(val: Relation) -> Self { 21 | MegalodonEntities::Relationship { 22 | id: val.id, 23 | following: val.is_following, 24 | followed_by: val.is_followed, 25 | blocking: val.is_blocking, 26 | blocked_by: val.is_blocked, 27 | muting: val.is_muted, 28 | muting_notifications: false, 29 | requested: val.has_pending_follow_request_from_you, 30 | domain_blocking: false, 31 | showing_reblogs: val.is_renote_muted, 32 | endorsed: false, 33 | notifying: false, 34 | note: None, 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/firefish/entities/session.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | #[derive(Debug, Deserialize, Clone)] 4 | pub struct Session { 5 | pub url: String, 6 | pub token: String, 7 | } 8 | -------------------------------------------------------------------------------- /src/firefish/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | #[serde(rename_all = "camelCase")] 6 | pub struct Stats { 7 | notes_count: u64, 8 | // original_notes_count: u32, 9 | users_count: u32, 10 | // original_users_count: u32, 11 | instances: u32, 12 | } 13 | 14 | impl From for MegalodonEntities::Stats { 15 | fn from(val: Stats) -> Self { 16 | MegalodonEntities::Stats { 17 | user_count: val.users_count, 18 | status_count: val.notes_count, 19 | domain_count: val.instances, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/firefish/mod.rs: -------------------------------------------------------------------------------- 1 | //! FireFish related modules 2 | 3 | mod api_client; 4 | mod entities; 5 | pub mod firefish; 6 | mod oauth; 7 | mod web_socket; 8 | 9 | pub use firefish::Firefish; 10 | -------------------------------------------------------------------------------- /src/firefish/oauth.rs: -------------------------------------------------------------------------------- 1 | use crate::oauth; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct AppDataFromServer { 6 | pub id: String, 7 | pub name: String, 8 | // #[serde(rename = "callbackUrl")] 9 | pub callback_url: Option, 10 | pub permission: Vec, 11 | pub secret: Option, 12 | #[serde(rename = "isAuthorized")] 13 | pub is_authorized: Option, 14 | } 15 | 16 | impl From for oauth::AppData { 17 | fn from(val: AppDataFromServer) -> Self { 18 | oauth::AppData::new( 19 | val.id, 20 | val.name, 21 | None, 22 | val.callback_url, 23 | "".to_string(), 24 | val.secret.unwrap(), 25 | ) 26 | } 27 | } 28 | 29 | /// Obteined token data from server. 30 | #[derive(Debug, Deserialize, Clone)] 31 | pub struct TokenDataFromServer { 32 | #[serde(rename = "accessToken")] 33 | access_token: String, 34 | } 35 | 36 | impl From for oauth::TokenData { 37 | fn from(val: TokenDataFromServer) -> Self { 38 | oauth::TokenData::new( 39 | val.access_token, 40 | "Firefish".to_string(), 41 | None, 42 | None, 43 | None, 44 | None, 45 | ) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/friendica/entities/activity.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Activity { 6 | week: String, 7 | statuses: String, 8 | logins: String, 9 | registrations: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Activity { 13 | fn from(val: Activity) -> Self { 14 | MegalodonEntities::Activity { 15 | week: val.week, 16 | statuses: val.statuses, 17 | logins: val.logins, 18 | registrations: val.registrations, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/friendica/entities/application.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Application { 6 | name: String, 7 | website: Option, 8 | vapid_key: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Application { 12 | fn from(val: Application) -> Self { 13 | MegalodonEntities::Application { 14 | name: val.name, 15 | website: val.website, 16 | vapid_key: val.vapid_key, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/friendica/entities/context.rs: -------------------------------------------------------------------------------- 1 | use super::Status; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Context { 7 | ancestors: Vec, 8 | descendants: Vec, 9 | } 10 | 11 | impl From for MegalodonEntities::Context { 12 | fn from(val: Context) -> Self { 13 | MegalodonEntities::Context { 14 | ancestors: val.ancestors.into_iter().map(|i| i.into()).collect(), 15 | descendants: val.descendants.into_iter().map(|i| i.into()).collect(), 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/friendica/entities/conversation.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Conversation { 7 | id: String, 8 | accounts: Vec, 9 | last_status: Option, 10 | unread: bool, 11 | } 12 | 13 | impl From for MegalodonEntities::Conversation { 14 | fn from(val: Conversation) -> Self { 15 | MegalodonEntities::Conversation { 16 | id: val.id, 17 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 18 | last_status: val.last_status.map(|i| i.into()), 19 | unread: val.unread, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/friendica/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Emoji { 6 | shortcode: String, 7 | static_url: String, 8 | url: String, 9 | visible_in_picker: bool, 10 | } 11 | 12 | impl From for Emoji { 13 | fn from(item: MegalodonEntities::Emoji) -> Self { 14 | Self { 15 | shortcode: item.shortcode, 16 | static_url: item.static_url, 17 | url: item.url, 18 | visible_in_picker: item.visible_in_picker, 19 | } 20 | } 21 | } 22 | 23 | impl From for MegalodonEntities::Emoji { 24 | fn from(val: Emoji) -> Self { 25 | MegalodonEntities::Emoji { 26 | shortcode: val.shortcode, 27 | static_url: val.static_url, 28 | url: val.url, 29 | visible_in_picker: val.visible_in_picker, 30 | category: None, 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/friendica/entities/featured_tag.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct FeaturedTag { 7 | id: String, 8 | name: String, 9 | statuses_count: u32, 10 | last_status_at: DateTime, 11 | } 12 | 13 | impl From for MegalodonEntities::FeaturedTag { 14 | fn from(val: FeaturedTag) -> Self { 15 | MegalodonEntities::FeaturedTag { 16 | id: val.id, 17 | name: val.name, 18 | statuses_count: val.statuses_count, 19 | last_status_at: val.last_status_at, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/friendica/entities/field.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Field { 7 | name: String, 8 | value: String, 9 | verified_at: Option>, 10 | } 11 | 12 | impl From for Field { 13 | fn from(item: MegalodonEntities::Field) -> Self { 14 | Self { 15 | name: item.name, 16 | value: item.value, 17 | verified_at: item.verified_at, 18 | } 19 | } 20 | } 21 | 22 | impl From for MegalodonEntities::Field { 23 | fn from(val: Field) -> Self { 24 | MegalodonEntities::Field { 25 | name: val.name, 26 | value: val.value, 27 | verified_at: val.verified_at, 28 | verified: None, 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/friendica/entities/filter.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Filter { 7 | id: String, 8 | phrase: String, 9 | context: Vec, 10 | expires_at: Option>, 11 | irreversible: bool, 12 | whole_word: bool, 13 | } 14 | 15 | #[derive(Debug, Clone, Serialize, Deserialize)] 16 | #[serde(rename_all = "lowercase")] 17 | pub enum FilterContext { 18 | Home, 19 | Notifications, 20 | Public, 21 | Thread, 22 | } 23 | 24 | impl From for MegalodonEntities::filter::FilterContext { 25 | fn from(val: FilterContext) -> Self { 26 | match val { 27 | FilterContext::Home => MegalodonEntities::filter::FilterContext::Home, 28 | FilterContext::Notifications => MegalodonEntities::filter::FilterContext::Notifications, 29 | FilterContext::Public => MegalodonEntities::filter::FilterContext::Public, 30 | FilterContext::Thread => MegalodonEntities::filter::FilterContext::Thread, 31 | } 32 | } 33 | } 34 | 35 | impl From for MegalodonEntities::Filter { 36 | fn from(val: Filter) -> Self { 37 | MegalodonEntities::Filter { 38 | id: val.id, 39 | phrase: val.phrase, 40 | context: val.context.into_iter().map(|i| i.into()).collect(), 41 | expires_at: val.expires_at, 42 | irreversible: val.irreversible, 43 | whole_word: val.whole_word, 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/friendica/entities/history.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct History { 6 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 7 | day: u64, 8 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 9 | uses: usize, 10 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 11 | accounts: usize, 12 | } 13 | 14 | impl From for MegalodonEntities::History { 15 | fn from(val: History) -> Self { 16 | MegalodonEntities::History { 17 | day: val.day, 18 | uses: val.uses, 19 | accounts: val.accounts, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/friendica/entities/identity_proof.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct IdentityProof { 7 | provider: String, 8 | provider_username: String, 9 | updated_at: DateTime, 10 | proof_url: String, 11 | profile_url: String, 12 | } 13 | 14 | impl From for MegalodonEntities::IdentityProof { 15 | fn from(val: IdentityProof) -> Self { 16 | MegalodonEntities::IdentityProof { 17 | provider: val.provider, 18 | provider_username: val.provider_username, 19 | updated_at: val.updated_at, 20 | proof_url: val.proof_url, 21 | profile_url: val.profile_url, 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/friendica/entities/list.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct List { 6 | id: String, 7 | title: String, 8 | replies_policy: RepliesPolicy, 9 | } 10 | 11 | #[derive(Debug, Deserialize, Clone)] 12 | #[serde(rename_all = "snake_case")] 13 | pub enum RepliesPolicy { 14 | Followed, 15 | List, 16 | None, 17 | } 18 | 19 | impl From for MegalodonEntities::list::RepliesPolicy { 20 | fn from(val: RepliesPolicy) -> Self { 21 | match val { 22 | RepliesPolicy::Followed => MegalodonEntities::list::RepliesPolicy::Followed, 23 | RepliesPolicy::List => MegalodonEntities::list::RepliesPolicy::List, 24 | RepliesPolicy::None => MegalodonEntities::list::RepliesPolicy::None, 25 | } 26 | } 27 | } 28 | 29 | impl From for MegalodonEntities::List { 30 | fn from(val: List) -> Self { 31 | MegalodonEntities::List { 32 | id: val.id, 33 | title: val.title, 34 | replies_policy: Some(val.replies_policy.into()), 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/friendica/entities/marker.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Marker { 7 | home: Option, 8 | notifications: Option, 9 | } 10 | 11 | #[derive(Debug, Deserialize, Clone)] 12 | struct InnerMarker { 13 | last_read_id: String, 14 | version: u32, 15 | updated_at: DateTime, 16 | } 17 | 18 | impl From for MegalodonEntities::Marker { 19 | fn from(val: Marker) -> Self { 20 | MegalodonEntities::Marker { 21 | home: val.home.map(|i| i.into()), 22 | notifications: val.notifications.map(|i| i.into()), 23 | } 24 | } 25 | } 26 | 27 | impl From for MegalodonEntities::marker::InnerMarker { 28 | fn from(val: InnerMarker) -> Self { 29 | MegalodonEntities::marker::InnerMarker { 30 | last_read_id: val.last_read_id, 31 | version: val.version, 32 | updated_at: val.updated_at, 33 | unread_count: None, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/friendica/entities/mention.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Mention { 6 | id: String, 7 | username: String, 8 | url: String, 9 | acct: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Mention { 13 | fn from(val: Mention) -> Self { 14 | MegalodonEntities::Mention { 15 | id: val.id, 16 | username: val.username, 17 | url: val.url, 18 | acct: val.acct, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/friendica/entities/poll.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, PollOption}; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct Poll { 8 | id: String, 9 | expires_at: Option>, 10 | expired: bool, 11 | multiple: bool, 12 | votes_count: u32, 13 | voters_count: Option, 14 | options: Vec, 15 | voted: Option, 16 | emojis: Vec, 17 | } 18 | 19 | impl From for MegalodonEntities::Poll { 20 | fn from(val: Poll) -> Self { 21 | MegalodonEntities::Poll { 22 | id: val.id, 23 | expires_at: val.expires_at, 24 | expired: val.expired, 25 | multiple: val.multiple, 26 | votes_count: val.votes_count, 27 | voters_count: val.voters_count, 28 | options: val.options.into_iter().map(|i| i.into()).collect(), 29 | voted: val.voted, 30 | emojis: val.emojis.into_iter().map(|i| i.into()).collect(), 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/friendica/entities/poll_option.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PollOption { 6 | title: String, 7 | votes_count: Option, 8 | } 9 | 10 | impl From for MegalodonEntities::PollOption { 11 | fn from(val: PollOption) -> Self { 12 | MegalodonEntities::PollOption { 13 | title: val.title, 14 | votes_count: val.votes_count, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/friendica/entities/push_subscription.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PushSubscription { 6 | id: String, 7 | endpoint: String, 8 | server_key: String, 9 | alerts: Alerts, 10 | } 11 | 12 | #[derive(Debug, Deserialize, Clone)] 13 | struct Alerts { 14 | follow: bool, 15 | favourite: bool, 16 | mention: bool, 17 | reblog: bool, 18 | poll: bool, 19 | } 20 | 21 | impl From for MegalodonEntities::PushSubscription { 22 | fn from(val: PushSubscription) -> Self { 23 | MegalodonEntities::PushSubscription { 24 | id: val.id, 25 | endpoint: val.endpoint, 26 | server_key: val.server_key, 27 | alerts: val.alerts.into(), 28 | } 29 | } 30 | } 31 | 32 | impl From for MegalodonEntities::push_subscription::Alerts { 33 | fn from(val: Alerts) -> Self { 34 | MegalodonEntities::push_subscription::Alerts { 35 | follow: val.follow, 36 | favourite: val.favourite, 37 | mention: val.mention, 38 | reblog: val.reblog, 39 | poll: val.poll, 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/friendica/entities/relationship.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Relationship { 6 | id: String, 7 | following: bool, 8 | followed_by: bool, 9 | blocking: bool, 10 | blocked_by: bool, 11 | muting: bool, 12 | muting_notifications: bool, 13 | requested: bool, 14 | domain_blocking: bool, 15 | showing_reblogs: bool, 16 | endorsed: bool, 17 | notifying: bool, 18 | note: Option, 19 | } 20 | 21 | impl From for MegalodonEntities::Relationship { 22 | fn from(val: Relationship) -> Self { 23 | MegalodonEntities::Relationship { 24 | id: val.id, 25 | following: val.following, 26 | followed_by: val.followed_by, 27 | blocking: val.blocking, 28 | blocked_by: val.blocked_by, 29 | muting: val.muting, 30 | muting_notifications: val.muting_notifications, 31 | requested: val.requested, 32 | domain_blocking: val.domain_blocking, 33 | showing_reblogs: val.showing_reblogs, 34 | endorsed: val.endorsed, 35 | notifying: val.notifying, 36 | note: val.note, 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/friendica/entities/report.rs: -------------------------------------------------------------------------------- 1 | use super::Account; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Report { 7 | pub id: String, 8 | pub action_taken: bool, 9 | pub category: Category, 10 | pub comment: String, 11 | pub forwarded: bool, 12 | pub status_ids: Option>, 13 | pub rule_ids: Option>, 14 | pub target_account: Account, 15 | } 16 | 17 | #[derive(Debug, Clone, Deserialize)] 18 | #[serde(rename_all = "lowercase")] 19 | pub enum Category { 20 | Spam, 21 | Violation, 22 | Other, 23 | } 24 | 25 | impl From for MegalodonEntities::report::Category { 26 | fn from(val: Category) -> Self { 27 | match val { 28 | Category::Spam => MegalodonEntities::report::Category::Spam, 29 | Category::Violation => MegalodonEntities::report::Category::Violation, 30 | Category::Other => MegalodonEntities::report::Category::Other, 31 | } 32 | } 33 | } 34 | 35 | impl From for MegalodonEntities::Report { 36 | fn from(val: Report) -> Self { 37 | MegalodonEntities::Report { 38 | id: val.id, 39 | action_taken: val.action_taken, 40 | action_taken_at: None, 41 | category: Some(val.category.into()), 42 | comment: Some(val.comment), 43 | forwarded: Some(val.forwarded), 44 | status_ids: val.status_ids, 45 | rule_ids: val.rule_ids, 46 | target_account: Some(val.target_account.into()), 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/friendica/entities/results.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status, Tag}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Results { 7 | accounts: Vec, 8 | statuses: Vec, 9 | hashtags: Vec, 10 | } 11 | 12 | impl From for MegalodonEntities::Results { 13 | fn from(val: Results) -> Self { 14 | MegalodonEntities::Results { 15 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 16 | statuses: val.statuses.into_iter().map(|i| i.into()).collect(), 17 | hashtags: val.hashtags.into_iter().map(|i| i.into()).collect(), 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/friendica/entities/scheduled_status.rs: -------------------------------------------------------------------------------- 1 | use super::{Attachment, StatusParams}; 2 | use crate::{entities as MegalodonEntities, megalodon}; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct ScheduledStatus { 8 | id: String, 9 | scheduled_at: DateTime, 10 | params: StatusParams, 11 | media_attachments: Vec, 12 | } 13 | 14 | impl From for MegalodonEntities::ScheduledStatus { 15 | fn from(val: ScheduledStatus) -> Self { 16 | MegalodonEntities::ScheduledStatus { 17 | id: val.id, 18 | scheduled_at: val.scheduled_at, 19 | params: val.params.into(), 20 | media_attachments: Some( 21 | val.media_attachments 22 | .into_iter() 23 | .map(|i| i.into()) 24 | .collect(), 25 | ), 26 | } 27 | } 28 | } 29 | 30 | impl From for megalodon::PostStatusOutput { 31 | fn from(val: ScheduledStatus) -> Self { 32 | megalodon::PostStatusOutput::ScheduledStatus(val.into()) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/friendica/entities/source.rs: -------------------------------------------------------------------------------- 1 | use super::Field; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Source { 7 | privacy: Option, 8 | sensitive: Option, 9 | language: Option, 10 | note: String, 11 | fields: Option>, 12 | } 13 | 14 | impl From for Source { 15 | fn from(item: MegalodonEntities::Source) -> Self { 16 | Self { 17 | privacy: item.privacy, 18 | sensitive: item.sensitive, 19 | language: item.language, 20 | note: item.note, 21 | fields: item 22 | .fields 23 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 24 | } 25 | } 26 | } 27 | 28 | impl From for MegalodonEntities::Source { 29 | fn from(val: Source) -> Self { 30 | MegalodonEntities::Source { 31 | privacy: val.privacy, 32 | sensitive: val.sensitive, 33 | language: val.language, 34 | note: val.note, 35 | fields: val 36 | .fields 37 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/friendica/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Stats { 6 | user_count: u32, 7 | status_count: u64, 8 | domain_count: u32, 9 | } 10 | 11 | impl From for MegalodonEntities::Stats { 12 | fn from(val: Stats) -> Self { 13 | MegalodonEntities::Stats { 14 | user_count: val.user_count, 15 | status_count: val.status_count, 16 | domain_count: val.domain_count, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/friendica/entities/status_params.rs: -------------------------------------------------------------------------------- 1 | use super::StatusVisibility; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct StatusParams { 8 | text: String, 9 | in_reply_to_id: Option, 10 | media_ids: Option>, 11 | sensitive: Option, 12 | spoiler_text: Option, 13 | visibility: Option, 14 | scheduled_at: Option>, 15 | application_id: String, 16 | } 17 | 18 | impl From for MegalodonEntities::StatusParams { 19 | fn from(val: StatusParams) -> Self { 20 | let mut app_id: Option = None; 21 | if let Ok(val) = val.application_id.parse::() { 22 | app_id = Some(val); 23 | } 24 | 25 | MegalodonEntities::StatusParams { 26 | text: val.text, 27 | in_reply_to_id: val.in_reply_to_id, 28 | media_ids: val.media_ids, 29 | sensitive: val.sensitive, 30 | spoiler_text: val.spoiler_text, 31 | visibility: val.visibility.map(|i| i.into()), 32 | scheduled_at: val.scheduled_at, 33 | application_id: app_id, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/friendica/entities/tag.rs: -------------------------------------------------------------------------------- 1 | use super::History; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Tag { 7 | name: String, 8 | url: String, 9 | history: Vec, 10 | following: Option, 11 | } 12 | 13 | impl From for MegalodonEntities::Tag { 14 | fn from(val: Tag) -> Self { 15 | MegalodonEntities::Tag { 16 | name: val.name, 17 | url: val.url, 18 | history: val.history.into_iter().map(|j| j.into()).collect(), 19 | following: val.following, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/friendica/entities/token.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Token { 6 | access_token: String, 7 | token_type: String, 8 | scope: String, 9 | created_at: u64, 10 | } 11 | 12 | impl From for MegalodonEntities::Token { 13 | fn from(val: Token) -> Self { 14 | MegalodonEntities::Token { 15 | access_token: val.access_token, 16 | token_type: val.token_type, 17 | scope: val.scope, 18 | created_at: val.created_at, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/friendica/entities/urls.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Deserialize, Debug, Clone)] 5 | pub struct URLs { 6 | streaming_api: String, 7 | } 8 | 9 | impl From for MegalodonEntities::URLs { 10 | fn from(val: URLs) -> Self { 11 | MegalodonEntities::URLs { 12 | streaming_api: val.streaming_api, 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/friendica/mod.rs: -------------------------------------------------------------------------------- 1 | //! Friendica related modules 2 | 3 | mod api_client; 4 | mod entities; 5 | pub mod friendica; 6 | mod oauth; 7 | mod web_socket; 8 | 9 | pub use friendica::Friendica; 10 | -------------------------------------------------------------------------------- /src/friendica/oauth.rs: -------------------------------------------------------------------------------- 1 | use crate::oauth; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct AppDataFromServer { 6 | id: String, 7 | name: String, 8 | website: Option, 9 | redirect_uri: String, 10 | client_id: String, 11 | client_secret: String, 12 | } 13 | 14 | /// Obteined token data from server. 15 | #[derive(Debug, Deserialize, Clone)] 16 | pub struct TokenDataFromServer { 17 | access_token: String, 18 | token_type: String, 19 | scope: String, 20 | created_at: u64, 21 | } 22 | 23 | impl From for oauth::AppData { 24 | fn from(val: AppDataFromServer) -> Self { 25 | oauth::AppData::new( 26 | val.id, 27 | val.name, 28 | val.website, 29 | Some(val.redirect_uri), 30 | val.client_id, 31 | val.client_secret, 32 | ) 33 | } 34 | } 35 | 36 | impl From for oauth::TokenData { 37 | fn from(val: TokenDataFromServer) -> Self { 38 | oauth::TokenData::new( 39 | val.access_token, 40 | val.token_type, 41 | Some(val.scope), 42 | Some(val.created_at), 43 | None, 44 | None, 45 | ) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/friendica/web_socket.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | use std::pin::Pin; 3 | 4 | use crate::streaming::{Message, Streaming}; 5 | use async_trait::async_trait; 6 | use tracing::error; 7 | 8 | #[derive(Debug, Clone)] 9 | pub struct WebSocket {} 10 | 11 | impl WebSocket { 12 | pub fn new() -> Self { 13 | Self {} 14 | } 15 | } 16 | 17 | #[async_trait] 18 | impl Streaming for WebSocket { 19 | async fn listen( 20 | &self, 21 | _callback: Box< 22 | dyn Fn(Message) -> Pin + Send>> 23 | + Send 24 | + Sync 25 | + 'async_trait, 26 | >, 27 | ) { 28 | error!("Friendica does not support WebSocket") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/gotosocial/entities/application.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Application { 6 | name: String, 7 | website: Option, 8 | vapid_key: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Application { 12 | fn from(val: Application) -> Self { 13 | MegalodonEntities::Application { 14 | name: val.name, 15 | website: val.website, 16 | vapid_key: val.vapid_key, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/gotosocial/entities/context.rs: -------------------------------------------------------------------------------- 1 | use super::Status; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Context { 7 | ancestors: Vec, 8 | descendants: Vec, 9 | } 10 | 11 | impl From for MegalodonEntities::Context { 12 | fn from(val: Context) -> MegalodonEntities::Context { 13 | MegalodonEntities::Context { 14 | ancestors: val.ancestors.into_iter().map(|i| i.into()).collect(), 15 | descendants: val.descendants.into_iter().map(|i| i.into()).collect(), 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/gotosocial/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Emoji { 6 | shortcode: String, 7 | static_url: String, 8 | url: String, 9 | visible_in_picker: bool, 10 | category: Option, 11 | } 12 | 13 | impl From for Emoji { 14 | fn from(item: MegalodonEntities::Emoji) -> Self { 15 | Self { 16 | shortcode: item.shortcode, 17 | static_url: item.static_url, 18 | url: item.url, 19 | visible_in_picker: item.visible_in_picker, 20 | category: item.category, 21 | } 22 | } 23 | } 24 | 25 | impl From for MegalodonEntities::Emoji { 26 | fn from(item: Emoji) -> MegalodonEntities::Emoji { 27 | MegalodonEntities::Emoji { 28 | shortcode: item.shortcode, 29 | static_url: item.static_url, 30 | url: item.url, 31 | visible_in_picker: item.visible_in_picker, 32 | category: item.category, 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/gotosocial/entities/field.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Field { 7 | name: String, 8 | value: String, 9 | verified_at: Option>, 10 | } 11 | 12 | impl From for Field { 13 | fn from(item: MegalodonEntities::Field) -> Self { 14 | Self { 15 | name: item.name, 16 | value: item.value, 17 | verified_at: item.verified_at, 18 | } 19 | } 20 | } 21 | 22 | impl From for MegalodonEntities::Field { 23 | fn from(item: Field) -> MegalodonEntities::Field { 24 | MegalodonEntities::Field { 25 | name: item.name, 26 | value: item.value, 27 | verified_at: item.verified_at, 28 | verified: None, 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/gotosocial/entities/filter.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Filter { 7 | id: String, 8 | phrase: String, 9 | context: Vec, 10 | expires_at: Option>, 11 | irreversible: bool, 12 | whole_word: bool, 13 | } 14 | 15 | #[derive(Debug, Clone, Serialize, Deserialize)] 16 | #[serde(rename_all = "lowercase")] 17 | pub enum FilterContext { 18 | Home, 19 | Notifications, 20 | Public, 21 | Thread, 22 | } 23 | 24 | impl From for MegalodonEntities::filter::FilterContext { 25 | fn from(val: FilterContext) -> Self { 26 | match val { 27 | FilterContext::Home => MegalodonEntities::filter::FilterContext::Home, 28 | FilterContext::Notifications => MegalodonEntities::filter::FilterContext::Notifications, 29 | FilterContext::Public => MegalodonEntities::filter::FilterContext::Public, 30 | FilterContext::Thread => MegalodonEntities::filter::FilterContext::Thread, 31 | } 32 | } 33 | } 34 | 35 | impl From for MegalodonEntities::Filter { 36 | fn from(val: Filter) -> Self { 37 | MegalodonEntities::Filter { 38 | id: val.id, 39 | phrase: val.phrase, 40 | context: val.context.into_iter().map(|i| i.into()).collect(), 41 | expires_at: val.expires_at, 42 | irreversible: val.irreversible, 43 | whole_word: val.whole_word, 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/gotosocial/entities/list.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct List { 6 | id: String, 7 | title: String, 8 | replies_policy: Option, 9 | } 10 | 11 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 12 | #[serde(rename_all = "snake_case")] 13 | pub enum RepliesPolicy { 14 | Followed, 15 | List, 16 | None, 17 | } 18 | 19 | impl From for MegalodonEntities::list::RepliesPolicy { 20 | fn from(val: RepliesPolicy) -> MegalodonEntities::list::RepliesPolicy { 21 | match val { 22 | RepliesPolicy::Followed => MegalodonEntities::list::RepliesPolicy::Followed, 23 | RepliesPolicy::List => MegalodonEntities::list::RepliesPolicy::List, 24 | RepliesPolicy::None => MegalodonEntities::list::RepliesPolicy::None, 25 | } 26 | } 27 | } 28 | 29 | impl From for MegalodonEntities::List { 30 | fn from(val: List) -> MegalodonEntities::List { 31 | MegalodonEntities::List { 32 | id: val.id, 33 | title: val.title, 34 | replies_policy: val.replies_policy.map(|r| r.into()), 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/gotosocial/entities/marker.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Marker { 7 | home: InnerMarker, 8 | notifications: InnerMarker, 9 | } 10 | 11 | #[derive(Debug, Deserialize, Clone)] 12 | struct InnerMarker { 13 | last_read_id: String, 14 | version: u32, 15 | updated_at: DateTime, 16 | } 17 | 18 | impl From for MegalodonEntities::Marker { 19 | fn from(val: Marker) -> MegalodonEntities::Marker { 20 | MegalodonEntities::Marker { 21 | home: Some(val.home.into()), 22 | notifications: Some(val.notifications.into()), 23 | } 24 | } 25 | } 26 | 27 | impl From for MegalodonEntities::marker::InnerMarker { 28 | fn from(val: InnerMarker) -> MegalodonEntities::marker::InnerMarker { 29 | MegalodonEntities::marker::InnerMarker { 30 | last_read_id: val.last_read_id, 31 | version: val.version, 32 | updated_at: val.updated_at, 33 | unread_count: None, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/gotosocial/entities/mention.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Mention { 6 | id: String, 7 | username: String, 8 | url: String, 9 | acct: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Mention { 13 | fn from(val: Mention) -> MegalodonEntities::Mention { 14 | MegalodonEntities::Mention { 15 | id: val.id, 16 | username: val.username, 17 | url: val.url, 18 | acct: val.acct, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/gotosocial/entities/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod account; 2 | pub mod application; 3 | pub mod attachment; 4 | pub mod card; 5 | pub mod context; 6 | pub mod emoji; 7 | pub mod field; 8 | pub mod filter; 9 | pub mod instance; 10 | pub mod list; 11 | pub mod marker; 12 | pub mod mention; 13 | pub mod notification; 14 | pub mod poll; 15 | pub mod poll_option; 16 | pub mod preferences; 17 | pub mod relationship; 18 | pub mod report; 19 | pub mod results; 20 | pub mod role; 21 | pub mod scheduled_status; 22 | pub mod source; 23 | pub mod stats; 24 | pub mod status; 25 | pub mod status_params; 26 | pub mod status_source; 27 | pub mod tag; 28 | pub mod token; 29 | pub mod urls; 30 | 31 | pub use account::Account; 32 | pub use application::Application; 33 | pub use attachment::Attachment; 34 | pub use card::Card; 35 | pub use context::Context; 36 | pub use emoji::Emoji; 37 | pub use field::Field; 38 | pub use filter::Filter; 39 | pub use instance::Instance; 40 | pub use list::List; 41 | pub use marker::Marker; 42 | pub use mention::Mention; 43 | pub use notification::Notification; 44 | pub use poll::Poll; 45 | pub use poll_option::PollOption; 46 | pub use preferences::Preferences; 47 | pub use relationship::Relationship; 48 | pub use report::Report; 49 | pub use results::Results; 50 | pub use role::Role; 51 | pub use scheduled_status::ScheduledStatus; 52 | pub use source::Source; 53 | pub use stats::Stats; 54 | pub use status::{Status, StatusVisibility}; 55 | pub use status_params::StatusParams; 56 | pub use status_source::StatusSource; 57 | pub use tag::Tag; 58 | pub use token::Token; 59 | pub use urls::URLs; 60 | -------------------------------------------------------------------------------- /src/gotosocial/entities/poll.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, PollOption}; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct Poll { 8 | id: String, 9 | expires_at: Option>, 10 | expired: bool, 11 | multiple: bool, 12 | votes_count: u32, 13 | voters_count: Option, 14 | options: Vec, 15 | voted: Option, 16 | emojis: Vec, 17 | } 18 | 19 | impl From for MegalodonEntities::Poll { 20 | fn from(val: Poll) -> MegalodonEntities::Poll { 21 | MegalodonEntities::Poll { 22 | id: val.id, 23 | expires_at: val.expires_at, 24 | expired: val.expired, 25 | multiple: val.multiple, 26 | votes_count: val.votes_count, 27 | voters_count: val.voters_count, 28 | options: val.options.into_iter().map(|i| i.into()).collect(), 29 | voted: val.voted, 30 | emojis: val.emojis.into_iter().map(|i| i.into()).collect(), 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/gotosocial/entities/poll_option.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PollOption { 6 | title: String, 7 | votes_count: Option, 8 | } 9 | 10 | impl From for MegalodonEntities::PollOption { 11 | fn from(val: PollOption) -> MegalodonEntities::PollOption { 12 | MegalodonEntities::PollOption { 13 | title: val.title, 14 | votes_count: val.votes_count, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/gotosocial/entities/relationship.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Relationship { 6 | id: String, 7 | following: bool, 8 | followed_by: bool, 9 | blocking: bool, 10 | blocked_by: bool, 11 | muting: bool, 12 | muting_notifications: bool, 13 | requested: bool, 14 | domain_blocking: bool, 15 | showing_reblogs: bool, 16 | endorsed: bool, 17 | notifying: bool, 18 | note: String, 19 | } 20 | 21 | impl From for MegalodonEntities::Relationship { 22 | fn from(val: Relationship) -> MegalodonEntities::Relationship { 23 | MegalodonEntities::Relationship { 24 | id: val.id, 25 | following: val.following, 26 | followed_by: val.followed_by, 27 | blocking: val.blocking, 28 | blocked_by: val.blocked_by, 29 | muting: val.muting, 30 | muting_notifications: val.muting_notifications, 31 | requested: val.requested, 32 | domain_blocking: val.domain_blocking, 33 | showing_reblogs: val.showing_reblogs, 34 | endorsed: val.endorsed, 35 | notifying: val.notifying, 36 | note: Some(val.note), 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/gotosocial/entities/results.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status, Tag}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Results { 7 | accounts: Vec, 8 | statuses: Vec, 9 | hashtags: Vec, 10 | } 11 | 12 | impl From for MegalodonEntities::Results { 13 | fn from(val: Results) -> MegalodonEntities::Results { 14 | MegalodonEntities::Results { 15 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 16 | statuses: val.statuses.into_iter().map(|i| i.into()).collect(), 17 | hashtags: val.hashtags.into_iter().map(|i| i.into()).collect(), 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/gotosocial/entities/role.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Role { 6 | name: String, 7 | } 8 | 9 | impl From for Role { 10 | fn from(value: MegalodonEntities::Role) -> Self { 11 | Self { name: value.name } 12 | } 13 | } 14 | 15 | impl From for MegalodonEntities::Role { 16 | fn from(val: Role) -> MegalodonEntities::Role { 17 | MegalodonEntities::Role { name: val.name } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/gotosocial/entities/scheduled_status.rs: -------------------------------------------------------------------------------- 1 | use super::{Attachment, StatusParams}; 2 | use crate::{entities as MegalodonEntities, megalodon}; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct ScheduledStatus { 8 | id: String, 9 | scheduled_at: DateTime, 10 | params: StatusParams, 11 | media_attachments: Vec, 12 | } 13 | 14 | impl From for MegalodonEntities::ScheduledStatus { 15 | fn from(val: ScheduledStatus) -> MegalodonEntities::ScheduledStatus { 16 | MegalodonEntities::ScheduledStatus { 17 | id: val.id, 18 | scheduled_at: val.scheduled_at, 19 | params: val.params.into(), 20 | media_attachments: Some( 21 | val.media_attachments 22 | .into_iter() 23 | .map(|i| i.into()) 24 | .collect(), 25 | ), 26 | } 27 | } 28 | } 29 | 30 | impl From for megalodon::PostStatusOutput { 31 | fn from(val: ScheduledStatus) -> megalodon::PostStatusOutput { 32 | megalodon::PostStatusOutput::ScheduledStatus(val.into()) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/gotosocial/entities/source.rs: -------------------------------------------------------------------------------- 1 | use super::Field; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Source { 7 | privacy: Option, 8 | sensitive: Option, 9 | language: Option, 10 | note: String, 11 | fields: Option>, 12 | } 13 | 14 | impl From for Source { 15 | fn from(item: MegalodonEntities::Source) -> Self { 16 | Self { 17 | privacy: item.privacy, 18 | sensitive: item.sensitive, 19 | language: item.language, 20 | note: item.note, 21 | fields: item 22 | .fields 23 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 24 | } 25 | } 26 | } 27 | 28 | impl From for MegalodonEntities::Source { 29 | fn from(val: Source) -> MegalodonEntities::Source { 30 | MegalodonEntities::Source { 31 | privacy: val.privacy, 32 | sensitive: val.sensitive, 33 | language: val.language, 34 | note: val.note, 35 | fields: val 36 | .fields 37 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/gotosocial/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Stats { 6 | user_count: u32, 7 | status_count: u64, 8 | domain_count: u32, 9 | } 10 | 11 | impl From for MegalodonEntities::Stats { 12 | fn from(val: Stats) -> MegalodonEntities::Stats { 13 | MegalodonEntities::Stats { 14 | user_count: val.user_count, 15 | status_count: val.status_count, 16 | domain_count: val.domain_count, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/gotosocial/entities/status_params.rs: -------------------------------------------------------------------------------- 1 | use super::StatusVisibility; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct StatusParams { 8 | text: String, 9 | in_reply_to_id: Option, 10 | media_ids: Option>, 11 | sensitive: Option, 12 | spoiler_text: Option, 13 | visibility: Option, 14 | scheduled_at: Option>, 15 | application_id: u32, 16 | } 17 | 18 | impl From for MegalodonEntities::StatusParams { 19 | fn from(val: StatusParams) -> MegalodonEntities::StatusParams { 20 | MegalodonEntities::StatusParams { 21 | text: val.text, 22 | in_reply_to_id: val.in_reply_to_id, 23 | media_ids: val.media_ids, 24 | sensitive: val.sensitive, 25 | spoiler_text: val.spoiler_text, 26 | visibility: val.visibility.map(|i| i.into()), 27 | scheduled_at: val.scheduled_at, 28 | application_id: Some(val.application_id), 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/gotosocial/entities/status_source.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 5 | pub struct StatusSource { 6 | // ID of the status in the database 7 | id: String, 8 | // The plain text used to compose the status 9 | text: String, 10 | // The plain text used to compose the status’s subject or content warning 11 | spoiler_text: String, 12 | } 13 | 14 | impl From for MegalodonEntities::StatusSource { 15 | fn from(val: StatusSource) -> Self { 16 | MegalodonEntities::StatusSource { 17 | id: val.id, 18 | text: val.text, 19 | spoiler_text: val.spoiler_text, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/gotosocial/entities/tag.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Tag { 6 | name: String, 7 | url: String, 8 | following: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Tag { 12 | fn from(val: Tag) -> MegalodonEntities::Tag { 13 | MegalodonEntities::Tag { 14 | name: val.name, 15 | url: val.url, 16 | history: [].to_vec(), 17 | following: val.following, 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/gotosocial/entities/token.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Token { 6 | access_token: String, 7 | token_type: String, 8 | scope: String, 9 | created_at: u64, 10 | } 11 | 12 | impl From for MegalodonEntities::Token { 13 | fn from(val: Token) -> MegalodonEntities::Token { 14 | MegalodonEntities::Token { 15 | access_token: val.access_token, 16 | token_type: val.token_type, 17 | scope: val.scope, 18 | created_at: val.created_at, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/gotosocial/entities/urls.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Deserialize, Debug, Clone)] 5 | pub struct URLs { 6 | streaming_api: String, 7 | } 8 | 9 | impl From for MegalodonEntities::URLs { 10 | fn from(val: URLs) -> MegalodonEntities::URLs { 11 | MegalodonEntities::URLs { 12 | streaming_api: val.streaming_api, 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/gotosocial/mod.rs: -------------------------------------------------------------------------------- 1 | //! Gotosocial related modules 2 | 3 | mod api_client; 4 | mod entities; 5 | /// Gotosocial API client. 6 | pub mod gotosocial; 7 | mod oauth; 8 | mod web_socket; 9 | 10 | pub use gotosocial::Gotosocial; 11 | -------------------------------------------------------------------------------- /src/gotosocial/oauth.rs: -------------------------------------------------------------------------------- 1 | use crate::oauth; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct AppDataFromServer { 6 | id: String, 7 | name: String, 8 | website: Option, 9 | redirect_uri: String, 10 | client_id: String, 11 | client_secret: String, 12 | } 13 | 14 | /// Obteined token data from server. 15 | #[derive(Debug, Deserialize, Clone)] 16 | pub struct TokenDataFromServer { 17 | access_token: String, 18 | token_type: String, 19 | scope: String, 20 | created_at: u64, 21 | } 22 | 23 | impl Into for AppDataFromServer { 24 | fn into(self) -> oauth::AppData { 25 | oauth::AppData::new( 26 | self.id, 27 | self.name, 28 | self.website, 29 | Some(self.redirect_uri), 30 | self.client_id, 31 | self.client_secret, 32 | ) 33 | } 34 | } 35 | 36 | impl Into for TokenDataFromServer { 37 | fn into(self) -> oauth::TokenData { 38 | oauth::TokenData::new( 39 | self.access_token, 40 | self.token_type, 41 | Some(self.scope), 42 | Some(self.created_at), 43 | None, 44 | None, 45 | ) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/mastodon/entities/activity.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Activity { 6 | week: String, 7 | statuses: String, 8 | logins: String, 9 | registrations: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Activity { 13 | fn from(val: Activity) -> Self { 14 | MegalodonEntities::Activity { 15 | week: val.week, 16 | statuses: val.statuses, 17 | logins: val.logins, 18 | registrations: val.registrations, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/mastodon/entities/application.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Application { 6 | name: String, 7 | website: Option, 8 | vapid_key: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Application { 12 | fn from(val: Application) -> Self { 13 | MegalodonEntities::Application { 14 | name: val.name, 15 | website: val.website, 16 | vapid_key: val.vapid_key, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/mastodon/entities/context.rs: -------------------------------------------------------------------------------- 1 | use super::Status; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Context { 7 | ancestors: Vec, 8 | descendants: Vec, 9 | } 10 | 11 | impl From for MegalodonEntities::Context { 12 | fn from(val: Context) -> Self { 13 | MegalodonEntities::Context { 14 | ancestors: val.ancestors.into_iter().map(|i| i.into()).collect(), 15 | descendants: val.descendants.into_iter().map(|i| i.into()).collect(), 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/mastodon/entities/conversation.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Conversation { 7 | id: String, 8 | accounts: Vec, 9 | last_status: Option, 10 | unread: bool, 11 | } 12 | 13 | impl From for MegalodonEntities::Conversation { 14 | fn from(val: Conversation) -> Self { 15 | MegalodonEntities::Conversation { 16 | id: val.id, 17 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 18 | last_status: val.last_status.map(|i| i.into()), 19 | unread: val.unread, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/mastodon/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Emoji { 6 | shortcode: String, 7 | static_url: String, 8 | url: String, 9 | visible_in_picker: bool, 10 | category: Option, 11 | } 12 | 13 | impl From for Emoji { 14 | fn from(item: MegalodonEntities::Emoji) -> Self { 15 | Self { 16 | shortcode: item.shortcode, 17 | static_url: item.static_url, 18 | url: item.url, 19 | visible_in_picker: item.visible_in_picker, 20 | category: item.category, 21 | } 22 | } 23 | } 24 | 25 | impl From for MegalodonEntities::Emoji { 26 | fn from(val: Emoji) -> Self { 27 | MegalodonEntities::Emoji { 28 | shortcode: val.shortcode, 29 | static_url: val.static_url, 30 | url: val.url, 31 | visible_in_picker: val.visible_in_picker, 32 | category: val.category, 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/mastodon/entities/featured_tag.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct FeaturedTag { 7 | id: String, 8 | name: String, 9 | statuses_count: u32, 10 | last_status_at: DateTime, 11 | } 12 | 13 | impl From for MegalodonEntities::FeaturedTag { 14 | fn from(val: FeaturedTag) -> Self { 15 | MegalodonEntities::FeaturedTag { 16 | id: val.id, 17 | name: val.name, 18 | statuses_count: val.statuses_count, 19 | last_status_at: val.last_status_at, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/mastodon/entities/field.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Field { 7 | name: String, 8 | value: String, 9 | verified_at: Option>, 10 | } 11 | 12 | impl From for Field { 13 | fn from(item: MegalodonEntities::Field) -> Self { 14 | Self { 15 | name: item.name, 16 | value: item.value, 17 | verified_at: item.verified_at, 18 | } 19 | } 20 | } 21 | 22 | impl From for MegalodonEntities::Field { 23 | fn from(val: Field) -> Self { 24 | MegalodonEntities::Field { 25 | name: val.name, 26 | value: val.value, 27 | verified_at: val.verified_at, 28 | verified: None, 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/mastodon/entities/filter.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Filter { 7 | id: String, 8 | phrase: String, 9 | context: Vec, 10 | expires_at: Option>, 11 | irreversible: bool, 12 | whole_word: bool, 13 | } 14 | 15 | #[derive(Debug, Clone, Serialize, Deserialize)] 16 | #[serde(rename_all = "lowercase")] 17 | pub enum FilterContext { 18 | Home, 19 | Notifications, 20 | Public, 21 | Thread, 22 | } 23 | 24 | impl From for MegalodonEntities::filter::FilterContext { 25 | fn from(val: FilterContext) -> Self { 26 | match val { 27 | FilterContext::Home => MegalodonEntities::filter::FilterContext::Home, 28 | FilterContext::Notifications => MegalodonEntities::filter::FilterContext::Notifications, 29 | FilterContext::Public => MegalodonEntities::filter::FilterContext::Public, 30 | FilterContext::Thread => MegalodonEntities::filter::FilterContext::Thread, 31 | } 32 | } 33 | } 34 | 35 | impl From for MegalodonEntities::Filter { 36 | fn from(val: Filter) -> Self { 37 | MegalodonEntities::Filter { 38 | id: val.id, 39 | phrase: val.phrase, 40 | context: val.context.into_iter().map(|i| i.into()).collect(), 41 | expires_at: val.expires_at, 42 | irreversible: val.irreversible, 43 | whole_word: val.whole_word, 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/mastodon/entities/history.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct History { 6 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 7 | day: u64, 8 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 9 | uses: usize, 10 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 11 | accounts: usize, 12 | } 13 | 14 | impl From for MegalodonEntities::History { 15 | fn from(val: History) -> Self { 16 | MegalodonEntities::History { 17 | day: val.day, 18 | uses: val.uses, 19 | accounts: val.accounts, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/mastodon/entities/identity_proof.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct IdentityProof { 7 | provider: String, 8 | provider_username: String, 9 | updated_at: DateTime, 10 | proof_url: String, 11 | profile_url: String, 12 | } 13 | 14 | impl From for MegalodonEntities::IdentityProof { 15 | fn from(val: IdentityProof) -> Self { 16 | MegalodonEntities::IdentityProof { 17 | provider: val.provider, 18 | provider_username: val.provider_username, 19 | updated_at: val.updated_at, 20 | proof_url: val.proof_url, 21 | profile_url: val.profile_url, 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/mastodon/entities/list.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct List { 6 | id: String, 7 | title: String, 8 | replies_policy: RepliesPolicy, 9 | } 10 | 11 | #[derive(Debug, Deserialize, Clone)] 12 | #[serde(rename_all = "snake_case")] 13 | pub enum RepliesPolicy { 14 | Followed, 15 | List, 16 | None, 17 | } 18 | 19 | impl From for MegalodonEntities::list::RepliesPolicy { 20 | fn from(val: RepliesPolicy) -> Self { 21 | match val { 22 | RepliesPolicy::Followed => MegalodonEntities::list::RepliesPolicy::Followed, 23 | RepliesPolicy::List => MegalodonEntities::list::RepliesPolicy::List, 24 | RepliesPolicy::None => MegalodonEntities::list::RepliesPolicy::None, 25 | } 26 | } 27 | } 28 | 29 | impl From for MegalodonEntities::List { 30 | fn from(val: List) -> Self { 31 | MegalodonEntities::List { 32 | id: val.id, 33 | title: val.title, 34 | replies_policy: Some(val.replies_policy.into()), 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/mastodon/entities/marker.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Marker { 7 | home: InnerMarker, 8 | notifications: InnerMarker, 9 | } 10 | 11 | #[derive(Debug, Deserialize, Clone)] 12 | struct InnerMarker { 13 | last_read_id: String, 14 | version: u32, 15 | updated_at: DateTime, 16 | } 17 | 18 | impl From for MegalodonEntities::Marker { 19 | fn from(val: Marker) -> Self { 20 | MegalodonEntities::Marker { 21 | home: Some(val.home.into()), 22 | notifications: Some(val.notifications.into()), 23 | } 24 | } 25 | } 26 | 27 | impl From for MegalodonEntities::marker::InnerMarker { 28 | fn from(val: InnerMarker) -> Self { 29 | MegalodonEntities::marker::InnerMarker { 30 | last_read_id: val.last_read_id, 31 | version: val.version, 32 | updated_at: val.updated_at, 33 | unread_count: None, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/mastodon/entities/mention.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Mention { 6 | id: String, 7 | username: String, 8 | url: String, 9 | acct: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Mention { 13 | fn from(val: Mention) -> Self { 14 | MegalodonEntities::Mention { 15 | id: val.id, 16 | username: val.username, 17 | url: val.url, 18 | acct: val.acct, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/mastodon/entities/poll.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, PollOption}; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct Poll { 8 | id: String, 9 | expires_at: Option>, 10 | expired: bool, 11 | multiple: bool, 12 | votes_count: u32, 13 | voters_count: Option, 14 | options: Vec, 15 | voted: Option, 16 | emojis: Vec, 17 | } 18 | 19 | impl From for MegalodonEntities::Poll { 20 | fn from(val: Poll) -> Self { 21 | MegalodonEntities::Poll { 22 | id: val.id, 23 | expires_at: val.expires_at, 24 | expired: val.expired, 25 | multiple: val.multiple, 26 | votes_count: val.votes_count, 27 | voters_count: val.voters_count, 28 | options: val.options.into_iter().map(|i| i.into()).collect(), 29 | voted: val.voted, 30 | emojis: val.emojis.into_iter().map(|i| i.into()).collect(), 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/mastodon/entities/poll_option.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PollOption { 6 | title: String, 7 | votes_count: Option, 8 | } 9 | 10 | impl From for MegalodonEntities::PollOption { 11 | fn from(val: PollOption) -> Self { 12 | MegalodonEntities::PollOption { 13 | title: val.title, 14 | votes_count: val.votes_count, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/mastodon/entities/push_subscription.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PushSubscription { 6 | id: String, 7 | endpoint: String, 8 | server_key: String, 9 | alerts: Alerts, 10 | } 11 | 12 | #[derive(Debug, Deserialize, Clone)] 13 | struct Alerts { 14 | follow: bool, 15 | favourite: bool, 16 | mention: bool, 17 | reblog: bool, 18 | poll: bool, 19 | } 20 | 21 | impl From for MegalodonEntities::PushSubscription { 22 | fn from(val: PushSubscription) -> Self { 23 | MegalodonEntities::PushSubscription { 24 | id: val.id, 25 | endpoint: val.endpoint, 26 | server_key: val.server_key, 27 | alerts: val.alerts.into(), 28 | } 29 | } 30 | } 31 | 32 | impl From for MegalodonEntities::push_subscription::Alerts { 33 | fn from(val: Alerts) -> Self { 34 | MegalodonEntities::push_subscription::Alerts { 35 | follow: val.follow, 36 | favourite: val.favourite, 37 | mention: val.mention, 38 | reblog: val.reblog, 39 | poll: val.poll, 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/mastodon/entities/relationship.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Relationship { 6 | id: String, 7 | following: bool, 8 | followed_by: bool, 9 | blocking: bool, 10 | blocked_by: bool, 11 | muting: bool, 12 | muting_notifications: bool, 13 | requested: bool, 14 | domain_blocking: bool, 15 | showing_reblogs: bool, 16 | endorsed: bool, 17 | notifying: bool, 18 | note: String, 19 | #[allow(dead_code)] 20 | languages: Option, 21 | } 22 | 23 | impl From for MegalodonEntities::Relationship { 24 | fn from(val: Relationship) -> Self { 25 | MegalodonEntities::Relationship { 26 | id: val.id, 27 | following: val.following, 28 | followed_by: val.followed_by, 29 | blocking: val.blocking, 30 | blocked_by: val.blocked_by, 31 | muting: val.muting, 32 | muting_notifications: val.muting_notifications, 33 | requested: val.requested, 34 | domain_blocking: val.domain_blocking, 35 | showing_reblogs: val.showing_reblogs, 36 | endorsed: val.endorsed, 37 | notifying: val.notifying, 38 | note: Some(val.note), 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/mastodon/entities/results.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status, Tag}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Results { 7 | accounts: Vec, 8 | statuses: Vec, 9 | hashtags: Vec, 10 | } 11 | 12 | impl From for MegalodonEntities::Results { 13 | fn from(val: Results) -> Self { 14 | MegalodonEntities::Results { 15 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 16 | statuses: val.statuses.into_iter().map(|i| i.into()).collect(), 17 | hashtags: val.hashtags.into_iter().map(|i| i.into()).collect(), 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/mastodon/entities/role.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Role { 6 | name: String, 7 | } 8 | 9 | impl From for Role { 10 | fn from(value: MegalodonEntities::Role) -> Self { 11 | Self { name: value.name } 12 | } 13 | } 14 | 15 | impl From for MegalodonEntities::Role { 16 | fn from(val: Role) -> Self { 17 | MegalodonEntities::Role { name: val.name } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/mastodon/entities/scheduled_status.rs: -------------------------------------------------------------------------------- 1 | use super::{Attachment, StatusParams}; 2 | use crate::{entities as MegalodonEntities, megalodon}; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct ScheduledStatus { 8 | id: String, 9 | scheduled_at: DateTime, 10 | params: StatusParams, 11 | media_attachments: Vec, 12 | } 13 | 14 | impl From for MegalodonEntities::ScheduledStatus { 15 | fn from(val: ScheduledStatus) -> Self { 16 | MegalodonEntities::ScheduledStatus { 17 | id: val.id, 18 | scheduled_at: val.scheduled_at, 19 | params: val.params.into(), 20 | media_attachments: Some( 21 | val.media_attachments 22 | .into_iter() 23 | .map(|i| i.into()) 24 | .collect(), 25 | ), 26 | } 27 | } 28 | } 29 | 30 | impl From for megalodon::PostStatusOutput { 31 | fn from(val: ScheduledStatus) -> Self { 32 | megalodon::PostStatusOutput::ScheduledStatus(val.into()) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/mastodon/entities/source.rs: -------------------------------------------------------------------------------- 1 | use super::Field; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Source { 7 | privacy: Option, 8 | sensitive: Option, 9 | language: Option, 10 | note: String, 11 | fields: Option>, 12 | } 13 | 14 | impl From for Source { 15 | fn from(item: MegalodonEntities::Source) -> Self { 16 | Self { 17 | privacy: item.privacy, 18 | sensitive: item.sensitive, 19 | language: item.language, 20 | note: item.note, 21 | fields: item 22 | .fields 23 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 24 | } 25 | } 26 | } 27 | 28 | impl From for MegalodonEntities::Source { 29 | fn from(val: Source) -> Self { 30 | MegalodonEntities::Source { 31 | privacy: val.privacy, 32 | sensitive: val.sensitive, 33 | language: val.language, 34 | note: val.note, 35 | fields: val 36 | .fields 37 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/mastodon/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Stats { 6 | user_count: u32, 7 | status_count: u64, 8 | domain_count: u32, 9 | } 10 | 11 | impl From for MegalodonEntities::Stats { 12 | fn from(val: Stats) -> Self { 13 | MegalodonEntities::Stats { 14 | user_count: val.user_count, 15 | status_count: val.status_count, 16 | domain_count: val.domain_count, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/mastodon/entities/status_params.rs: -------------------------------------------------------------------------------- 1 | use super::StatusVisibility; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct StatusParams { 8 | text: String, 9 | in_reply_to_id: Option, 10 | media_ids: Option>, 11 | sensitive: Option, 12 | spoiler_text: Option, 13 | visibility: Option, 14 | scheduled_at: Option>, 15 | application_id: u32, 16 | } 17 | 18 | impl From for MegalodonEntities::StatusParams { 19 | fn from(val: StatusParams) -> Self { 20 | MegalodonEntities::StatusParams { 21 | text: val.text, 22 | in_reply_to_id: val.in_reply_to_id, 23 | media_ids: val.media_ids, 24 | sensitive: val.sensitive, 25 | spoiler_text: val.spoiler_text, 26 | visibility: val.visibility.map(|i| i.into()), 27 | scheduled_at: val.scheduled_at, 28 | application_id: Some(val.application_id), 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/mastodon/entities/status_source.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 5 | pub struct StatusSource { 6 | // ID of the status in the database 7 | id: String, 8 | // The plain text used to compose the status 9 | text: String, 10 | // The plain text used to compose the status’s subject or content warning 11 | spoiler_text: String, 12 | } 13 | 14 | impl From for MegalodonEntities::StatusSource { 15 | fn from(val: StatusSource) -> Self { 16 | MegalodonEntities::StatusSource { 17 | id: val.id, 18 | text: val.text, 19 | spoiler_text: val.spoiler_text, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/mastodon/entities/tag.rs: -------------------------------------------------------------------------------- 1 | use super::History; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Tag { 7 | name: String, 8 | url: String, 9 | history: Vec, 10 | following: Option, 11 | } 12 | 13 | impl From for MegalodonEntities::Tag { 14 | fn from(val: Tag) -> Self { 15 | MegalodonEntities::Tag { 16 | name: val.name, 17 | url: val.url, 18 | history: val.history.into_iter().map(|j| j.into()).collect(), 19 | following: val.following, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/mastodon/entities/token.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Token { 6 | access_token: String, 7 | token_type: String, 8 | scope: String, 9 | created_at: u64, 10 | } 11 | 12 | impl From for MegalodonEntities::Token { 13 | fn from(val: Token) -> Self { 14 | MegalodonEntities::Token { 15 | access_token: val.access_token, 16 | token_type: val.token_type, 17 | scope: val.scope, 18 | created_at: val.created_at, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/mastodon/entities/urls.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Deserialize, Debug, Clone)] 5 | pub struct URLs { 6 | streaming_api: String, 7 | } 8 | 9 | impl From for MegalodonEntities::URLs { 10 | fn from(val: URLs) -> Self { 11 | MegalodonEntities::URLs { 12 | streaming_api: val.streaming_api, 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/mastodon/mod.rs: -------------------------------------------------------------------------------- 1 | //! Mastodon related modules 2 | 3 | mod api_client; 4 | mod entities; 5 | /// Mastodon API client. 6 | pub mod mastodon; 7 | mod oauth; 8 | mod web_socket; 9 | 10 | pub use mastodon::Mastodon; 11 | -------------------------------------------------------------------------------- /src/mastodon/oauth.rs: -------------------------------------------------------------------------------- 1 | use crate::oauth; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct AppDataFromServer { 6 | id: String, 7 | name: String, 8 | website: Option, 9 | redirect_uri: String, 10 | client_id: String, 11 | client_secret: String, 12 | } 13 | 14 | /// Obteined token data from server. 15 | #[derive(Debug, Deserialize, Clone)] 16 | pub struct TokenDataFromServer { 17 | access_token: String, 18 | token_type: String, 19 | scope: String, 20 | created_at: u64, 21 | } 22 | 23 | impl From for oauth::AppData { 24 | fn from(val: AppDataFromServer) -> Self { 25 | oauth::AppData::new( 26 | val.id, 27 | val.name, 28 | val.website, 29 | Some(val.redirect_uri), 30 | val.client_id, 31 | val.client_secret, 32 | ) 33 | } 34 | } 35 | 36 | impl From for oauth::TokenData { 37 | fn from(val: TokenDataFromServer) -> Self { 38 | oauth::TokenData::new( 39 | val.access_token, 40 | val.token_type, 41 | Some(val.scope), 42 | Some(val.created_at), 43 | None, 44 | None, 45 | ) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/pixelfed/entities/application.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Application { 6 | name: String, 7 | website: Option, 8 | vapid_key: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Application { 12 | fn from(val: Application) -> Self { 13 | MegalodonEntities::Application { 14 | name: val.name, 15 | website: val.website, 16 | vapid_key: val.vapid_key, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/pixelfed/entities/context.rs: -------------------------------------------------------------------------------- 1 | use super::Status; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Context { 7 | ancestors: Vec, 8 | descendants: Vec, 9 | } 10 | 11 | impl From for MegalodonEntities::Context { 12 | fn from(val: Context) -> Self { 13 | MegalodonEntities::Context { 14 | ancestors: val.ancestors.into_iter().map(|i| i.into()).collect(), 15 | descendants: val.descendants.into_iter().map(|i| i.into()).collect(), 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/pixelfed/entities/conversation.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Conversation { 7 | id: String, 8 | accounts: Vec, 9 | last_status: Option, 10 | unread: bool, 11 | } 12 | 13 | impl From for MegalodonEntities::Conversation { 14 | fn from(val: Conversation) -> Self { 15 | MegalodonEntities::Conversation { 16 | id: val.id, 17 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 18 | last_status: val.last_status.map(|i| i.into()), 19 | unread: val.unread, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pixelfed/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Emoji { 6 | shortcode: String, 7 | static_url: String, 8 | url: String, 9 | visible_in_picker: bool, 10 | category: Option, 11 | } 12 | 13 | impl From for Emoji { 14 | fn from(item: MegalodonEntities::Emoji) -> Self { 15 | Self { 16 | shortcode: item.shortcode, 17 | static_url: item.static_url, 18 | url: item.url, 19 | visible_in_picker: item.visible_in_picker, 20 | category: item.category, 21 | } 22 | } 23 | } 24 | 25 | impl From for MegalodonEntities::Emoji { 26 | fn from(val: Emoji) -> Self { 27 | MegalodonEntities::Emoji { 28 | shortcode: val.shortcode, 29 | static_url: val.static_url, 30 | url: val.url, 31 | visible_in_picker: val.visible_in_picker, 32 | category: val.category, 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/pixelfed/entities/field.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Field { 7 | name: String, 8 | value: String, 9 | verified_at: Option>, 10 | } 11 | 12 | impl From for Field { 13 | fn from(item: MegalodonEntities::Field) -> Self { 14 | Self { 15 | name: item.name, 16 | value: item.value, 17 | verified_at: item.verified_at, 18 | } 19 | } 20 | } 21 | 22 | impl From for MegalodonEntities::Field { 23 | fn from(val: Field) -> Self { 24 | MegalodonEntities::Field { 25 | name: val.name, 26 | value: val.value, 27 | verified_at: val.verified_at, 28 | verified: None, 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/pixelfed/entities/filter.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Filter { 7 | id: String, 8 | phrase: String, 9 | context: Vec, 10 | expires_at: Option>, 11 | irreversible: bool, 12 | whole_word: bool, 13 | } 14 | 15 | #[derive(Debug, Clone, Serialize, Deserialize)] 16 | #[serde(rename_all = "lowercase")] 17 | pub enum FilterContext { 18 | Home, 19 | Notifications, 20 | Public, 21 | Thread, 22 | } 23 | 24 | impl From for MegalodonEntities::filter::FilterContext { 25 | fn from(val: FilterContext) -> Self { 26 | match val { 27 | FilterContext::Home => MegalodonEntities::filter::FilterContext::Home, 28 | FilterContext::Notifications => MegalodonEntities::filter::FilterContext::Notifications, 29 | FilterContext::Public => MegalodonEntities::filter::FilterContext::Public, 30 | FilterContext::Thread => MegalodonEntities::filter::FilterContext::Thread, 31 | } 32 | } 33 | } 34 | 35 | impl From for MegalodonEntities::Filter { 36 | fn from(val: Filter) -> Self { 37 | MegalodonEntities::Filter { 38 | id: val.id, 39 | phrase: val.phrase, 40 | context: val.context.into_iter().map(|i| i.into()).collect(), 41 | expires_at: val.expires_at, 42 | irreversible: val.irreversible, 43 | whole_word: val.whole_word, 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/pixelfed/entities/history.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct History { 6 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 7 | day: u64, 8 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 9 | uses: usize, 10 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 11 | accounts: usize, 12 | } 13 | 14 | impl From for MegalodonEntities::History { 15 | fn from(val: History) -> Self { 16 | MegalodonEntities::History { 17 | day: val.day, 18 | uses: val.uses, 19 | accounts: val.accounts, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pixelfed/entities/marker.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Marker { 7 | home: InnerMarker, 8 | notifications: InnerMarker, 9 | } 10 | 11 | #[derive(Debug, Deserialize, Clone)] 12 | struct InnerMarker { 13 | last_read_id: String, 14 | version: u32, 15 | updated_at: DateTime, 16 | } 17 | 18 | impl From for MegalodonEntities::Marker { 19 | fn from(val: Marker) -> Self { 20 | MegalodonEntities::Marker { 21 | home: Some(val.home.into()), 22 | notifications: Some(val.notifications.into()), 23 | } 24 | } 25 | } 26 | 27 | impl From for MegalodonEntities::marker::InnerMarker { 28 | fn from(val: InnerMarker) -> Self { 29 | MegalodonEntities::marker::InnerMarker { 30 | last_read_id: val.last_read_id, 31 | version: val.version, 32 | updated_at: val.updated_at, 33 | unread_count: None, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/pixelfed/entities/mention.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Mention { 6 | id: String, 7 | username: String, 8 | url: String, 9 | acct: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Mention { 13 | fn from(val: Mention) -> Self { 14 | MegalodonEntities::Mention { 15 | id: val.id, 16 | username: val.username, 17 | url: val.url, 18 | acct: val.acct, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/pixelfed/entities/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod account; 2 | pub mod announcement; 3 | pub mod application; 4 | pub mod attachment; 5 | pub mod context; 6 | pub mod conversation; 7 | pub mod emoji; 8 | pub mod field; 9 | pub mod filter; 10 | pub mod history; 11 | pub mod instance; 12 | pub mod marker; 13 | pub mod mention; 14 | pub mod notification; 15 | pub mod poll; 16 | pub mod poll_option; 17 | pub mod preferences; 18 | pub mod relationship; 19 | pub mod report; 20 | pub mod results; 21 | pub mod scheduled_status; 22 | pub mod source; 23 | pub mod stats; 24 | pub mod status; 25 | pub mod status_params; 26 | pub mod tag; 27 | pub mod token; 28 | 29 | pub use account::Account; 30 | pub use announcement::Announcement; 31 | pub use application::Application; 32 | pub use attachment::Attachment; 33 | pub use context::Context; 34 | pub use conversation::Conversation; 35 | pub use emoji::Emoji; 36 | pub use field::Field; 37 | pub use filter::Filter; 38 | pub use history::History; 39 | pub use instance::Instance; 40 | pub use marker::Marker; 41 | pub use mention::Mention; 42 | pub use notification::Notification; 43 | pub use poll::Poll; 44 | pub use poll_option::PollOption; 45 | pub use preferences::Preferences; 46 | pub use relationship::Relationship; 47 | pub use report::Report; 48 | pub use results::Results; 49 | pub use scheduled_status::ScheduledStatus; 50 | pub use source::Source; 51 | pub use stats::Stats; 52 | pub use status::{Status, StatusVisibility}; 53 | pub use status_params::StatusParams; 54 | pub use tag::Tag; 55 | pub use token::Token; 56 | -------------------------------------------------------------------------------- /src/pixelfed/entities/poll.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, PollOption}; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct Poll { 8 | id: String, 9 | expires_at: Option>, 10 | expired: bool, 11 | multiple: bool, 12 | votes_count: u32, 13 | voters_count: Option, 14 | options: Vec, 15 | voted: Option, 16 | emojis: Vec, 17 | } 18 | 19 | impl From for MegalodonEntities::Poll { 20 | fn from(val: Poll) -> Self { 21 | MegalodonEntities::Poll { 22 | id: val.id, 23 | expires_at: val.expires_at, 24 | expired: val.expired, 25 | multiple: val.multiple, 26 | votes_count: val.votes_count, 27 | voters_count: val.voters_count, 28 | options: val.options.into_iter().map(|i| i.into()).collect(), 29 | voted: val.voted, 30 | emojis: val.emojis.into_iter().map(|i| i.into()).collect(), 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/pixelfed/entities/poll_option.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PollOption { 6 | title: String, 7 | votes_count: Option, 8 | } 9 | 10 | impl From for MegalodonEntities::PollOption { 11 | fn from(val: PollOption) -> Self { 12 | MegalodonEntities::PollOption { 13 | title: val.title, 14 | votes_count: val.votes_count, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/pixelfed/entities/relationship.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Relationship { 6 | id: String, 7 | following: bool, 8 | followed_by: bool, 9 | blocking: bool, 10 | blocked_by: bool, 11 | muting: bool, 12 | muting_notifications: bool, 13 | requested: bool, 14 | domain_blocking: bool, 15 | showing_reblogs: bool, 16 | endorsed: bool, 17 | notifying: bool, 18 | note: String, 19 | #[allow(dead_code)] 20 | languages: Option, 21 | } 22 | 23 | impl From for MegalodonEntities::Relationship { 24 | fn from(val: Relationship) -> Self { 25 | MegalodonEntities::Relationship { 26 | id: val.id, 27 | following: val.following, 28 | followed_by: val.followed_by, 29 | blocking: val.blocking, 30 | blocked_by: val.blocked_by, 31 | muting: val.muting, 32 | muting_notifications: val.muting_notifications, 33 | requested: val.requested, 34 | domain_blocking: val.domain_blocking, 35 | showing_reblogs: val.showing_reblogs, 36 | endorsed: val.endorsed, 37 | notifying: val.notifying, 38 | note: Some(val.note), 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/pixelfed/entities/results.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status, Tag}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Results { 7 | accounts: Vec, 8 | statuses: Vec, 9 | hashtags: Vec, 10 | } 11 | 12 | impl From for MegalodonEntities::Results { 13 | fn from(val: Results) -> Self { 14 | MegalodonEntities::Results { 15 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 16 | statuses: val.statuses.into_iter().map(|i| i.into()).collect(), 17 | hashtags: val.hashtags.into_iter().map(|i| i.into()).collect(), 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/pixelfed/entities/scheduled_status.rs: -------------------------------------------------------------------------------- 1 | use super::{Attachment, StatusParams}; 2 | use crate::{entities as MegalodonEntities, megalodon}; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct ScheduledStatus { 8 | id: String, 9 | scheduled_at: DateTime, 10 | params: StatusParams, 11 | media_attachments: Vec, 12 | } 13 | 14 | impl From for MegalodonEntities::ScheduledStatus { 15 | fn from(val: ScheduledStatus) -> Self { 16 | MegalodonEntities::ScheduledStatus { 17 | id: val.id, 18 | scheduled_at: val.scheduled_at, 19 | params: val.params.into(), 20 | media_attachments: Some( 21 | val.media_attachments 22 | .into_iter() 23 | .map(|i| i.into()) 24 | .collect(), 25 | ), 26 | } 27 | } 28 | } 29 | 30 | impl From for megalodon::PostStatusOutput { 31 | fn from(val: ScheduledStatus) -> Self { 32 | megalodon::PostStatusOutput::ScheduledStatus(val.into()) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/pixelfed/entities/source.rs: -------------------------------------------------------------------------------- 1 | use super::Field; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Source { 7 | privacy: Option, 8 | sensitive: Option, 9 | language: Option, 10 | note: String, 11 | fields: Option>, 12 | } 13 | 14 | impl From for Source { 15 | fn from(item: MegalodonEntities::Source) -> Self { 16 | Self { 17 | privacy: item.privacy, 18 | sensitive: item.sensitive, 19 | language: item.language, 20 | note: item.note, 21 | fields: item 22 | .fields 23 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 24 | } 25 | } 26 | } 27 | 28 | impl From for MegalodonEntities::Source { 29 | fn from(val: Source) -> Self { 30 | MegalodonEntities::Source { 31 | privacy: val.privacy, 32 | sensitive: val.sensitive, 33 | language: val.language, 34 | note: val.note, 35 | fields: val 36 | .fields 37 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/pixelfed/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Stats { 6 | user_count: u32, 7 | status_count: u64, 8 | domain_count: u32, 9 | } 10 | 11 | impl From for MegalodonEntities::Stats { 12 | fn from(val: Stats) -> Self { 13 | MegalodonEntities::Stats { 14 | user_count: val.user_count, 15 | status_count: val.status_count, 16 | domain_count: val.domain_count, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/pixelfed/entities/status_params.rs: -------------------------------------------------------------------------------- 1 | use super::StatusVisibility; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct StatusParams { 8 | text: String, 9 | in_reply_to_id: Option, 10 | media_ids: Option>, 11 | sensitive: Option, 12 | spoiler_text: Option, 13 | visibility: Option, 14 | scheduled_at: Option>, 15 | application_id: u32, 16 | } 17 | 18 | impl From for MegalodonEntities::StatusParams { 19 | fn from(val: StatusParams) -> Self { 20 | MegalodonEntities::StatusParams { 21 | text: val.text, 22 | in_reply_to_id: val.in_reply_to_id, 23 | media_ids: val.media_ids, 24 | sensitive: val.sensitive, 25 | spoiler_text: val.spoiler_text, 26 | visibility: val.visibility.map(|i| i.into()), 27 | scheduled_at: val.scheduled_at, 28 | application_id: Some(val.application_id), 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/pixelfed/entities/tag.rs: -------------------------------------------------------------------------------- 1 | use super::History; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Tag { 7 | name: String, 8 | url: String, 9 | history: Vec, 10 | following: Option, 11 | } 12 | 13 | impl From for MegalodonEntities::Tag { 14 | fn from(val: Tag) -> Self { 15 | MegalodonEntities::Tag { 16 | name: val.name, 17 | url: val.url, 18 | history: val.history.into_iter().map(|j| j.into()).collect(), 19 | following: val.following, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pixelfed/entities/token.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Token { 6 | access_token: String, 7 | token_type: String, 8 | scope: String, 9 | created_at: u64, 10 | } 11 | 12 | impl From for MegalodonEntities::Token { 13 | fn from(val: Token) -> Self { 14 | MegalodonEntities::Token { 15 | access_token: val.access_token, 16 | token_type: val.token_type, 17 | scope: val.scope, 18 | created_at: val.created_at, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/pixelfed/mod.rs: -------------------------------------------------------------------------------- 1 | //! Pixelfed related modules 2 | 3 | mod api_client; 4 | mod entities; 5 | mod oauth; 6 | /// Pixelfed API client. 7 | pub mod pixelfed; 8 | mod web_socket; 9 | 10 | pub use pixelfed::Pixelfed; 11 | -------------------------------------------------------------------------------- /src/pixelfed/oauth.rs: -------------------------------------------------------------------------------- 1 | use crate::oauth; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct AppDataFromServer { 6 | id: String, 7 | name: String, 8 | website: Option, 9 | redirect_uri: String, 10 | client_id: String, 11 | client_secret: String, 12 | } 13 | 14 | /// Obteined token data from server. 15 | #[derive(Debug, Deserialize, Clone)] 16 | pub struct TokenDataFromServer { 17 | access_token: String, 18 | refresh_token: String, 19 | token_type: String, 20 | expires_in: u64, 21 | created_at: u64, 22 | } 23 | 24 | impl From for oauth::AppData { 25 | fn from(val: AppDataFromServer) -> Self { 26 | oauth::AppData::new( 27 | val.id, 28 | val.name, 29 | val.website, 30 | Some(val.redirect_uri), 31 | val.client_id, 32 | val.client_secret, 33 | ) 34 | } 35 | } 36 | 37 | impl From for oauth::TokenData { 38 | fn from(val: TokenDataFromServer) -> Self { 39 | oauth::TokenData::new( 40 | val.access_token, 41 | val.token_type, 42 | None, 43 | Some(val.created_at), 44 | Some(val.expires_in), 45 | Some(val.refresh_token), 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/pixelfed/web_socket.rs: -------------------------------------------------------------------------------- 1 | use async_trait::async_trait; 2 | use std::future::Future; 3 | use std::pin::Pin; 4 | 5 | use crate::{streaming::Message, Streaming}; 6 | 7 | #[derive(Debug, Clone)] 8 | pub struct WebSocket {} 9 | 10 | impl WebSocket { 11 | pub fn new() -> Self { 12 | Self {} 13 | } 14 | } 15 | 16 | #[async_trait] 17 | impl Streaming for WebSocket { 18 | async fn listen( 19 | &self, 20 | _callback: Box< 21 | dyn Fn(Message) -> Pin + Send>> 22 | + Send 23 | + Sync 24 | + 'async_trait, 25 | >, 26 | ) { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/pleroma/entities/activity.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Activity { 6 | week: String, 7 | statuses: String, 8 | logins: String, 9 | registrations: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Activity { 13 | fn from(val: Activity) -> Self { 14 | MegalodonEntities::Activity { 15 | week: val.week, 16 | statuses: val.statuses, 17 | logins: val.logins, 18 | registrations: val.registrations, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/pleroma/entities/application.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Application { 6 | name: String, 7 | website: Option, 8 | vapid_key: Option, 9 | } 10 | 11 | impl From for MegalodonEntities::Application { 12 | fn from(val: Application) -> Self { 13 | MegalodonEntities::Application { 14 | name: val.name, 15 | website: val.website, 16 | vapid_key: val.vapid_key, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/pleroma/entities/context.rs: -------------------------------------------------------------------------------- 1 | use super::Status; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Context { 7 | ancestors: Vec, 8 | descendants: Vec, 9 | } 10 | 11 | impl From for MegalodonEntities::Context { 12 | fn from(val: Context) -> Self { 13 | MegalodonEntities::Context { 14 | ancestors: val.ancestors.into_iter().map(|i| i.into()).collect(), 15 | descendants: val.descendants.into_iter().map(|i| i.into()).collect(), 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/pleroma/entities/conversation.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Conversation { 7 | id: String, 8 | accounts: Vec, 9 | last_status: Option, 10 | unread: bool, 11 | } 12 | 13 | impl From for MegalodonEntities::Conversation { 14 | fn from(val: Conversation) -> Self { 15 | MegalodonEntities::Conversation { 16 | id: val.id, 17 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 18 | last_status: val.last_status.map(|i| i.into()), 19 | unread: val.unread, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pleroma/entities/emoji.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Emoji { 6 | shortcode: String, 7 | static_url: String, 8 | url: String, 9 | visible_in_picker: bool, 10 | } 11 | 12 | impl From for Emoji { 13 | fn from(item: MegalodonEntities::Emoji) -> Self { 14 | Self { 15 | shortcode: item.shortcode, 16 | static_url: item.static_url, 17 | url: item.url, 18 | visible_in_picker: item.visible_in_picker, 19 | } 20 | } 21 | } 22 | 23 | impl From for MegalodonEntities::Emoji { 24 | fn from(val: Emoji) -> Self { 25 | MegalodonEntities::Emoji { 26 | shortcode: val.shortcode, 27 | static_url: val.static_url, 28 | url: val.url, 29 | visible_in_picker: val.visible_in_picker, 30 | category: None, 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/pleroma/entities/featured_tag.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct FeaturedTag { 7 | id: String, 8 | name: String, 9 | statuses_count: u32, 10 | last_status_at: DateTime, 11 | } 12 | 13 | impl From for MegalodonEntities::FeaturedTag { 14 | fn from(val: FeaturedTag) -> Self { 15 | MegalodonEntities::FeaturedTag { 16 | id: val.id, 17 | name: val.name, 18 | statuses_count: val.statuses_count, 19 | last_status_at: val.last_status_at, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pleroma/entities/field.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Field { 7 | name: String, 8 | value: String, 9 | verified_at: Option>, 10 | } 11 | 12 | impl From for Field { 13 | fn from(item: MegalodonEntities::Field) -> Self { 14 | Self { 15 | name: item.name, 16 | value: item.value, 17 | verified_at: item.verified_at, 18 | } 19 | } 20 | } 21 | 22 | impl From for MegalodonEntities::Field { 23 | fn from(val: Field) -> Self { 24 | MegalodonEntities::Field { 25 | name: val.name, 26 | value: val.value, 27 | verified_at: val.verified_at, 28 | verified: None, 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/pleroma/entities/filter.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Filter { 7 | id: String, 8 | phrase: String, 9 | context: Vec, 10 | expires_at: Option>, 11 | irreversible: bool, 12 | whole_word: bool, 13 | } 14 | 15 | #[derive(Debug, Clone, Serialize, Deserialize)] 16 | #[serde(rename_all = "lowercase")] 17 | pub enum FilterContext { 18 | Home, 19 | Notifications, 20 | Public, 21 | Thread, 22 | } 23 | 24 | impl From for MegalodonEntities::filter::FilterContext { 25 | fn from(val: FilterContext) -> Self { 26 | match val { 27 | FilterContext::Home => MegalodonEntities::filter::FilterContext::Home, 28 | FilterContext::Notifications => MegalodonEntities::filter::FilterContext::Notifications, 29 | FilterContext::Public => MegalodonEntities::filter::FilterContext::Public, 30 | FilterContext::Thread => MegalodonEntities::filter::FilterContext::Thread, 31 | } 32 | } 33 | } 34 | 35 | impl From for MegalodonEntities::Filter { 36 | fn from(val: Filter) -> Self { 37 | MegalodonEntities::Filter { 38 | id: val.id, 39 | phrase: val.phrase, 40 | context: val.context.into_iter().map(|i| i.into()).collect(), 41 | expires_at: val.expires_at, 42 | irreversible: val.irreversible, 43 | whole_word: val.whole_word, 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/pleroma/entities/history.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct History { 6 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 7 | day: u64, 8 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 9 | uses: usize, 10 | #[serde(deserialize_with = "MegalodonEntities::history::parse_from_string")] 11 | accounts: usize, 12 | } 13 | 14 | impl From for MegalodonEntities::History { 15 | fn from(val: History) -> Self { 16 | MegalodonEntities::History { 17 | day: val.day, 18 | uses: val.uses, 19 | accounts: val.accounts, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pleroma/entities/identity_proof.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use chrono::{DateTime, Utc}; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct IdentityProof { 7 | provider: String, 8 | provider_username: String, 9 | updated_at: DateTime, 10 | proof_url: String, 11 | profile_url: String, 12 | } 13 | 14 | impl From for MegalodonEntities::IdentityProof { 15 | fn from(val: IdentityProof) -> Self { 16 | MegalodonEntities::IdentityProof { 17 | provider: val.provider, 18 | provider_username: val.provider_username, 19 | updated_at: val.updated_at, 20 | proof_url: val.proof_url, 21 | profile_url: val.profile_url, 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/pleroma/entities/list.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct List { 6 | id: String, 7 | title: String, 8 | } 9 | 10 | impl From for MegalodonEntities::List { 11 | fn from(val: List) -> Self { 12 | MegalodonEntities::List { 13 | id: val.id, 14 | title: val.title, 15 | replies_policy: None, 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/pleroma/entities/mention.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Mention { 6 | id: String, 7 | username: String, 8 | url: String, 9 | acct: String, 10 | } 11 | 12 | impl From for MegalodonEntities::Mention { 13 | fn from(val: Mention) -> Self { 14 | MegalodonEntities::Mention { 15 | id: val.id, 16 | username: val.username, 17 | url: val.url, 18 | acct: val.acct, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/pleroma/entities/poll.rs: -------------------------------------------------------------------------------- 1 | use super::{Emoji, PollOption}; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct Poll { 8 | id: String, 9 | expires_at: Option>, 10 | expired: bool, 11 | multiple: bool, 12 | votes_count: u32, 13 | voters_count: Option, 14 | options: Vec, 15 | voted: Option, 16 | emojis: Vec, 17 | } 18 | 19 | impl From for MegalodonEntities::Poll { 20 | fn from(val: Poll) -> Self { 21 | MegalodonEntities::Poll { 22 | id: val.id, 23 | expires_at: val.expires_at, 24 | expired: val.expired, 25 | multiple: val.multiple, 26 | votes_count: val.votes_count, 27 | voters_count: val.voters_count, 28 | options: val.options.into_iter().map(|i| i.into()).collect(), 29 | voted: val.voted, 30 | emojis: val.emojis.into_iter().map(|i| i.into()).collect(), 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/pleroma/entities/poll_option.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PollOption { 6 | title: String, 7 | votes_count: Option, 8 | } 9 | 10 | impl From for MegalodonEntities::PollOption { 11 | fn from(val: PollOption) -> Self { 12 | MegalodonEntities::PollOption { 13 | title: val.title, 14 | votes_count: val.votes_count, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/pleroma/entities/push_subscription.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct PushSubscription { 6 | id: String, 7 | endpoint: String, 8 | server_key: String, 9 | alerts: Alerts, 10 | } 11 | 12 | #[derive(Debug, Deserialize, Clone)] 13 | struct Alerts { 14 | follow: bool, 15 | favourite: bool, 16 | mention: bool, 17 | reblog: bool, 18 | poll: bool, 19 | } 20 | 21 | impl From for MegalodonEntities::PushSubscription { 22 | fn from(val: PushSubscription) -> Self { 23 | MegalodonEntities::PushSubscription { 24 | id: val.id, 25 | endpoint: val.endpoint, 26 | server_key: val.server_key, 27 | alerts: val.alerts.into(), 28 | } 29 | } 30 | } 31 | 32 | impl From for MegalodonEntities::push_subscription::Alerts { 33 | fn from(val: Alerts) -> Self { 34 | MegalodonEntities::push_subscription::Alerts { 35 | follow: val.follow, 36 | favourite: val.favourite, 37 | mention: val.mention, 38 | reblog: val.reblog, 39 | poll: val.poll, 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/pleroma/entities/reaction.rs: -------------------------------------------------------------------------------- 1 | use super::Account; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Reaction { 7 | pub count: u32, 8 | pub me: bool, 9 | pub name: String, 10 | pub accounts: Option>, 11 | pub account_ids: Option>, 12 | pub url: Option, 13 | } 14 | 15 | impl From for MegalodonEntities::Reaction { 16 | fn from(val: Reaction) -> Self { 17 | MegalodonEntities::Reaction { 18 | count: val.count, 19 | me: val.me, 20 | name: val.name, 21 | url: val.url.clone(), 22 | static_url: val.url, 23 | account_ids: val.account_ids, 24 | accounts: val 25 | .accounts 26 | .clone() 27 | .map(|i| i.into_iter().map(|a| a.into()).collect()), 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/pleroma/entities/relationship.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Relationship { 6 | id: String, 7 | following: bool, 8 | followed_by: bool, 9 | blocking: bool, 10 | blocked_by: bool, 11 | muting: bool, 12 | muting_notifications: bool, 13 | requested: bool, 14 | domain_blocking: bool, 15 | showing_reblogs: bool, 16 | endorsed: bool, 17 | #[allow(dead_code)] 18 | subscribing: bool, 19 | notifying: bool, 20 | note: String, 21 | } 22 | 23 | impl From for MegalodonEntities::Relationship { 24 | fn from(val: Relationship) -> Self { 25 | MegalodonEntities::Relationship { 26 | id: val.id, 27 | following: val.following, 28 | followed_by: val.followed_by, 29 | blocking: val.blocking, 30 | blocked_by: val.blocked_by, 31 | muting: val.muting, 32 | muting_notifications: val.muting_notifications, 33 | requested: val.requested, 34 | domain_blocking: val.domain_blocking, 35 | showing_reblogs: val.showing_reblogs, 36 | endorsed: val.endorsed, 37 | notifying: val.notifying, 38 | note: Some(val.note), 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/pleroma/entities/report.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Report { 6 | pub id: String, 7 | pub action_taken: bool, 8 | } 9 | 10 | impl From for MegalodonEntities::Report { 11 | fn from(val: Report) -> Self { 12 | MegalodonEntities::Report { 13 | id: val.id, 14 | action_taken: val.action_taken, 15 | action_taken_at: None, 16 | category: None, 17 | comment: None, 18 | forwarded: None, 19 | status_ids: None, 20 | rule_ids: None, 21 | target_account: None, 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/pleroma/entities/results.rs: -------------------------------------------------------------------------------- 1 | use super::{Account, Status, Tag}; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Results { 7 | accounts: Vec, 8 | statuses: Vec, 9 | hashtags: Vec, 10 | } 11 | 12 | impl From for MegalodonEntities::Results { 13 | fn from(val: Results) -> Self { 14 | MegalodonEntities::Results { 15 | accounts: val.accounts.into_iter().map(|i| i.into()).collect(), 16 | statuses: val.statuses.into_iter().map(|i| i.into()).collect(), 17 | hashtags: val.hashtags.into_iter().map(|i| i.into()).collect(), 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/pleroma/entities/scheduled_status.rs: -------------------------------------------------------------------------------- 1 | use super::{Attachment, StatusParams}; 2 | use crate::{entities as MegalodonEntities, megalodon}; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct ScheduledStatus { 8 | id: String, 9 | scheduled_at: DateTime, 10 | params: StatusParams, 11 | media_attachments: Option>, 12 | } 13 | 14 | impl From for MegalodonEntities::ScheduledStatus { 15 | fn from(val: ScheduledStatus) -> Self { 16 | MegalodonEntities::ScheduledStatus { 17 | id: val.id, 18 | scheduled_at: val.scheduled_at, 19 | params: val.params.into(), 20 | media_attachments: val 21 | .media_attachments 22 | .map(|m| m.into_iter().map(|i| i.into()).collect()), 23 | } 24 | } 25 | } 26 | 27 | impl From for megalodon::PostStatusOutput { 28 | fn from(val: ScheduledStatus) -> Self { 29 | megalodon::PostStatusOutput::ScheduledStatus(val.into()) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/pleroma/entities/source.rs: -------------------------------------------------------------------------------- 1 | use super::Field; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Source { 7 | privacy: Option, 8 | sensitive: Option, 9 | language: Option, 10 | note: String, 11 | fields: Option>, 12 | } 13 | 14 | impl From for Source { 15 | fn from(item: MegalodonEntities::Source) -> Self { 16 | Self { 17 | privacy: item.privacy, 18 | sensitive: item.sensitive, 19 | language: item.language, 20 | note: item.note, 21 | fields: item 22 | .fields 23 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 24 | } 25 | } 26 | } 27 | 28 | impl From for MegalodonEntities::Source { 29 | fn from(val: Source) -> Self { 30 | MegalodonEntities::Source { 31 | privacy: val.privacy, 32 | sensitive: val.sensitive, 33 | language: val.language, 34 | note: val.note, 35 | fields: val 36 | .fields 37 | .map(|i| i.into_iter().map(|j| j.into()).collect()), 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/pleroma/entities/stats.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Stats { 6 | user_count: u32, 7 | status_count: u64, 8 | domain_count: u32, 9 | } 10 | 11 | impl From for MegalodonEntities::Stats { 12 | fn from(val: Stats) -> Self { 13 | MegalodonEntities::Stats { 14 | user_count: val.user_count, 15 | status_count: val.status_count, 16 | domain_count: val.domain_count, 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/pleroma/entities/status_params.rs: -------------------------------------------------------------------------------- 1 | use super::StatusVisibility; 2 | use crate::entities as MegalodonEntities; 3 | use chrono::{DateTime, Utc}; 4 | use serde::Deserialize; 5 | 6 | #[derive(Debug, Deserialize, Clone)] 7 | pub struct StatusParams { 8 | text: String, 9 | in_reply_to_id: Option, 10 | media_ids: Option>, 11 | sensitive: Option, 12 | spoiler_text: Option, 13 | visibility: Option, 14 | scheduled_at: Option>, 15 | } 16 | 17 | impl From for MegalodonEntities::StatusParams { 18 | fn from(val: StatusParams) -> Self { 19 | MegalodonEntities::StatusParams { 20 | text: val.text, 21 | in_reply_to_id: val.in_reply_to_id, 22 | media_ids: val.media_ids, 23 | sensitive: val.sensitive, 24 | spoiler_text: val.spoiler_text, 25 | visibility: val.visibility.map(|i| i.into()), 26 | scheduled_at: val.scheduled_at, 27 | application_id: None, 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/pleroma/entities/status_source.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 5 | pub struct StatusSource { 6 | // ID of the status in the database 7 | id: String, 8 | // The plain text used to compose the status 9 | text: String, 10 | // The plain text used to compose the status’s subject or content warning 11 | spoiler_text: String, 12 | } 13 | 14 | impl From for MegalodonEntities::StatusSource { 15 | fn from(val: StatusSource) -> Self { 16 | MegalodonEntities::StatusSource { 17 | id: val.id, 18 | text: val.text, 19 | spoiler_text: val.spoiler_text, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pleroma/entities/tag.rs: -------------------------------------------------------------------------------- 1 | use super::History; 2 | use crate::entities as MegalodonEntities; 3 | use serde::Deserialize; 4 | 5 | #[derive(Debug, Deserialize, Clone)] 6 | pub struct Tag { 7 | name: String, 8 | url: String, 9 | history: Vec, 10 | following: Option, 11 | } 12 | 13 | impl From for MegalodonEntities::Tag { 14 | fn from(val: Tag) -> Self { 15 | MegalodonEntities::Tag { 16 | name: val.name, 17 | url: val.url, 18 | history: val.history.into_iter().map(|j| j.into()).collect(), 19 | following: val.following, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/pleroma/entities/token.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct Token { 6 | access_token: String, 7 | token_type: String, 8 | scope: String, 9 | created_at: u64, 10 | } 11 | 12 | impl From for MegalodonEntities::Token { 13 | fn from(val: Token) -> Self { 14 | MegalodonEntities::Token { 15 | access_token: val.access_token, 16 | token_type: val.token_type, 17 | scope: val.scope, 18 | created_at: val.created_at, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/pleroma/entities/urls.rs: -------------------------------------------------------------------------------- 1 | use crate::entities as MegalodonEntities; 2 | use serde::Deserialize; 3 | 4 | #[derive(Deserialize, Debug, Clone)] 5 | pub struct URLs { 6 | streaming_api: String, 7 | } 8 | 9 | impl From for MegalodonEntities::URLs { 10 | fn from(val: URLs) -> Self { 11 | MegalodonEntities::URLs { 12 | streaming_api: val.streaming_api, 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/pleroma/mod.rs: -------------------------------------------------------------------------------- 1 | //! Pleroma related modules 2 | 3 | mod api_client; 4 | pub mod entities; 5 | mod oauth; 6 | pub mod pleroma; 7 | mod web_socket; 8 | 9 | pub use pleroma::Pleroma; 10 | -------------------------------------------------------------------------------- /src/pleroma/oauth.rs: -------------------------------------------------------------------------------- 1 | use crate::oauth; 2 | use serde::Deserialize; 3 | 4 | #[derive(Debug, Deserialize, Clone)] 5 | pub struct AppDataFromServer { 6 | id: String, 7 | name: String, 8 | website: Option, 9 | redirect_uri: String, 10 | client_id: String, 11 | client_secret: String, 12 | } 13 | 14 | /// Obteined token data from server. 15 | #[derive(Debug, Deserialize, Clone)] 16 | pub struct TokenDataFromServer { 17 | access_token: String, 18 | token_type: String, 19 | scope: String, 20 | created_at: u64, 21 | expires_in: Option, 22 | refresh_token: Option, 23 | } 24 | 25 | impl From for oauth::AppData { 26 | fn from(val: AppDataFromServer) -> Self { 27 | oauth::AppData::new( 28 | val.id, 29 | val.name, 30 | val.website, 31 | Some(val.redirect_uri), 32 | val.client_id, 33 | val.client_secret, 34 | ) 35 | } 36 | } 37 | 38 | impl From for oauth::TokenData { 39 | fn from(val: TokenDataFromServer) -> Self { 40 | oauth::TokenData::new( 41 | val.access_token, 42 | val.token_type, 43 | Some(val.scope), 44 | Some(val.created_at), 45 | val.expires_in, 46 | val.refresh_token, 47 | ) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/response.rs: -------------------------------------------------------------------------------- 1 | //! Response modules 2 | use reqwest::header::HeaderMap; 3 | use serde::de::DeserializeOwned; 4 | use std::fmt::Debug; 5 | 6 | /// Response struct for API response. 7 | #[derive(Debug, Clone)] 8 | pub struct Response { 9 | /// Parsed json object. 10 | pub json: T, 11 | /// Status code of the response. 12 | pub status: u16, 13 | /// Status text of the response. 14 | pub status_text: String, 15 | /// Headers of the response. 16 | pub header: HeaderMap, 17 | } 18 | 19 | impl Response { 20 | /// Create a new Response struct. 21 | pub fn new(json: T, status: u16, status_text: String, header: HeaderMap) -> Response { 22 | Self { 23 | json, 24 | status, 25 | status_text, 26 | header, 27 | } 28 | } 29 | 30 | /// Create a new Response struct from reqwest::Response. 31 | pub async fn from_reqwest(response: reqwest::Response) -> Result, reqwest::Error> 32 | where 33 | T: DeserializeOwned + Debug, 34 | { 35 | let header = response.headers().clone(); 36 | let status_code = response.status(); 37 | let json = response.json::().await?; 38 | 39 | Ok(Self { 40 | json, 41 | status: status_code.as_u16(), 42 | status_text: status_code.as_str().to_string(), 43 | header, 44 | }) 45 | } 46 | 47 | /// Get json object. 48 | pub fn json(&self) -> T 49 | where 50 | T: Clone, 51 | { 52 | self.json.clone() 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/streaming.rs: -------------------------------------------------------------------------------- 1 | //! Streaming modules 2 | use crate::entities as MegalodonEntities; 3 | use async_trait::async_trait; 4 | use std::future::Future; 5 | use std::pin::Pin; 6 | 7 | /// Streaming interface to listen message. 8 | #[async_trait] 9 | pub trait Streaming { 10 | /// Start listening stream messages. When receive a message, the callback function will be called. 11 | async fn listen( 12 | &self, 13 | callback: Box< 14 | dyn Fn(Message) -> Pin + Send>> 15 | + Send 16 | + Sync 17 | + 'async_trait, 18 | >, 19 | ); 20 | } 21 | 22 | /// Stream message definitions. 23 | #[derive(Debug, Clone)] 24 | pub enum Message { 25 | /// Update message for `update` event. 26 | Update(MegalodonEntities::Status), 27 | /// Notification message for `notification` evnet. 28 | Notification(MegalodonEntities::Notification), 29 | /// Conversation message for `conversation` event. 30 | Conversation(MegalodonEntities::Conversation), 31 | /// Delete message for `delete` event. 32 | Delete(String), 33 | /// StatusUpdate message of `status.update` event. 34 | StatusUpdate(MegalodonEntities::Status), 35 | /// Heartbeat for streaming connection. 36 | Heartbeat(), 37 | } 38 | --------------------------------------------------------------------------------