From 8a919cf5b87841cf2af8588e65443b02cd2009c6 Mon Sep 17 00:00:00 2001 From: Akkerman Date: Thu, 22 Feb 2024 21:25:46 +0200 Subject: [PATCH 1/4] Add initial implementations for get_status_source() --- src/entities/mod.rs | 2 ++ src/entities/status_source.rs | 11 +++++++++++ src/firefish/entities/note.rs | 11 +++++++++++ src/firefish/firefish.rs | 14 ++++++++++++++ src/friendica/friendica.rs | 10 ++++++++++ src/mastodon/mastodon.rs | 14 ++++++++++++++ src/megalodon.rs | 3 +++ src/pleroma/pleroma.rs | 14 ++++++++++++++ 8 files changed, 79 insertions(+) create mode 100644 src/entities/status_source.rs diff --git a/src/entities/mod.rs b/src/entities/mod.rs index a0de947..a469656 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -35,6 +35,7 @@ pub mod source; pub mod stats; pub mod status; pub mod status_params; +pub mod status_source; pub mod tag; pub mod token; pub mod urls; @@ -75,6 +76,7 @@ pub use source::Source; pub use stats::Stats; pub use status::{Status, StatusVisibility}; pub use status_params::StatusParams; +pub use status_source::StatusSource; pub use tag::Tag; pub use token::Token; pub use urls::URLs; diff --git a/src/entities/status_source.rs b/src/entities/status_source.rs new file mode 100644 index 0000000..3e78d84 --- /dev/null +++ b/src/entities/status_source.rs @@ -0,0 +1,11 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +pub struct StatusSource { + // ID of the status in the database + pub id: String, + // The plain text used to compose the status + pub text: String, + // The plain text used to compose the status’s subject or content warning + pub spoiler_text: String, +} diff --git a/src/firefish/entities/note.rs b/src/firefish/entities/note.rs index 5fe5701..ac63e51 100644 --- a/src/firefish/entities/note.rs +++ b/src/firefish/entities/note.rs @@ -198,6 +198,17 @@ impl Into for Note { } } +impl Into for Note { + fn into(self) -> MegalodonEntities::StatusSource { + let Self {id, text, cw, ..} = self; + MegalodonEntities::StatusSource { + id, + text: text.unwrap_or_default(), + spoiler_text: cw.unwrap_or_default(), + } + } +} + impl Into for Note { fn into(self) -> MegalodonEntities::Conversation { let accounts: Vec = [self.user.clone().into()].to_vec(); diff --git a/src/firefish/firefish.rs b/src/firefish/firefish.rs index 889a619..d4aabea 100644 --- a/src/firefish/firefish.rs +++ b/src/firefish/firefish.rs @@ -1318,6 +1318,20 @@ impl megalodon::Megalodon for Firefish { )) } + async fn get_status_source(&self, id: String) -> Result, Error> { + let params = HashMap::<&str, Value>::from([("noteId", Value::String(id))]); + let res = self + .client + .post::("/api/notes/show", ¶ms, None) + .await?; + Ok(Response::::new( + res.json.into(), + res.status, + res.status_text, + res.header, + )) + } + async fn edit_status( &self, id: String, diff --git a/src/friendica/friendica.rs b/src/friendica/friendica.rs index e25db52..19fb2ae 100644 --- a/src/friendica/friendica.rs +++ b/src/friendica/friendica.rs @@ -1267,6 +1267,16 @@ impl megalodon::Megalodon for Friendica { )) } + async fn get_status_source(&self, id: String) -> Result, Error> { + // Check https://wiki.friendi.ca/docs/api-mastodon#currently_unimplemented_endpoints + Err(Error::new_own( + "Friendica does not support".to_string(), + error::Kind::NoImplementedError, + None, + None, + )) + } + async fn edit_status( &self, id: String, diff --git a/src/mastodon/mastodon.rs b/src/mastodon/mastodon.rs index f9bf4cb..bd20e8d 100644 --- a/src/mastodon/mastodon.rs +++ b/src/mastodon/mastodon.rs @@ -1504,6 +1504,20 @@ impl megalodon::Megalodon for Mastodon { )) } + async fn get_status_source(&self, id: String) -> Result, Error> { + let res = self + .client + .get::(format!("/api/v1/statuses/{}/source", id).as_str(), None) + .await?; + + Ok(Response::::new( + res.json.into(), + res.status, + res.status_text, + res.header, + )) + } + async fn edit_status( &self, id: String, diff --git a/src/megalodon.rs b/src/megalodon.rs index 2549b77..3e460b2 100644 --- a/src/megalodon.rs +++ b/src/megalodon.rs @@ -363,6 +363,9 @@ pub trait Megalodon { /// Get information about a status. async fn get_status(&self, id: String) -> Result, Error>; + /// Obtain the source properties for a status so that it can be edited. + async fn get_status_source(&self, id: String) -> Result, Error>; + /// Edit a status. async fn edit_status( &self, diff --git a/src/pleroma/pleroma.rs b/src/pleroma/pleroma.rs index 88f9fe4..35ffd5a 100644 --- a/src/pleroma/pleroma.rs +++ b/src/pleroma/pleroma.rs @@ -1430,6 +1430,20 @@ impl megalodon::Megalodon for Pleroma { )) } + async fn get_status_source(&self, id: String) -> Result, Error> { + let res = self + .client + .get::(format!("/api/v1/statuses/{}/source", id).as_str(), None) + .await?; + + Ok(Response::::new( + res.json.into(), + res.status, + res.status_text, + res.header, + )) + } + async fn edit_status( &self, id: String, From 3c65241687fc890b48efdc271938719216b52a2c Mon Sep 17 00:00:00 2001 From: Akkerman Date: Sun, 25 Feb 2024 15:13:08 +0200 Subject: [PATCH 2/4] Fix var name --- src/friendica/friendica.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/friendica/friendica.rs b/src/friendica/friendica.rs index 19fb2ae..ea96eb3 100644 --- a/src/friendica/friendica.rs +++ b/src/friendica/friendica.rs @@ -1267,7 +1267,7 @@ impl megalodon::Megalodon for Friendica { )) } - async fn get_status_source(&self, id: String) -> Result, Error> { + async fn get_status_source(&self, _id: String) -> Result, Error> { // Check https://wiki.friendi.ca/docs/api-mastodon#currently_unimplemented_endpoints Err(Error::new_own( "Friendica does not support".to_string(), From bb2119d19611bba74e9032c8705c234f9bdca01e Mon Sep 17 00:00:00 2001 From: Akkerman Date: Sun, 3 Mar 2024 14:34:53 +0200 Subject: [PATCH 3/4] Use pleroma/mastodon specific enitities for StatusSource --- src/mastodon/entities/mod.rs | 2 ++ src/mastodon/entities/status_source.rs | 22 ++++++++++++++++++++++ src/mastodon/mastodon.rs | 2 +- src/pleroma/entities/mod.rs | 2 ++ src/pleroma/entities/status_source.rs | 22 ++++++++++++++++++++++ src/pleroma/pleroma.rs | 2 +- 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/mastodon/entities/status_source.rs create mode 100644 src/pleroma/entities/status_source.rs diff --git a/src/mastodon/entities/mod.rs b/src/mastodon/entities/mod.rs index 3ccf890..8250830 100644 --- a/src/mastodon/entities/mod.rs +++ b/src/mastodon/entities/mod.rs @@ -30,6 +30,7 @@ pub mod source; pub mod stats; pub mod status; pub mod status_params; +pub mod status_source; pub mod tag; pub mod token; pub mod urls; @@ -66,6 +67,7 @@ pub use source::Source; pub use stats::Stats; pub use status::{Status, StatusVisibility}; pub use status_params::StatusParams; +pub use status_source::StatusSource; pub use tag::Tag; pub use token::Token; pub use urls::URLs; diff --git a/src/mastodon/entities/status_source.rs b/src/mastodon/entities/status_source.rs new file mode 100644 index 0000000..afb0436 --- /dev/null +++ b/src/mastodon/entities/status_source.rs @@ -0,0 +1,22 @@ +use crate::entities as MegalodonEntities; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +pub struct StatusSource { + // ID of the status in the database + pub id: String, + // The plain text used to compose the status + pub text: String, + // The plain text used to compose the status’s subject or content warning + pub spoiler_text: String, +} + +impl Into for StatusSource { + fn into(self) -> MegalodonEntities::StatusSource { + MegalodonEntities::StatusSource { + id: self.id, + text: self.text, + spoiler_text: self.spoiler_text, + } + } +} diff --git a/src/mastodon/mastodon.rs b/src/mastodon/mastodon.rs index bd20e8d..9baf890 100644 --- a/src/mastodon/mastodon.rs +++ b/src/mastodon/mastodon.rs @@ -1507,7 +1507,7 @@ impl megalodon::Megalodon for Mastodon { async fn get_status_source(&self, id: String) -> Result, Error> { let res = self .client - .get::(format!("/api/v1/statuses/{}/source", id).as_str(), None) + .get::(format!("/api/v1/statuses/{}/source", id).as_str(), None) .await?; Ok(Response::::new( diff --git a/src/pleroma/entities/mod.rs b/src/pleroma/entities/mod.rs index 77fc6c3..d7bc676 100644 --- a/src/pleroma/entities/mod.rs +++ b/src/pleroma/entities/mod.rs @@ -30,6 +30,7 @@ pub mod source; pub mod stats; pub mod status; pub mod status_params; +pub mod status_source; pub mod tag; pub mod token; pub mod urls; @@ -66,6 +67,7 @@ pub use source::Source; pub use stats::Stats; pub use status::{Status, StatusVisibility}; pub use status_params::StatusParams; +pub use status_source::StatusSource; pub use tag::Tag; pub use token::Token; pub use urls::URLs; diff --git a/src/pleroma/entities/status_source.rs b/src/pleroma/entities/status_source.rs new file mode 100644 index 0000000..afb0436 --- /dev/null +++ b/src/pleroma/entities/status_source.rs @@ -0,0 +1,22 @@ +use crate::entities as MegalodonEntities; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +pub struct StatusSource { + // ID of the status in the database + pub id: String, + // The plain text used to compose the status + pub text: String, + // The plain text used to compose the status’s subject or content warning + pub spoiler_text: String, +} + +impl Into for StatusSource { + fn into(self) -> MegalodonEntities::StatusSource { + MegalodonEntities::StatusSource { + id: self.id, + text: self.text, + spoiler_text: self.spoiler_text, + } + } +} diff --git a/src/pleroma/pleroma.rs b/src/pleroma/pleroma.rs index 35ffd5a..b7da3d6 100644 --- a/src/pleroma/pleroma.rs +++ b/src/pleroma/pleroma.rs @@ -1433,7 +1433,7 @@ impl megalodon::Megalodon for Pleroma { async fn get_status_source(&self, id: String) -> Result, Error> { let res = self .client - .get::(format!("/api/v1/statuses/{}/source", id).as_str(), None) + .get::(format!("/api/v1/statuses/{}/source", id).as_str(), None) .await?; Ok(Response::::new( From 9ce644c662c48da218746591dd2ea85fb77f11ae Mon Sep 17 00:00:00 2001 From: Akkerman Date: Sun, 3 Mar 2024 14:40:53 +0200 Subject: [PATCH 4/4] Make fields private --- src/mastodon/entities/status_source.rs | 6 +++--- src/pleroma/entities/status_source.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mastodon/entities/status_source.rs b/src/mastodon/entities/status_source.rs index afb0436..61191d3 100644 --- a/src/mastodon/entities/status_source.rs +++ b/src/mastodon/entities/status_source.rs @@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct StatusSource { // ID of the status in the database - pub id: String, + id: String, // The plain text used to compose the status - pub text: String, + text: String, // The plain text used to compose the status’s subject or content warning - pub spoiler_text: String, + spoiler_text: String, } impl Into for StatusSource { diff --git a/src/pleroma/entities/status_source.rs b/src/pleroma/entities/status_source.rs index afb0436..61191d3 100644 --- a/src/pleroma/entities/status_source.rs +++ b/src/pleroma/entities/status_source.rs @@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct StatusSource { // ID of the status in the database - pub id: String, + id: String, // The plain text used to compose the status - pub text: String, + text: String, // The plain text used to compose the status’s subject or content warning - pub spoiler_text: String, + spoiler_text: String, } impl Into for StatusSource {