Skip to content

Commit

Permalink
Merge pull request #201 from AkkermanD/feature/view_status_source
Browse files Browse the repository at this point in the history
Add "View status source" method
  • Loading branch information
h3poteto authored Mar 3, 2024
2 parents dfc6462 + 9ce644c commit ab1f137
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
11 changes: 11 additions & 0 deletions src/entities/status_source.rs
Original file line number Diff line number Diff line change
@@ -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,
}
11 changes: 11 additions & 0 deletions src/firefish/entities/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ impl Into<MegalodonEntities::Status> for Note {
}
}

impl Into<MegalodonEntities::StatusSource> 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<MegalodonEntities::Conversation> for Note {
fn into(self) -> MegalodonEntities::Conversation {
let accounts: Vec<MegalodonEntities::Account> = [self.user.clone().into()].to_vec();
Expand Down
14 changes: 14 additions & 0 deletions src/firefish/firefish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,20 @@ impl megalodon::Megalodon for Firefish {
))
}

async fn get_status_source(&self, id: String) -> Result<Response<MegalodonEntities::StatusSource>, Error> {
let params = HashMap::<&str, Value>::from([("noteId", Value::String(id))]);
let res = self
.client
.post::<entities::Note>("/api/notes/show", &params, None)
.await?;
Ok(Response::<MegalodonEntities::StatusSource>::new(
res.json.into(),
res.status,
res.status_text,
res.header,
))
}

async fn edit_status(
&self,
id: String,
Expand Down
10 changes: 10 additions & 0 deletions src/friendica/friendica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,16 @@ impl megalodon::Megalodon for Friendica {
))
}

async fn get_status_source(&self, _id: String) -> Result<Response<MegalodonEntities::StatusSource>, 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,
Expand Down
2 changes: 2 additions & 0 deletions src/mastodon/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
22 changes: 22 additions & 0 deletions src/mastodon/entities/status_source.rs
Original file line number Diff line number Diff line change
@@ -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
id: String,
// The plain text used to compose the status
text: String,
// The plain text used to compose the status’s subject or content warning
spoiler_text: String,
}

impl Into<MegalodonEntities::StatusSource> for StatusSource {
fn into(self) -> MegalodonEntities::StatusSource {
MegalodonEntities::StatusSource {
id: self.id,
text: self.text,
spoiler_text: self.spoiler_text,
}
}
}
14 changes: 14 additions & 0 deletions src/mastodon/mastodon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,20 @@ impl megalodon::Megalodon for Mastodon {
))
}

async fn get_status_source(&self, id: String) -> Result<Response<MegalodonEntities::StatusSource>, Error> {
let res = self
.client
.get::<entities::StatusSource>(format!("/api/v1/statuses/{}/source", id).as_str(), None)
.await?;

Ok(Response::<MegalodonEntities::StatusSource>::new(
res.json.into(),
res.status,
res.status_text,
res.header,
))
}

async fn edit_status(
&self,
id: String,
Expand Down
3 changes: 3 additions & 0 deletions src/megalodon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ pub trait Megalodon {
/// Get information about a status.
async fn get_status(&self, id: String) -> Result<Response<entities::Status>, Error>;

/// Obtain the source properties for a status so that it can be edited.
async fn get_status_source(&self, id: String) -> Result<Response<entities::StatusSource>, Error>;

/// Edit a status.
async fn edit_status(
&self,
Expand Down
2 changes: 2 additions & 0 deletions src/pleroma/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
22 changes: 22 additions & 0 deletions src/pleroma/entities/status_source.rs
Original file line number Diff line number Diff line change
@@ -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
id: String,
// The plain text used to compose the status
text: String,
// The plain text used to compose the status’s subject or content warning
spoiler_text: String,
}

impl Into<MegalodonEntities::StatusSource> for StatusSource {
fn into(self) -> MegalodonEntities::StatusSource {
MegalodonEntities::StatusSource {
id: self.id,
text: self.text,
spoiler_text: self.spoiler_text,
}
}
}
14 changes: 14 additions & 0 deletions src/pleroma/pleroma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,20 @@ impl megalodon::Megalodon for Pleroma {
))
}

async fn get_status_source(&self, id: String) -> Result<Response<MegalodonEntities::StatusSource>, Error> {
let res = self
.client
.get::<entities::StatusSource>(format!("/api/v1/statuses/{}/source", id).as_str(), None)
.await?;

Ok(Response::<MegalodonEntities::StatusSource>::new(
res.json.into(),
res.status,
res.status_text,
res.header,
))
}

async fn edit_status(
&self,
id: String,
Expand Down

0 comments on commit ab1f137

Please sign in to comment.